Magento Product attribute type change

$prefix = Mage::getConfig()->getTablePrefix();
$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_write');
$attributeIds       = 671;
$entityTypeId       = 4;
$sql                = 'SELECT * FROM '.$prefix.'catalog_product_entity_text WHERE attribute_id IN ('.$attributeIds.') AND entity_type_id = '.$entityTypeId;
$rows               = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
foreach ($rows as $row){
    $price = $row['value'];
    if (!is_null($price)) {
        $sql = 'INSERT INTO '.$prefix.'catalog_product_entity_decimal (`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`)
            VALUES (?,?,?,?,?)';
        $connection->query($sql, array($row['entity_type_id'], $row['attribute_id'], $row['store_id'], $row['entity_id'], $price));
    }
    $sql = 'DELETE FROM '.$prefix.'catalog_product_entity_text WHERE value_id = ?'; // or your old storage table
    $connection->query($sql, $row['value_id']);
}
$sql = 'UPDATE '.$prefix.'eav_attribute SET backend_type="decimal" WHERE attribute_id IN ('.$attributeIds.')';
$connection->query($sql);

Share this

Related Posts

Previous
Next Post »

Pageviews from the past week