外部网站的Magento购物车信息

时间:2013-02-11 19:42:48

标签: magento cart

环境:Magento Enterprise 1.12,Redhat Linux

我正在尝试使用显示购物车信息的最小代码在Magento(Enterprise 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"; }

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

<强>更新

我通过System-&gt;下的管理部分设置了cookie路径。配置 - &gt; Web-&gt;会话Cookie管理。

然后我创建了一个test.php并将你的代码复制到文件中,并在Mage :: app()之后添加了一行:

Mage::getSingleton('core/session', array('name'=>'frontend'));