2
votes

Environment: Magento Enterprise 1.12, Redhat Linux

I'm trying to develop a stand-alone php page in Magento (Enterprise 1.12) with the minimal code to display shopping cart information. This would be used by an external website that displays basic cart information from the Magento store. I'm trying to avoid a full-blown custom MVC model if possible since I'm just trying to get minimal read-only information.

I want to display:

  • the number of items in the shopping cart (whether or not they have logged in)
  • the product names in the cart if it's not empty
  • whether or not the user is logged in
  • customer name if they have logged in

I've seen many posts about this on the net and have tried all the examples without success.

Here's what I am trying:

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"; }

Any help very much appreciated.

1

1 Answers

0
votes

Updated

I set-up the cookie path via the admin section under System-> Configuration->Web->Session Cookie Management.

I then created a test.php and copied your code into the file with the addition of the line just after the Mage::app():

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