2013-12-18 89 views
2

我正在使用Wordpress Plugin MWI - Mage/WP集成來創建一個網站,該網站的核心爲Wordpress,子文件夾中爲Magento。無法訪問Wordpress中的Magento會話

我希望能夠訪問Wordpress頁面中的Magento會話。多虧了MWI插件,我可以訪問「客戶/會話」,但是它似乎與我訪問網站的Magento部分時使用的會話不同。

我知道這是因爲我已經將數據添加到Magento中的會話中,但是當我來到主頁(由Wordpress驅動)時,自定義數據不存在!

這裏是林如何在Magento添加額外的數據:

Mage::getSingleton('customer/session')->setData("foo","bar"); 

然後用得到它:

Mage::getSingleton('customer/session')->getData("foo"); 

這將返回NULL。

任何想法?

回答

2

所以,多了幾分試驗&錯誤後,我能解決這個問題。

本質上,通過切換到核心/會話而不是客戶/會話,然後我可以在Wordpress中訪問同一個會話。因此,設置&越來越成爲:

Mage::getSingleton('core/session')->setData("foo","bar"); 
Mage::getSingleton('core/session')->getData("foo"); 

在WordPress是使用很重要:

Mage::getSingleton('core/session', array('name' => 'frontend'))->getData("foo"); 
0

此外,作爲替代解決方案,我們可以創建簡單的模塊用輔助用於獲取會話變量。下面是返回Magento的會議輔助funtcion:

require_once('path_to/Mage.php'); 
    Mage::app(); 
    var_dump(Mage::helper('namespace_modulename')->getSession()->getData()); 

class Namespace_Modulename_Helper_Data extends Mage_Core_Helper_Abstract 
    { 
     public function getSession() 
     { 
      return return Mage::getSingleton('core/session', array('name' => 'frontend')); 
     } 
    } 

然後,我們可以通過這樣的代碼訪問會話數據