Magento – Update custom attribute value for all products – Magento1.9

magento-1.9product-attribute

I have a Magento store with products count 70,000 approx. I want to update 5 custom attribute's value for all products.

I have a CSV file which contains SKU and value of custom attributes for all products. Is there any option available to update/set value for all text types attribute either using MySQL query or programmatically?

Thank you.

Best Answer

This should give you an idea for how to run a script to perform a mass update on your products.

/*
 * Script to update custom attributes product values
 */

$_productCollection = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToSelect('*');
$storeId = 0;

foreach($_productCollection as $_product)  {
    $product = Mage::getModel('catalog/product')->load($_product->getId());   
    $data = array(
                'custom_attribute_1' => 'VALUE_OF_ATTRIBUTE1',
                'custom_attribute_2 '=> 'VALUE_OF_ATTRIBUTE2',
    ); 
    Mage::getSingleton('catalog/product_action')->updateAttributes(array($product->getId()), $data, $storeId); 
}
Related Topic