Showing results for 
Search instead for 
Did you mean: 

Shopping Cart Empty with 404

Shopping Cart Empty with 404

I have the following script which adds products to a cart from a remote UI via cURL from another domain. The products are submitted to the script as XML, parsed, added to the cart and then I need to return the url (string) to the checkout page. Adding to the cart is working - the products get added without errors but when using the URL to open the checkout it returns 404 message with an empty cart.

The url is typically something like:

which is derived by using - Mage::getUrl('checkout/cart');

When using the URL to view the cart the page loads with a 404 , I can manually change it to

The cart appears as expected. However trying to use this index.php url instead, bypassing the checkout.php/checkout/cart it also shows an empty cart.

I am hoping the problem is obvious to someone with more Magento experience. 

error_reporting(E_ERROR | E_PARSE | E_ALL );

 // xml payload submitted to this script
 $postXML = file_get_contents('php://input');

// convert xml string to xml document
$xml = new SimpleXMLElement($postXML);

include '../app/Mage.php';

$core_session = Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton('customer/session');

$cart = Mage::getSingleton('checkout/cart');

// array for submitted product ids and qty
$cartitems = [];

foreach($xml->lineitems->item as $item)
 $product = [];
 $product[] = $item->qty;
 $product[] = $item->sku;
 $cartitems[] = $product;  

// add products to cart
foreach($cartitems as $citem){
    try {
        $product_id = Mage::getModel("catalog/product")->getIdBySku( $citem[1] ); 
        $qty = $citem[0]-0; // Replace qty with your qty
        $product = Mage::getModel('catalog/product')->load($product_id);
         $cart->addProduct($product, array('qty' => $qty));
         //echo "added";
    } catch (Exception $e) {
       echo $e->getMessage()." ".$product_id."<br>";

$url = Mage::getUrl('checkout/cart');

echo $url;



Re: Shopping Cart Empty with 404

To fix it, you should know the exact 404 error that you are getting. For this, you need to enable the debugging mode.


To enable it, edit the index.php file in root directory and change the code like this 



//if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {

#ini_set('display_errors', 1);

Re: Shopping Cart Empty with 404

Thank you for that suggestion. Let me clarify that only the title of the page is "404 Not Found 1"  there may not be a server error per se...


I did edit the index.php but there was no error reporting as a result