Magento 2 : Cart Total Not UpdatingHow to call a model method from controller in Magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleMagento 2: How to override newsletter Subscriber modelMagento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridAdd configure product in Cart using Magento 2 API facing an issueI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.3 Can't view module's front end page output?Magento 2.2.6: Programatically updating product custom options
Possibly bubble sort algorithm
How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?
Should I join office cleaning event for free?
New order #4: World
If Manufacturer spice model and Datasheet give different values which should I use?
Email Account under attack (really) - anything I can do?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
GPS Rollover on Android Smartphones
Is it possible to make sharp wind that can cut stuff from afar?
Why are only specific transaction types accepted into the mempool?
Download, install and reboot computer at night if needed
Is it possible to do 50 km distance without any previous training?
How to add power-LED to my small amplifier?
How is this relation reflexive?
Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?
Why is this code 6.5x slower with optimizations enabled?
Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).
Why CLRS example on residual networks does not follows its formula?
Copycat chess is back
Shell script can be run only with sh command
How to report a triplet of septets in NMR tabulation?
"You are your self first supporter", a more proper way to say it
Is Social Media Science Fiction?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
Magento 2 : Cart Total Not Updating
How to call a model method from controller in Magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleMagento 2: How to override newsletter Subscriber modelMagento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridAdd configure product in Cart using Magento 2 API facing an issueI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.3 Can't view module's front end page output?Magento 2.2.6: Programatically updating product custom options
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I added simple product with options programmatically into cart using this code.
namespace VendorExtensionControllerCustomer;
class Myclass extends MagentoFrameworkAppActionAction
protected $messageManager;
protected $custsession;
protected $_responseFactory;
protected $_url;
protected $_appRequestInterface;
public function __construct(MagentoFrameworkAppActionContext $context,
MagentoCustomerModelSession $custsession,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppRequestInterface $appRequestInterface,
MagentoFrameworkMessageManagerInterface $messageManager)
$this->custsession = $custsession;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
$this->_appRequestInterface = $appRequestInterface;
$this->messageManager = $messageManager;
parent::__construct($context);
public function execute()
if($this->custsession->isLoggedIn())
try
$params = [
'product' => 12,
'selected_configurable_option' => NULL,
'related_product' => NULL,
'options' => [
3 => 8,
],
'qty' => 2
];
$product = $om->create('MagentoCatalogModelProduct')->load(12);
$mycartp = $om->get('MagentoCheckoutModelCart');
$mycartp->addProduct($product,$params);
$mycartp->save();
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
$message = "Your quote has been successfully added to cart";
$this->messageManager->addSuccess($message);
$accUrl = $this->_url->getUrl('checkout/cart/');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
catch(Exception $e)
$this->messageManager->addError($e->getMessage());
$accUrl = $this->_url->getUrl('extension/controller/mypage');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
else
$accUrl = $this->_url->getUrl('customer/account/login');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
The product sucessfully added to cart with options, but it not show correct subtotal in cart page and mini-cart. See below screen-sort.
One's I click on "Update Shopping Cart" it show correct total. See below screen-sort.
Any one know about this?
magento2 product cart totals
add a comment |
I added simple product with options programmatically into cart using this code.
namespace VendorExtensionControllerCustomer;
class Myclass extends MagentoFrameworkAppActionAction
protected $messageManager;
protected $custsession;
protected $_responseFactory;
protected $_url;
protected $_appRequestInterface;
public function __construct(MagentoFrameworkAppActionContext $context,
MagentoCustomerModelSession $custsession,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppRequestInterface $appRequestInterface,
MagentoFrameworkMessageManagerInterface $messageManager)
$this->custsession = $custsession;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
$this->_appRequestInterface = $appRequestInterface;
$this->messageManager = $messageManager;
parent::__construct($context);
public function execute()
if($this->custsession->isLoggedIn())
try
$params = [
'product' => 12,
'selected_configurable_option' => NULL,
'related_product' => NULL,
'options' => [
3 => 8,
],
'qty' => 2
];
$product = $om->create('MagentoCatalogModelProduct')->load(12);
$mycartp = $om->get('MagentoCheckoutModelCart');
$mycartp->addProduct($product,$params);
$mycartp->save();
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
$message = "Your quote has been successfully added to cart";
$this->messageManager->addSuccess($message);
$accUrl = $this->_url->getUrl('checkout/cart/');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
catch(Exception $e)
$this->messageManager->addError($e->getMessage());
$accUrl = $this->_url->getUrl('extension/controller/mypage');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
else
$accUrl = $this->_url->getUrl('customer/account/login');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
The product sucessfully added to cart with options, but it not show correct subtotal in cart page and mini-cart. See below screen-sort.
One's I click on "Update Shopping Cart" it show correct total. See below screen-sort.
Any one know about this?
magento2 product cart totals
did you ever find a solution to this?
– pixiemedia
Aug 27 '17 at 12:09
add a comment |
I added simple product with options programmatically into cart using this code.
namespace VendorExtensionControllerCustomer;
class Myclass extends MagentoFrameworkAppActionAction
protected $messageManager;
protected $custsession;
protected $_responseFactory;
protected $_url;
protected $_appRequestInterface;
public function __construct(MagentoFrameworkAppActionContext $context,
MagentoCustomerModelSession $custsession,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppRequestInterface $appRequestInterface,
MagentoFrameworkMessageManagerInterface $messageManager)
$this->custsession = $custsession;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
$this->_appRequestInterface = $appRequestInterface;
$this->messageManager = $messageManager;
parent::__construct($context);
public function execute()
if($this->custsession->isLoggedIn())
try
$params = [
'product' => 12,
'selected_configurable_option' => NULL,
'related_product' => NULL,
'options' => [
3 => 8,
],
'qty' => 2
];
$product = $om->create('MagentoCatalogModelProduct')->load(12);
$mycartp = $om->get('MagentoCheckoutModelCart');
$mycartp->addProduct($product,$params);
$mycartp->save();
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
$message = "Your quote has been successfully added to cart";
$this->messageManager->addSuccess($message);
$accUrl = $this->_url->getUrl('checkout/cart/');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
catch(Exception $e)
$this->messageManager->addError($e->getMessage());
$accUrl = $this->_url->getUrl('extension/controller/mypage');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
else
$accUrl = $this->_url->getUrl('customer/account/login');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
The product sucessfully added to cart with options, but it not show correct subtotal in cart page and mini-cart. See below screen-sort.
One's I click on "Update Shopping Cart" it show correct total. See below screen-sort.
Any one know about this?
magento2 product cart totals
I added simple product with options programmatically into cart using this code.
namespace VendorExtensionControllerCustomer;
class Myclass extends MagentoFrameworkAppActionAction
protected $messageManager;
protected $custsession;
protected $_responseFactory;
protected $_url;
protected $_appRequestInterface;
public function __construct(MagentoFrameworkAppActionContext $context,
MagentoCustomerModelSession $custsession,
MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppRequestInterface $appRequestInterface,
MagentoFrameworkMessageManagerInterface $messageManager)
$this->custsession = $custsession;
$this->_responseFactory = $responseFactory;
$this->_url = $url;
$this->_appRequestInterface = $appRequestInterface;
$this->messageManager = $messageManager;
parent::__construct($context);
public function execute()
if($this->custsession->isLoggedIn())
try
$params = [
'product' => 12,
'selected_configurable_option' => NULL,
'related_product' => NULL,
'options' => [
3 => 8,
],
'qty' => 2
];
$product = $om->create('MagentoCatalogModelProduct')->load(12);
$mycartp = $om->get('MagentoCheckoutModelCart');
$mycartp->addProduct($product,$params);
$mycartp->save();
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
$message = "Your quote has been successfully added to cart";
$this->messageManager->addSuccess($message);
$accUrl = $this->_url->getUrl('checkout/cart/');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
catch(Exception $e)
$this->messageManager->addError($e->getMessage());
$accUrl = $this->_url->getUrl('extension/controller/mypage');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
else
$accUrl = $this->_url->getUrl('customer/account/login');
$this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
exit;
The product sucessfully added to cart with options, but it not show correct subtotal in cart page and mini-cart. See below screen-sort.
One's I click on "Update Shopping Cart" it show correct total. See below screen-sort.
Any one know about this?
magento2 product cart totals
magento2 product cart totals
edited Aug 4 '17 at 5:16
Dhiren Vasoya
asked Mar 25 '17 at 3:15
Dhiren VasoyaDhiren Vasoya
4,39151844
4,39151844
did you ever find a solution to this?
– pixiemedia
Aug 27 '17 at 12:09
add a comment |
did you ever find a solution to this?
– pixiemedia
Aug 27 '17 at 12:09
did you ever find a solution to this?
– pixiemedia
Aug 27 '17 at 12:09
did you ever find a solution to this?
– pixiemedia
Aug 27 '17 at 12:09
add a comment |
1 Answer
1
active
oldest
votes
Please replace below code with my code :
Replace This :
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
Replace With :
$quoteRepository = $om->get('MagentoQuoteApiCartRepositoryInterface');
$quoteObject = $quoteRepository->get($mycartp->getQuote()->getId());
$quoteObject->setTriggerRecollect(1);
$quoteObject->setIsActive(true);
$quoteObject->collectTotals()->save();
Above code works for me. So please try this one.
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%2f166136%2fmagento-2-cart-total-not-updating%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
Please replace below code with my code :
Replace This :
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
Replace With :
$quoteRepository = $om->get('MagentoQuoteApiCartRepositoryInterface');
$quoteObject = $quoteRepository->get($mycartp->getQuote()->getId());
$quoteObject->setTriggerRecollect(1);
$quoteObject->setIsActive(true);
$quoteObject->collectTotals()->save();
Above code works for me. So please try this one.
add a comment |
Please replace below code with my code :
Replace This :
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
Replace With :
$quoteRepository = $om->get('MagentoQuoteApiCartRepositoryInterface');
$quoteObject = $quoteRepository->get($mycartp->getQuote()->getId());
$quoteObject->setTriggerRecollect(1);
$quoteObject->setIsActive(true);
$quoteObject->collectTotals()->save();
Above code works for me. So please try this one.
add a comment |
Please replace below code with my code :
Replace This :
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
Replace With :
$quoteRepository = $om->get('MagentoQuoteApiCartRepositoryInterface');
$quoteObject = $quoteRepository->get($mycartp->getQuote()->getId());
$quoteObject->setTriggerRecollect(1);
$quoteObject->setIsActive(true);
$quoteObject->collectTotals()->save();
Above code works for me. So please try this one.
Please replace below code with my code :
Replace This :
$quote = $om->get('MagentoQuoteModelQuote');
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
$checkout = $om->get('MagentoCheckoutModelSession');
$checkout->getQuote()->collectTotals()->save();
Replace With :
$quoteRepository = $om->get('MagentoQuoteApiCartRepositoryInterface');
$quoteObject = $quoteRepository->get($mycartp->getQuote()->getId());
$quoteObject->setTriggerRecollect(1);
$quoteObject->setIsActive(true);
$quoteObject->collectTotals()->save();
Above code works for me. So please try this one.
answered Apr 4 at 12:52
Sneha PanchalSneha Panchal
550325
550325
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%2f166136%2fmagento-2-cart-total-not-updating%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
did you ever find a solution to this?
– pixiemedia
Aug 27 '17 at 12:09