环境:Magento Enterprise 1.12,Redhat Linux
我正在尝试用最少的代码在 Magento(企业 1.12)中开发一个独立的 php 页面来显示购物车信息。这将由显示来自 Magento 商店的基本购物车信息的外部网站使用。如果可能,我会尽量避免使用成熟的自定义 MVC 模型,因为我只是想获得最少的只读信息。
我想显示:
- 购物车中的商品数量(无论是否登录)
- 购物车中的产品名称(如果它不为空)
- 用户是否登录
- 客户名称(如果他们已登录)
我在网上看到了很多关于此的帖子,并且尝试了所有示例但没有成功。
这是我正在尝试的:
require_once 'app/Mage.php';
umask(0);
Mage::app();
// The following three variables are successfully set
// but they don't help with what I'm trying to do
$session = Mage::getModel('core/cookie')->get('frontend');
$cartid = Mage::getModel('core/cookie')->get('CART');
$sid = Mage::getModel("core/session")->getEncryptedSessionId();
echo "session=$session <br />\n";
echo "cartid=$cartid <br />\n";
echo "sid=$sid <br />\n";
// None of the following seem to work, whether or not I''m logged in
$cart = Mage::getSingleton('checkout/cart')->getItemsCount();
echo "cart items count: $cart <br />\n";
$cart = Mage::helper('checkout/cart')->getItemsCount();
echo "cart items count: $cart <br />\n";
$cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
echo "cart items count: $cart <br />\n";
$cart = Mage::helper('checkout/cart')->getCart()->getQuote()->getItemsCount();
echo "cart items count: $cart <br />\n";
$count = Mage::helper('checkout/cart')->getSummaryCount();
echo "cart items count: $cart <br />\n";
// None of the following seem to work. I'm logged in, but the following code says I'm not.
$session = Mage::getSingleton("customer/session");
if($session->isLoggedIn()) { echo "logged in <br />\n"; } else { echo "not logged in <br />\n"; }
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
if($session->isLoggedIn()) { echo "logged in <br />\n"; } else { echo "not logged in <br />\n"; }
非常感谢任何帮助。