How to Update Group Price Programmatically Without Product Object Save












4















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?










share|improve this question

























  • did you get this to work @zhenming ?

    – Robin
    Sep 17 '15 at 5:30
















4















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?










share|improve this question

























  • did you get this to work @zhenming ?

    – Robin
    Sep 17 '15 at 5:30














4












4








4








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?










share|improve this 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?







group-price






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 '15 at 14:17









musicliftsme

5,34252567




5,34252567










asked Mar 23 '15 at 9:22









zhenmingzhenming

12815




12815













  • did you get this to work @zhenming ?

    – Robin
    Sep 17 '15 at 5:30



















  • did you get this to work @zhenming ?

    – Robin
    Sep 17 '15 at 5:30

















did you get this to work @zhenming ?

– Robin
Sep 17 '15 at 5:30





did you get this to work @zhenming ?

– Robin
Sep 17 '15 at 5:30










3 Answers
3






active

oldest

votes


















1














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.






share|improve this answer
























  • can you show an example with the above code? I can't get it to work

    – Robin
    Sep 16 '15 at 13:21



















0














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






share|improve this answer
























  • 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





share























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f61640%2fhow-to-update-group-price-programmatically-without-product-object-save%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    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.






    share|improve this answer
























    • can you show an example with the above code? I can't get it to work

      – Robin
      Sep 16 '15 at 13:21
















    1














    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.






    share|improve this answer
























    • can you show an example with the above code? I can't get it to work

      – Robin
      Sep 16 '15 at 13:21














    1












    1








    1







    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.






    share|improve this 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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 23 '15 at 14:17









    musicliftsmemusicliftsme

    5,34252567




    5,34252567













    • can you show an example with the above code? I can't get it to work

      – Robin
      Sep 16 '15 at 13:21



















    • can you show an example with the above code? I can't get it to work

      – Robin
      Sep 16 '15 at 13:21

















    can you show an example with the above code? I can't get it to work

    – Robin
    Sep 16 '15 at 13:21





    can you show an example with the above code? I can't get it to work

    – Robin
    Sep 16 '15 at 13:21













    0














    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






    share|improve this answer
























    • 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














    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






    share|improve this answer
























    • 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












    0








    0







    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






    share|improve this answer













    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







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 6 '18 at 12:47









    Adam GierońAdam Gieroń

    9111




    9111













    • 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



















    • 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

















    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





    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





    share




























      0














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





      share


























        0












        0








        0







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





        share













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






        share











        share


        share










        answered 8 mins ago









        Adam GierońAdam Gieroń

        9111




        9111






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f61640%2fhow-to-update-group-price-programmatically-without-product-object-save%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Magento 2 controller redirect on button click in phtml file

            Polycentropodidae