Programatically clear the cart of a logged-in user The 2019 Stack Overflow Developer Survey Results Are InWhy is shopping cart not emptied after placing an order?Cart empties itself very quicklyCart ID in MagentoHow to create Mouseover Shopping Cart Icon in right header?Logout user while preserving cart contentsGrand total is zero with items in the cartUnable to get cart items for a user on login eventHow to redirect cart page from checkout onepage when product out of stock ?Magento 2 - how to set a message for the customer cart page after removing cart items via cronjobImplementing a persistent cart for guestsMagento 2 Clear cart is not working
What information about me do stores get via my credit card?
How to charge AirPods to keep battery healthy?
Does adding complexity mean a more secure cipher?
What is this business jet?
Relationship between Gromov-Witten and Taubes' Gromov invariant
Is it okay to consider publishing in my first year of PhD?
I am an eight letter word. What am I?
How can I add encounters in the Lost Mine of Phandelver campaign without giving PCs too much XP?
How to support a colleague who finds meetings extremely tiring?
How do PCB vias affect signal quality?
How to type a long/em dash `—`
What is the light source in the black hole images?
Getting crown tickets for Statue of Liberty
Is it possible for absolutely everyone to attain enlightenment?
What is the meaning of Triage in Cybersec world?
What's the name of these plastic connectors
Why was M87 targeted for the Event Horizon Telescope instead of Sagittarius A*?
What do I do when my TA workload is more than expected?
APIPA and LAN Broadcast Domain
What is the motivation for a law requiring 2 parties to consent for recording a conversation
A word that means fill it to the required quantity
Straighten subgroup lattice
$EDITOR environment variable won't set
How come people say “Would of”?
Programatically clear the cart of a logged-in user
The 2019 Stack Overflow Developer Survey Results Are InWhy is shopping cart not emptied after placing an order?Cart empties itself very quicklyCart ID in MagentoHow to create Mouseover Shopping Cart Icon in right header?Logout user while preserving cart contentsGrand total is zero with items in the cartUnable to get cart items for a user on login eventHow to redirect cart page from checkout onepage when product out of stock ?Magento 2 - how to set a message for the customer cart page after removing cart items via cronjobImplementing a persistent cart for guestsMagento 2 Clear cart is not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
TL;DR
When a customer is logged in, Mage::getSingleton('checkout/session')->clear(); doesn't clear their cart. I need something that will.
I've asked this as part of another question, but i discovered it was actually two problems, other other one now fixed.
I'm programatically creating an order in a controller using the items in the cart. After the order is saved the cart should be cleared. I do this using
Mage::getSingleton('checkout/session')->clear();
which works fine most of the time. The problem comes when the customer is logged-in. If they are logged in the cart doesn't clear. I've found other solutions (like load the cart items and removed them one at a time in a loop) but they don't meet all my requirements. WHat I need is something that will:
- remove all the items (obviously)
- stay on the same page (why loading the cart doesn't seem to work. I end up redirected to the cart page)
- NOT go to another page and then come back (2 redirects won't work in this case)
Is there something different I need to do when they are logged in? How can I get the cart cleared? Thanks all for the help.
cart controllers login shopping-cart user
add a comment |
TL;DR
When a customer is logged in, Mage::getSingleton('checkout/session')->clear(); doesn't clear their cart. I need something that will.
I've asked this as part of another question, but i discovered it was actually two problems, other other one now fixed.
I'm programatically creating an order in a controller using the items in the cart. After the order is saved the cart should be cleared. I do this using
Mage::getSingleton('checkout/session')->clear();
which works fine most of the time. The problem comes when the customer is logged-in. If they are logged in the cart doesn't clear. I've found other solutions (like load the cart items and removed them one at a time in a loop) but they don't meet all my requirements. WHat I need is something that will:
- remove all the items (obviously)
- stay on the same page (why loading the cart doesn't seem to work. I end up redirected to the cart page)
- NOT go to another page and then come back (2 redirects won't work in this case)
Is there something different I need to do when they are logged in? How can I get the cart cleared? Thanks all for the help.
cart controllers login shopping-cart user
If you create an order programmatically following the normal Magento process, the cart should I think end up empty automatically. What steps are you taking to create the order?
– Jonathan Hussey
Oct 22 '14 at 10:31
add a comment |
TL;DR
When a customer is logged in, Mage::getSingleton('checkout/session')->clear(); doesn't clear their cart. I need something that will.
I've asked this as part of another question, but i discovered it was actually two problems, other other one now fixed.
I'm programatically creating an order in a controller using the items in the cart. After the order is saved the cart should be cleared. I do this using
Mage::getSingleton('checkout/session')->clear();
which works fine most of the time. The problem comes when the customer is logged-in. If they are logged in the cart doesn't clear. I've found other solutions (like load the cart items and removed them one at a time in a loop) but they don't meet all my requirements. WHat I need is something that will:
- remove all the items (obviously)
- stay on the same page (why loading the cart doesn't seem to work. I end up redirected to the cart page)
- NOT go to another page and then come back (2 redirects won't work in this case)
Is there something different I need to do when they are logged in? How can I get the cart cleared? Thanks all for the help.
cart controllers login shopping-cart user
TL;DR
When a customer is logged in, Mage::getSingleton('checkout/session')->clear(); doesn't clear their cart. I need something that will.
I've asked this as part of another question, but i discovered it was actually two problems, other other one now fixed.
I'm programatically creating an order in a controller using the items in the cart. After the order is saved the cart should be cleared. I do this using
Mage::getSingleton('checkout/session')->clear();
which works fine most of the time. The problem comes when the customer is logged-in. If they are logged in the cart doesn't clear. I've found other solutions (like load the cart items and removed them one at a time in a loop) but they don't meet all my requirements. WHat I need is something that will:
- remove all the items (obviously)
- stay on the same page (why loading the cart doesn't seem to work. I end up redirected to the cart page)
- NOT go to another page and then come back (2 redirects won't work in this case)
Is there something different I need to do when they are logged in? How can I get the cart cleared? Thanks all for the help.
cart controllers login shopping-cart user
cart controllers login shopping-cart user
asked Oct 22 '14 at 10:02
Matt FlammMatt Flamm
124213
124213
If you create an order programmatically following the normal Magento process, the cart should I think end up empty automatically. What steps are you taking to create the order?
– Jonathan Hussey
Oct 22 '14 at 10:31
add a comment |
If you create an order programmatically following the normal Magento process, the cart should I think end up empty automatically. What steps are you taking to create the order?
– Jonathan Hussey
Oct 22 '14 at 10:31
If you create an order programmatically following the normal Magento process, the cart should I think end up empty automatically. What steps are you taking to create the order?
– Jonathan Hussey
Oct 22 '14 at 10:31
If you create an order programmatically following the normal Magento process, the cart should I think end up empty automatically. What steps are you taking to create the order?
– Jonathan Hussey
Oct 22 '14 at 10:31
add a comment |
4 Answers
4
active
oldest
votes
Check quote status is_active for the quote (sales_flat_quote) regarding to the created order. If its active (value is 1) set it inactive ($quote->setIsActive(0)->save()) after successfully order creation and than clear checkout session.
This seems to be doing it. The process it follows leaves magento before the quote is made inactive, then comes back to create the order after that would have happened. This seems to make it work just fine.
– Matt Flamm
Oct 27 '14 at 13:02
add a comment |
This is against standard Magento logic, so you need a custom module that will observe customer_logout event and execute the following code bit:
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item )
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
more info
I'm not trying to clear it at log-out, rather to clear it after the order is made while still on the success screen
– Matt Flamm
Oct 23 '14 at 13:54
add a comment |
/** @var Mage_Sales_Model_Quote $quote */
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->removeAllItems()->save();
Method 'removeAllItems' not found
– TheKitMurkit
Dec 20 '17 at 21:49
add a comment |
This should do a job (note that without checking if cart actually has items it will not work good):
$cart = Mage::getSingleton('checkout/cart');
if (count($cart->getItems()))
$cart->truncate();
$cart->save();
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%2f40992%2fprogramatically-clear-the-cart-of-a-logged-in-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Check quote status is_active for the quote (sales_flat_quote) regarding to the created order. If its active (value is 1) set it inactive ($quote->setIsActive(0)->save()) after successfully order creation and than clear checkout session.
This seems to be doing it. The process it follows leaves magento before the quote is made inactive, then comes back to create the order after that would have happened. This seems to make it work just fine.
– Matt Flamm
Oct 27 '14 at 13:02
add a comment |
Check quote status is_active for the quote (sales_flat_quote) regarding to the created order. If its active (value is 1) set it inactive ($quote->setIsActive(0)->save()) after successfully order creation and than clear checkout session.
This seems to be doing it. The process it follows leaves magento before the quote is made inactive, then comes back to create the order after that would have happened. This seems to make it work just fine.
– Matt Flamm
Oct 27 '14 at 13:02
add a comment |
Check quote status is_active for the quote (sales_flat_quote) regarding to the created order. If its active (value is 1) set it inactive ($quote->setIsActive(0)->save()) after successfully order creation and than clear checkout session.
Check quote status is_active for the quote (sales_flat_quote) regarding to the created order. If its active (value is 1) set it inactive ($quote->setIsActive(0)->save()) after successfully order creation and than clear checkout session.
edited Sep 22 '17 at 2:09
Amit Bera♦
59.9k1677178
59.9k1677178
answered Oct 22 '14 at 10:40
Stefan BothnerStefan Bothner
1866
1866
This seems to be doing it. The process it follows leaves magento before the quote is made inactive, then comes back to create the order after that would have happened. This seems to make it work just fine.
– Matt Flamm
Oct 27 '14 at 13:02
add a comment |
This seems to be doing it. The process it follows leaves magento before the quote is made inactive, then comes back to create the order after that would have happened. This seems to make it work just fine.
– Matt Flamm
Oct 27 '14 at 13:02
This seems to be doing it. The process it follows leaves magento before the quote is made inactive, then comes back to create the order after that would have happened. This seems to make it work just fine.
– Matt Flamm
Oct 27 '14 at 13:02
This seems to be doing it. The process it follows leaves magento before the quote is made inactive, then comes back to create the order after that would have happened. This seems to make it work just fine.
– Matt Flamm
Oct 27 '14 at 13:02
add a comment |
This is against standard Magento logic, so you need a custom module that will observe customer_logout event and execute the following code bit:
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item )
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
more info
I'm not trying to clear it at log-out, rather to clear it after the order is made while still on the success screen
– Matt Flamm
Oct 23 '14 at 13:54
add a comment |
This is against standard Magento logic, so you need a custom module that will observe customer_logout event and execute the following code bit:
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item )
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
more info
I'm not trying to clear it at log-out, rather to clear it after the order is made while still on the success screen
– Matt Flamm
Oct 23 '14 at 13:54
add a comment |
This is against standard Magento logic, so you need a custom module that will observe customer_logout event and execute the following code bit:
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item )
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
more info
This is against standard Magento logic, so you need a custom module that will observe customer_logout event and execute the following code bit:
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item )
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
more info
edited May 5 '18 at 8:38
Teja Bhagavan Kollepara
2,98841949
2,98841949
answered Oct 22 '14 at 10:57
ravi patelravi patel
576418
576418
I'm not trying to clear it at log-out, rather to clear it after the order is made while still on the success screen
– Matt Flamm
Oct 23 '14 at 13:54
add a comment |
I'm not trying to clear it at log-out, rather to clear it after the order is made while still on the success screen
– Matt Flamm
Oct 23 '14 at 13:54
I'm not trying to clear it at log-out, rather to clear it after the order is made while still on the success screen
– Matt Flamm
Oct 23 '14 at 13:54
I'm not trying to clear it at log-out, rather to clear it after the order is made while still on the success screen
– Matt Flamm
Oct 23 '14 at 13:54
add a comment |
/** @var Mage_Sales_Model_Quote $quote */
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->removeAllItems()->save();
Method 'removeAllItems' not found
– TheKitMurkit
Dec 20 '17 at 21:49
add a comment |
/** @var Mage_Sales_Model_Quote $quote */
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->removeAllItems()->save();
Method 'removeAllItems' not found
– TheKitMurkit
Dec 20 '17 at 21:49
add a comment |
/** @var Mage_Sales_Model_Quote $quote */
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->removeAllItems()->save();
/** @var Mage_Sales_Model_Quote $quote */
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->removeAllItems()->save();
answered Sep 21 '17 at 23:14
zlikzlik
211
211
Method 'removeAllItems' not found
– TheKitMurkit
Dec 20 '17 at 21:49
add a comment |
Method 'removeAllItems' not found
– TheKitMurkit
Dec 20 '17 at 21:49
Method 'removeAllItems' not found
– TheKitMurkit
Dec 20 '17 at 21:49
Method 'removeAllItems' not found
– TheKitMurkit
Dec 20 '17 at 21:49
add a comment |
This should do a job (note that without checking if cart actually has items it will not work good):
$cart = Mage::getSingleton('checkout/cart');
if (count($cart->getItems()))
$cart->truncate();
$cart->save();
add a comment |
This should do a job (note that without checking if cart actually has items it will not work good):
$cart = Mage::getSingleton('checkout/cart');
if (count($cart->getItems()))
$cart->truncate();
$cart->save();
add a comment |
This should do a job (note that without checking if cart actually has items it will not work good):
$cart = Mage::getSingleton('checkout/cart');
if (count($cart->getItems()))
$cart->truncate();
$cart->save();
This should do a job (note that without checking if cart actually has items it will not work good):
$cart = Mage::getSingleton('checkout/cart');
if (count($cart->getItems()))
$cart->truncate();
$cart->save();
answered Apr 8 at 9:22
Anton SuslovAnton Suslov
112
112
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%2f40992%2fprogramatically-clear-the-cart-of-a-logged-in-user%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
If you create an order programmatically following the normal Magento process, the cart should I think end up empty automatically. What steps are you taking to create the order?
– Jonathan Hussey
Oct 22 '14 at 10:31