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
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
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.
add a comment |
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
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.
add a comment |
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
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
magento2 magento-2.1 php
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.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 18 '17 at 17:00
Andrey KonosovAndrey Konosov
381111
381111
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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