Magento 2 Update product additional option added in add to cartAttribute added to Mini Cart Magento 2Set custom price of product when adding to cart code not workingMagento : Not able to set posted value in the observerPrice not getting updated for second product…how to add a new customizable product optionLocalization for Cart/Quote APIs doesn't work properly in magento 2Magento2 : How to add a custom option to Item in cartAdd event after user add the product to cart to update quantityMagento 2.2.5: Add, Update and Delete existing products Custom Options

How to explain what's wrong with this application of the chain rule?

Can you use Vicious Mockery to win an argument or gain favours?

Biological Blimps: Propulsion

Confused about Cramer-Rao lower bound and CLT

How to get directions in deep space?

"It doesn't matter" or "it won't matter"?

How do you make your own symbol when Detexify fails?

Shouldn’t conservatives embrace universal basic income?

How can I write humor as character trait?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

"before" and "want" for the same systemd service?

awk assign to multiple variables at once

Why is so much work done on numerical verification of the Riemann Hypothesis?

How to convince somebody that he is fit for something else, but not this job?

Find the next value of this number series

What fields between the rationals and the reals allow a good notion of 2D distance?

What does Apple's new App Store requirement mean

Multiplicative persistence

Pre-mixing cryogenic fuels and using only one fuel tank

Merge org tables

How does electrical safety system work on ISS?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Is there a nicer/politer/more positive alternative for "negates"?

How could a planet have erratic days?



Magento 2 Update product additional option added in add to cart


Attribute added to Mini Cart Magento 2Set custom price of product when adding to cart code not workingMagento : Not able to set posted value in the observerPrice not getting updated for second product…how to add a new customizable product optionLocalization for Cart/Quote APIs doesn't work properly in magento 2Magento2 : How to add a custom option to Item in cartAdd event after user add the product to cart to update quantityMagento 2.2.5: Add, Update and Delete existing products Custom Options













4















I have configurable product in my website and I added the product additional option in add to cart to hold the custom value, Now on cart page I want to allow the user to update those additional option value.



I created a custom controller to handle the edit action, But here the value updated by the user is not reflecting into the cart.



Please give me your suggestion to fix the issue, Below is my code.



My Observer code



catalog_product_load_after:

public function execute(MagentoFrameworkEventObserver $observer)
// Check and set information according to your need
if ($this->_request->getFullActionName() == 'checkout_cart_add') //checking when product is adding to cart
$post = $this->_request->getParam('personalized');

$additionalOptions = [];
$additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text1');
$additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text2');

if (count($additionalOptions) > 0)
$observer->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));





The above code is working fine, I am able to add these additonal option in cart and it's displaying in cart page.



Now for updating on cart page I have done the following code which is not working.



$quoteObj = $this->_cart->getQuote();

$item_id = 201;
$item = $quoteObj->getItemById($item_id);


if (!empty($item))


$additionalOptions = [];


### Setting up additional options
$additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text3');
$additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text4');


if (count($additionalOptions) > 0)

$item->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));


$item->getProduct()->setIsSuperMode(true);
$item->save();










share|improve this question














bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.



















    4















    I have configurable product in my website and I added the product additional option in add to cart to hold the custom value, Now on cart page I want to allow the user to update those additional option value.



    I created a custom controller to handle the edit action, But here the value updated by the user is not reflecting into the cart.



    Please give me your suggestion to fix the issue, Below is my code.



    My Observer code



    catalog_product_load_after:

    public function execute(MagentoFrameworkEventObserver $observer)
    // Check and set information according to your need
    if ($this->_request->getFullActionName() == 'checkout_cart_add') //checking when product is adding to cart
    $post = $this->_request->getParam('personalized');

    $additionalOptions = [];
    $additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text1');
    $additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text2');

    if (count($additionalOptions) > 0)
    $observer->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));





    The above code is working fine, I am able to add these additonal option in cart and it's displaying in cart page.



    Now for updating on cart page I have done the following code which is not working.



    $quoteObj = $this->_cart->getQuote();

    $item_id = 201;
    $item = $quoteObj->getItemById($item_id);


    if (!empty($item))


    $additionalOptions = [];


    ### Setting up additional options
    $additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text3');
    $additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text4');


    if (count($additionalOptions) > 0)

    $item->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));


    $item->getProduct()->setIsSuperMode(true);
    $item->save();










    share|improve this question














    bumped to the homepage by Community 9 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      4












      4








      4








      I have configurable product in my website and I added the product additional option in add to cart to hold the custom value, Now on cart page I want to allow the user to update those additional option value.



      I created a custom controller to handle the edit action, But here the value updated by the user is not reflecting into the cart.



      Please give me your suggestion to fix the issue, Below is my code.



      My Observer code



      catalog_product_load_after:

      public function execute(MagentoFrameworkEventObserver $observer)
      // Check and set information according to your need
      if ($this->_request->getFullActionName() == 'checkout_cart_add') //checking when product is adding to cart
      $post = $this->_request->getParam('personalized');

      $additionalOptions = [];
      $additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text1');
      $additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text2');

      if (count($additionalOptions) > 0)
      $observer->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));





      The above code is working fine, I am able to add these additonal option in cart and it's displaying in cart page.



      Now for updating on cart page I have done the following code which is not working.



      $quoteObj = $this->_cart->getQuote();

      $item_id = 201;
      $item = $quoteObj->getItemById($item_id);


      if (!empty($item))


      $additionalOptions = [];


      ### Setting up additional options
      $additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text3');
      $additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text4');


      if (count($additionalOptions) > 0)

      $item->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));


      $item->getProduct()->setIsSuperMode(true);
      $item->save();










      share|improve this question














      I have configurable product in my website and I added the product additional option in add to cart to hold the custom value, Now on cart page I want to allow the user to update those additional option value.



      I created a custom controller to handle the edit action, But here the value updated by the user is not reflecting into the cart.



      Please give me your suggestion to fix the issue, Below is my code.



      My Observer code



      catalog_product_load_after:

      public function execute(MagentoFrameworkEventObserver $observer)
      // Check and set information according to your need
      if ($this->_request->getFullActionName() == 'checkout_cart_add') //checking when product is adding to cart
      $post = $this->_request->getParam('personalized');

      $additionalOptions = [];
      $additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text1');
      $additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text2');

      if (count($additionalOptions) > 0)
      $observer->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));





      The above code is working fine, I am able to add these additonal option in cart and it's displaying in cart page.



      Now for updating on cart page I have done the following code which is not working.



      $quoteObj = $this->_cart->getQuote();

      $item_id = 201;
      $item = $quoteObj->getItemById($item_id);


      if (!empty($item))


      $additionalOptions = [];


      ### Setting up additional options
      $additionalOptions[] = array('label' => "labelVal1", 'value' => 'Text3');
      $additionalOptions[] = array('label' => "labelVal2", 'value' => 'Text4');


      if (count($additionalOptions) > 0)

      $item->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));


      $item->getProduct()->setIsSuperMode(true);
      $item->save();







      magento2 magento-2.1 php






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 15 '17 at 12:09









      Irfan.gwbIrfan.gwb

      211




      211





      bumped to the homepage by Community 9 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 9 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          First of all, let's check the MagentoQuoteModelQuoteItem::beforeSave method. This is the only one method invoked after $item->save() call. As you can see, the item object doesn't refresh the custom options from product object. To make it work, you need to pass values directly in quote item using addOption method, like so:



          $item->addOption(['label' => 'some_key', 'value' => $this->request->getPostValue('some_key')]);
          $item->save();


          Also, you need to connect new quote item option with additional_options array on rendering stage.



          Please take into account that additional_options might be used by other developers and it's better to merge your data to this array instead of replacing.






          share|improve this answer






















            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%2f205994%2fmagento-2-update-product-additional-option-added-in-add-to-cart%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            First of all, let's check the MagentoQuoteModelQuoteItem::beforeSave method. This is the only one method invoked after $item->save() call. As you can see, the item object doesn't refresh the custom options from product object. To make it work, you need to pass values directly in quote item using addOption method, like so:



            $item->addOption(['label' => 'some_key', 'value' => $this->request->getPostValue('some_key')]);
            $item->save();


            Also, you need to connect new quote item option with additional_options array on rendering stage.



            Please take into account that additional_options might be used by other developers and it's better to merge your data to this array instead of replacing.






            share|improve this answer



























              0














              First of all, let's check the MagentoQuoteModelQuoteItem::beforeSave method. This is the only one method invoked after $item->save() call. As you can see, the item object doesn't refresh the custom options from product object. To make it work, you need to pass values directly in quote item using addOption method, like so:



              $item->addOption(['label' => 'some_key', 'value' => $this->request->getPostValue('some_key')]);
              $item->save();


              Also, you need to connect new quote item option with additional_options array on rendering stage.



              Please take into account that additional_options might be used by other developers and it's better to merge your data to this array instead of replacing.






              share|improve this answer

























                0












                0








                0







                First of all, let's check the MagentoQuoteModelQuoteItem::beforeSave method. This is the only one method invoked after $item->save() call. As you can see, the item object doesn't refresh the custom options from product object. To make it work, you need to pass values directly in quote item using addOption method, like so:



                $item->addOption(['label' => 'some_key', 'value' => $this->request->getPostValue('some_key')]);
                $item->save();


                Also, you need to connect new quote item option with additional_options array on rendering stage.



                Please take into account that additional_options might be used by other developers and it's better to merge your data to this array instead of replacing.






                share|improve this answer













                First of all, let's check the MagentoQuoteModelQuoteItem::beforeSave method. This is the only one method invoked after $item->save() call. As you can see, the item object doesn't refresh the custom options from product object. To make it work, you need to pass values directly in quote item using addOption method, like so:



                $item->addOption(['label' => 'some_key', 'value' => $this->request->getPostValue('some_key')]);
                $item->save();


                Also, you need to connect new quote item option with additional_options array on rendering stage.



                Please take into account that additional_options might be used by other developers and it's better to merge your data to this array instead of replacing.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 18 '17 at 17:00









                Andrey KonosovAndrey Konosov

                381111




                381111



























                    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%2f205994%2fmagento-2-update-product-additional-option-added-in-add-to-cart%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

                    Jet Time Laivasto | Lähteet | Aiheesta muualla | NavigointivalikkoJet Time - The CompanyThe CompanyManagementJet Time aloittaa lauantaina Suomi-rekisterissä olevalla Boeing 737 -koneellaJettime Finland Fleet Details and HistoryJettime Fleet Details and HistoryRegional Jet OÜ takes over ATR production for SASJet Time Returns To Its Core BusinessYhtiön kotisivutlaajentamalla

                    Olympian arkeologinen museo Sisällysluettelo Historia ja rakennus | Kokoelmat | Lähteet | Aiheesta muualla | Navigointivalikko37°38′36″N, 21°37′46″EInfobox OKArchaeological Museum of Olympia: HistoryArchaeological Museum of Olympia: DescriptionΜουσείο Ιστορίας των Ολυμπιακών Αγώνων της Αρχαιότητας: ΙστορικόArchaeological Museum of Olympia

                    Äpy Sisällysluettelo Äpyt kautta historian | Esimerkkejä Äpy-huumorista | Katso myös | Kirjallisuutta | Aiheesta muualla | Navigointivalikkowww.äpy.fi