cancel
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:

   mysite.com/checkout.php/checkout/cart/?SID=.....

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 

   mysite.com/index.php/checkout/cart/?SID=.....

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. 

ini_set("displayErrors",1);
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';
Mage::app();

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

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

// 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>";
    }$cart->save();

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

echo $url;

 

2 REPLIES 2

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 

 

#Varien_Profiler::enable();

//if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
//}

#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