【问题标题】:Get cart content outside of Magento but on same domain在 Magento 之外但在同一域中获取购物车内容
【发布时间】:2015-03-10 00:27:00
【问题描述】:

我需要以某种方式使我的 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 magento magento-1.9


    【解决方案1】:

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

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

    其他域的更多参考:

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

    【讨论】:

      猜你喜欢
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多