在Magento之外但在同一域上获取购物车内容


Get cart content outside of Magento but on same domain

我需要以某种方式使Magento商店中的当前购物车和客户信息可供Magento以外的网站其余部分访问。

例如,mysite.com/blog 不在 mysite.com/store 之内。

在我的域基础中,我已经运行了此代码,但它只返回 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();
}

这是一个工作的独立文件:

<?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 );
        }
    }
?>

其他域的更多参考:

如何从Magento外部访问Magento客户的会话?