環境: Magento Enterprise 1.12、Redhat Linux
ショッピングカート情報を表示するための最小限のコードを使用して、Magento (Enterprise 1.12) でスタンドアロンの php ページを開発しようとしています。これは、Magento ストアからの基本的なカート情報を表示する外部 Web サイトで使用されます。最小限の読み取り専用情報を取得しようとしているだけなので、可能であれば本格的なカスタム 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"; }
どんな助けでも大歓迎です。