2014-11-08 54 views
0

訪問會話我使用Mangeto 1.9.1的Magento - Magento的外

我想外面的Magento訪問Magento的客戶會議的PHP文件在Magento的根文件夾中。

這裏是我的代碼:

<?php 
error_reporting(E_ALL | E_STRICT); 
$mageFilename = 'app/Mage.php'; 
require_once $mageFilename; 
$app = Mage::app('default'); 
Mage::app(); 

$customer_id = Mage::getSingleton('customer/session')->getId(); 


$GrandTotal = Mage::getModel('sales/quote')->loadByCustomer($customer_id)->getGrandTotal(); 
$HalfTotal = $GrandTotal/2; 
echo "Grand: $GrandTotal<br>Half: $HalfTotal"; 
?> 

我的Magento安裝在一個子像beta.mymagento.com

但似乎無法訪問會話。 我該如何解決它?

在此先感謝!

回答

0

你有拿起正確的會話一個問題,因爲在Magento的不同的Cookie,而不是典型的PHP應用程序存儲其會話ID。您需要首先初始化一個核心會話,然後告訴它查看名爲前端的cookie,而不是PHP默認的cookie。您的代碼應如下所示:

... 

Mage::getSingleton('core/session', array('name' => 'frontend')); 
$customer_id = Mage::getSingleton('customer/session')->getId(); 

... 

另外,您很可能只需要一個呼叫Mage::app()

注:如果您有多個商店/在你的Magento網站上安裝,你將不得不調用Mage::app()與相應的標識符,例如Mage::app('<website_code>', 'website');