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

Does grappling negate Mirror Image?

Why Shazam when there is already Superman?

Why the "ls" command is showing the permissions of files in a FAT32 partition?

When were female captains banned from Starfleet?

What (the heck) is a Super Worm Equinox Moon?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

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

Multiplicative persistence

What kind of floor tile is this?

Does Doodling or Improvising on the Piano Have Any Benefits?

Why do ¬, ∀ and ∃ have the same precedence?

Is it allowed to activate the ability of multiple planeswalkers in a single turn?

How much of a Devil Fruit must be consumed to gain the power?

Doesn't the system of the Supreme Court oppose justice?

How to make money from a browser who sees 5 seconds into the future of any web page?

Find the next value of this number series

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?

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

Why is the Sun approximated as a black body at ~ 5800 K?

Which was the first story featuring espers?

Stack Interview Code methods made from class Node and Smart Pointers

How to preserve electronics (computers, iPads and phones) for hundreds of years

Is this toilet slogan correct usage of the English language?

awk assign to multiple variables at once



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 23 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 23 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 23 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 23 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

                    Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                    How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2

                    Nissan Patrol Зміст Перше покоління — 4W60 (1951-1960) | Друге покоління — 60 series (1960-1980) | Третє покоління (1980–2002) | Четверте покоління — Y60 (1987–1998) | П'яте покоління — Y61 (1997–2013) | Шосте покоління — Y62 (2010- ) | Посилання | Зноски | Навігаційне менюОфіційний український сайтТест-драйв Nissan Patrol 2010 7-го поколінняNissan PatrolКак мы тестировали Nissan Patrol 2016рвиправивши або дописавши її