1

I have a script that adds items to a cart from an external source. The cart is created and products added and now I want to return a URL to the cart.

This URL should open the checkout cart and display the cart contents.

Here is the script so far but it opens to an empty cart

<?php

include '../app/Mage.php';
Mage::app();

$cartId = $_GET['id'];

$quote = Mage::getModel('sales/quote')->load($cartId);

$quote->setIsActive(true)->save();

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

echo $Url;

?>
3
  • Is it just one product always? If so why don´t you just use this www.yourUrl/checkout/cart/add/product/PRODUCTID ?
    – seb
    Commented Jul 20, 2016 at 15:44
  • No there are multiple products added to the cart in another php script. So once the cart is created and products added I need to open a new window from a url to view the checkout page
    – alQemist
    Commented Jul 20, 2016 at 16:09
  • I need a way to open a previously populated cart using cart id / url
    – alQemist
    Commented Jul 20, 2016 at 16:14

1 Answer 1

0

Replace current quote:

$quote = Mage::getModel('sales/quote')->load($quoteId);
Mage::getSingleton('checkout/session')->replaceQuote($quote);

But it will be better to merge custom quote items to current quote

$currentQuote = Mage::getSingleton('checkout/session')->getQuote();
var_dump($currentQuote->getData());

$items = $currentQuote->getAllItems();

var_dump('before: ' . count($items) . ' items');
foreach ($items as $item) {
    var_dump($item->getId());
}

$quote = Mage::getModel('sales/quote')->load($quoteId);

// add custom validation
$isAllowedToBeAdded = $quote->getId();

if ($isAllowedToBeAdded) {

    // Merge your quote to current quote
    $currentQuote->merge($quote)
        ->collectTotals()
        ->save();

    Mage::getSingleton('checkout/session')->replaceQuote($currentQuote);
}

$items = $currentQuote->getAllItems();
var_dump('after: ' . count($items) . ' items');
foreach ($items as $item) {
    var_dump($item->getId());
}
var_dump($currentQuote->getData());
1
  • This is fine - the products are in the cart - now how to return a URL from your example that will open the checkout page ?? www.mySite.com/checkout.php/checkout/cart --- returns 404 www.mySite.com/index.php/checkout/cart - opens empty cart page
    – alQemist
    Commented Jul 21, 2016 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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