2

I searched and was unable to find anything. I've tried many solutions such as: How to get all items in cart currently? as far as I can tell it should work in Magento 1.8. I've tried Mage::getModel('checkout/cart')->getQuote(); and Mage::getSingleton('checkout/session')->getQuote();

An example of something I tried:

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
    echo "something";
}

Doing print_r on $cart shows that $_items is empty and Mage::helper('checkout/cart')->getItemsCount(); returns 0.

Full example code to clear confusion, error reporting is on:

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',true);

require_once('app/Mage.php');  
umask(0);
Mage::app();

$totalItems = Mage::helper('checkout/cart')->getItemsCount();
if( $totalItems == 0 )
{
    echo "0 items";
}

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item)
{
    echo "something";
}

Someone will visit the magento store, add items to their basket and then click a link which takes them a PHP file. However, their basket is always empty when checked from the external file. Is there a problem with the code or the magento configuration or is the wrong way to do it in Magento 1.8?

closed as too broad by Marius Jun 16 '15 at 8:11

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • what do u mean by external file? – MTM Aug 28 '14 at 10:36
  • Are you running Mage::app() in the file. – Dan Hanly Aug 28 '14 at 10:55
  • From an external file? The cart is of course linked to a session. Which cart items do you expect to get? You would only get cart items if you put some items in the cart in your external file beforehand. – Simon Aug 28 '14 at 11:11
  • Updated to clear things up. By 'external' file I mean a php file which someone will navigate to afterp lacing items in their basket. – browndesk965 Aug 29 '14 at 8:15