How to Update Group Price Programmatically Without Product Object Save

group-pricemagento-1.9

To save group price for the products, the following works for me.

$product->setData('group_price', $group_pricing_data);
$product->save();

However, it takes a while for mass updating products. The faster way to save only attributes via saveAttribute() does not seem to work on group price.

$product->setData('group_price', $group_pricing_data);
$product->getResource()->saveAttribute($product, 'group_price');

Is it because group_price is not EAV like the other attributes, and if so, is there any other way to just save only group pricing?

Best Answer

As far as I know, you can't simply update group price data using saveAttribute because it has a custom backend model, catalog/product_attribute_backend_groupprice.

When you load and save a product object, group price's custom resource mode does the work to load and save the data accordingly. If you look at Mage_Catalog_Model_Resource_Product_Attribute_Backend_Groupprice_Abstract, you will see the methods Magento uses to load and save group price data.

Specifically, savePriceData shows how to save the data properly. If you want a fast group price update, you can mimic what's done here. Check how $data looks like, and you have a good place to start.

Related Topic