I have a unique workflow for redeeming vouchers on our site through Magento. I have a form that users use for inputting a series of vouchers to get products. It isn't "in" Magento as a CMS page or anything of that nature. The code I am using to achieve access to Magento's resources/models is as followed:


require_once('../app/Mage.php'); //Path to Magento

// Now you can run ANY Magento code you want

* Get the resource model
$resource = Mage::getSingleton('core/resource');

I have several codes that can be used to clear session or cart contents but for whatever reason, I can't get them to work by just calling on Mage.php. Here are my codes:

Version 1:

// Empty shopping cart

Version 2:

// Clear session data

Version 3:

$quote = Mage::getSingleton('checkout/session')->getQuote();

None of these will work with the method I listed above. I am placing it after the "$resource..." line. Is there a better way to do this?

The Goal: Everytime a user visits this "voucher form", which is the landing page - I want their shopping cart to be emptied. Thanks.

2 Answers 2


This one should work as it removes all items from the current quote:


But you need to save it afterwards:


By the way, you can remove the following line:

$resource = Mage::getSingleton('core/resource');

since you don't use the variable and instantiating this singleton doesn't do anything in particular.

  • the ->save() is the function I needed even in M2.
    – dchayka
    Sep 5, 2018 at 20:43
  • This removes all items from the cart but leaves the number of items in cart intact. That means there are no items in cart but it shows the number yet. Any idea?
    – revo
    Sep 17, 2018 at 10:04

You can't get result what you want through this code.


You need to use ->save() to achieve what you want.


Hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.