Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You can speed up saving group_price attribute like this:

$prices = $product->getData('group_price');

above code return array, next step is to modify this array and last inject as parameter to below:

$product->setGroupPrice($prices)
            ->getResource()
            ->getAttribute('group_price')
            ->getBackend()
            ->afterSave($product);

5k products 45 ~ 60 sec on docker local environment.

Happy coding, Adam

try to: var_dump($product->setGroupPrice($prices) ->getResource() ->getAttribute('group_price')); and post here

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top