I want to add dynamically new products in the cart during the checkout process, but I've no clear the differences between the Quote and the Cart.
In my catalog pages I'm adding contents directly to the cart with:
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
$cart->addProduct($product, $params);
$cart->save();
whereas in the checkout process I am using:
$quote = $this->getOnepage()->getQuote();
$product = Mage::getModel('catalog/product')->load(
$params = array(
'product' => 113,
'qty' => 1
);
$quoteItem = Mage::getModel('sales/quote_item')->setProduct($product)->setQty(1);
$quoteItem->setStoreId(Mage::app()->getStore()->getId());
$quote->addItem($quoteItem);
$quote->save();
Not sure why I am doing like that 🙂 Does it make sense to also add the products in the cart in that last step?
Can someone throw some light on this?
Best Answer
The cart model is an abstraction for the quote (or better: for the items in the cart) and you should use it wherever possible. Working with the quote object directly when it comes to adding, removing and changing items is complicated and almost never necessary.
As I've written in Programmatically create an order of grouped and bundle product in Magento: