3

I need to somehow make the current cart and customer info in my Magento store be accessible to the rest of my website, outside of Magento.

For example mysite.com/blog is outside of mysite.com/store.

In the base of my domain I have run this code but it just returns NULL.

require_once 'store/app/Mage.php';
umask(0);
Mage::app();

Mage::getSingleton('core/session', array('name'=>'frontend'));
$totalItems = Mage::getModel('checkout/cart')->getQuote();

$cart = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
foreach ($cart->getAllItems() as $item) {
    $productName = $item->getProduct()->getName();
    $productPrice = $item->getProduct()->getPrice();
}
Mark
  • 622
  • 11
  • 27

1 Answers1

2

Here's a working standalone file:

<?php
    require_once( 'app/Mage.php' );

    umask(0);
    Mage::app('default');

    // This has to run to authenticate customer and checkout session calls.
    Mage::getSingleton('core/session', array('name' => 'frontend'));

    // Get any customer model you desire.
    $oSession = Mage::getSingleton( 'customer/session' );
    $oCustomer = $oSession->getCustomer();
    $oCheckout = Mage::getSingleton( 'checkout/session' );
    $oQuote = $oCheckout->getQuote();

    var_dump( $oCustomer );
    var_dump( $oSession );
    var_dump( $oQuote );
    var_dump( $oCheckout );

    $oCart = $oQuote->getAllItems();
    if( !empty( $oCart ) )
    {
        foreach ( $oCart as $oItem ) 
        {
            $sName  = $oItem->getProduct()->getName();
            $fPrice = $oItem->getProduct()->getPrice();
            var_dump( $sName );
            var_dump( $fPrice );
        }
    }
?>

More reference for other domains:

How to access Magento customer's session from outside Magento?

Community
  • 1
  • 1
Vladimir Ramik
  • 1,920
  • 2
  • 13
  • 23