0
Mage::getResourceModel('catalog/product')->getAttributeRawValue($id, 'attribute', Mage::app()->getStore());

This can be used to fetch the product attribute by ID. How can one set this value as well?

2 Answers 2

2

For that you'll want the Mage_Catalog_Model_Product_Action model.

Mage::getSingleton('catalog/product_action')->updateAttributes(
    array(100, 200, 300),               // Product IDs to update
    array('my_attribute'=>'new value'), // Key/value pairs of attributes and their values
    1                                   // Store ID
);
1
  • I should note that this doesn't fire the usual catalog_product_after_save event, only catalog_product_attribute_update_before and catalog_product_attribute_update_after which might not reindex things or clear caches as you might expect, so use it carefully.
    – Tyler V.
    Commented May 9, 2015 at 1:21
1

You can use the saveAttribute method of Mage_Eav_Model_Entity_Abstract which Mage_Catalog_Model_Resource_Abstract extends:

$id = 905;
$attributeCode = 'name';

$product = Mage::getModel('catalog/product');
$product->setStoreId(0);
$product->setId($id);
$product->setName('8GB Memory Card');

$product->getResource()->saveAttribute($product, $attributeCode);

Note that this will not work with attributes that have a static backend type like sku. Sku is actually a field in catalog_product_entity table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.