2
環境:用最少的代碼來顯示購物車信息Magento企業1.12,紅帽LinuxMagento的購物車信息的外部網站
我試圖開發Magento的一個獨立的PHP頁面(企業1.12)。這將用於顯示來自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"; }
任何幫助,非常感謝。
非常感謝您的回覆,但它返回一個空值,在購物車中有或沒有任何東西。 – Dave 2013-02-11 20:41:17
嘗試在系統管理 - >配置 - > Web->會話Cookie管理下設置您的Cookie路徑到系統管理員。 – dmanners 2013-02-11 20:57:17
或者試試這行Mage :: getSingleton('core/session',array('name'=>'frontend'));在Mage :: app()調用之後。 – dmanners 2013-02-11 21:30:37