Skip to content

Instantly share code, notes, and snippets.

@gabidavila
Last active December 16, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabidavila/5376289 to your computer and use it in GitHub Desktop.
Save gabidavila/5376289 to your computer and use it in GitHub Desktop.
Alterar valor de atributo para todos os produtos no Magento Change attribute value for all products in Magento
<?php
//get all products
$products = Mage::getResourceModel('catalog/product_collection')->getAllIds();
//Now create an array of attribute_code => values
$attributesData = array(
array('orig' => 1),
array('ncm' => 33030020),
array('ucom' => 'un'),
array('subst' => 1)
);
//Set the store to affect. I used admin to change all default values
$storeId = 0; //A.K.A Admin
//Now Update the attribute(s) for the given products.
foreach ($attributesData as $attributeData) {
Mage::getSingleton('catalog/product_action')->updateAttributes($products, $attributeData, $storeId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment