I'm trying, for various reasons, to use an "external" (as in non-Magento) frontend. I do want to keep the checkout process (because I want the order/shipping/invoicing functionality) in Magento, so I obviously must keep the Cart in Magento as well. However, I can not get the "other" frontend to share the Cart with my Magento installation.
The custom frontend is:
- Integrated by simply including the Mage.php file (heavily inspired by Magento-on-Angular) and using it's method for adding items to cart
- On the same domain (for now, localhost or 127.0.0.1)
- Working fine in isolation in both "systems" (i.e add-to-cart is actually adding to the cart in the same frontend, but not shared).
- Not given the same output from
Mage::getSingleton("core/session")->getEncryptedSessionId()
- Given the same output from
\Mage::app()->getWebsite()->getId()
- Not given the same output from
Mage::getSingleton('checkout/session')->getQuote()->getId()
- Using Laravel as framework
I do realize that a possible workaround would be to somehow force the getQuote()->getId() in the real Magento when passing cutomer to checkout. This does feel dirty though, and will probably cause lots of lost Carts (that's just a not educated guess though).
Actual code (stripped down and combined from several methods)
Custom Frontend - add to cart
session_start();
\Mage::getSingleton('customer/session')->start();
$product = \Mage::getModel('catalog/product')->load((int) $productId);
$basket = \Mage::getSingleton('checkout/cart');
$basket->addProduct($product, 1);
$basket->save();
Custom Frontend - show cart sub total
session_start();
\Mage::getSingleton('customer/session')->start();
$session = \Mage::getSingleton('checkout/session');
$quote = $session->getQuote();
$items = $quote->getAllItems();
$data = array();
$totals = $quote->getTotals();
$subTotal = $totals['subtotal']->getValue();
$grandTotal = $totals['grand_total']->getValue();
The frontend is of course adding products that exist.
My best guess is that the fact that Laravel's bootstrap process starts the session before Magento comes in to play is a problem. If so, the question might be "how to "inject" a session into Magento programmatically".
What am I doing wrong?