5

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?

  • did you get this to work @zhenming ? – Robin Sep 17 '15 at 5:30
2

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.

  • can you show an example with the above code? I can't get it to work – Robin Sep 16 '15 at 13:21
1

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

  • I cannot get this to work have you any ideas? "Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to a member function getBackend() on boolean " – harri Jan 29 at 14:28
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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