在Magento之外但在同一域中获取购物车内容 [英] Get cart content outside of Magento but on same domain

查看:58
本文介绍了在Magento之外但在同一域中获取购物车内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以某种方式使Magento商店之外的Magento商店中的其他人可以访问我的Magento商店中的当前购物车和客户信息.

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.

例如,mysite.com/blog在mysite.com/store之外.

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

在我的域的基础上,我运行了这段代码,但是它只返回NULL.

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

推荐答案

这是一个有效的独立文件:

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

其他域的更多参考:

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

这篇关于在Magento之外但在同一域中获取购物车内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆