我需要以某种方式让我的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();
}
答案 0 :(得分:2)
这是一个有效的独立文件:
<?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?