1

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?

  • By external frontend do you mean on another domain or subdomain or subdirectory? If it's the same domain you would be able to use the session like this. On another domain i think using the session will require some tricky workaround. Maybe you should create your own cart and when checking out making a complete request to magento so it generates an invoice and such. Like creating some sort of API between magento and your system. this website has a good article on that. inchoo.net/magento/programmatically-create-order-in-magento – FROSIT Jul 17 '15 at 22:55
  • Hi. It is on the same domain. The mage.php used on custom frontend is the same mage.php used on the actual magento frontend. What i basically want is to force the session (at least CART session) to be the same session, without caring about of it it's from Laravel or Magento. – Christoffer Tyrefors Jul 18 '15 at 10:37
0

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".

Yes, and the simplest solution will be to close the Laravel session before initializing Magento:

\session_write_close();
\Mage::app();

Then Magento can open its own session (with the session name "frontend") and you don't have to do anything else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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