我正在嘗試編寫一個在Drupal塊內加載Magento購物車的塊。Magento和Drupal會話衝突 - 如何解決?
下面的代碼(位於/test.php)裝入購物車和它的內容正確(Magento的安裝位於/ Magento的):
<?php
/*
* Initialize magento.
*/
require_once('magento/app/Mage.php');
umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name'=>'frontend'));
Mage::getSingleton('customer/session');
/*
* Add specific layout handles to our layout and then load them.
*/
$layout = Mage::app()->getLayout();
$layout->getUpdate()
->addHandle('default')
->load();
/*
* Generate blocks, but XML from previously loaded layout handles must be
* loaded first.
*/
$layout->generateXml()
->generateBlocks();
/*
* Now we can simply get any block in the usual way.
*/
$cart = $layout->getBlock('cart_sidebar')->toHtml();
echo $cart;
?>
(我使用FirePHP調試會話值 - - 這是在FB();電話是)
如果我使用的是內Drupal的完全相同的代碼(通過hook_menu回調),我收到以下錯誤:
Fatal error: Mage_Core_Model_Session_Abstract::getMessages(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Mage_Core_Model_Message_Collection" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/aendrew/workspace/drupgento/magento/app/code/core/Mage/Core/Model/Session/Abstract.php on line 215
我的猜測是噸。帽子Drupal正在做一些與Magento相沖突的會話處理 - 如果我在腳本開始時未設置$ _SESSION,它將顯示一個空的購物車(不管它是否有實際的物品)。我也嘗試把現有的會話放在一個臨時變量中,然後在最後做一個array_merge(),但這也不起作用。
任何想法我可以做到這一點?謝謝!
嘗試從這裏開始http://www.magentocommerce.com/wiki/doc/webservices-api/api/cart#methods – Zyava
@Zyava我已經經歷了這一點。方法'cart.info'需要整數'quoteId',它是現有購物車的ID。如果我有'quoteId',我可以避免所有這些,但是我不知道如何爲當前用戶獲取它(特別是在Magento會話之外) - 這真的是我在第2點所要求的。 – aendrew
值得添加的是,我在'admin-> system-> configuration-> web中將我的cookie路徑設置爲「/」。 – aendrew