2010-10-01 27 views
2

我試圖在推出購物車頁面中放置推薦商品列表,我試圖使用layaout/catalog.xml中的相關產品塊,但它適用於產品視圖頁面中的單個產品,並且在結帳購物車頁面中可以有多個產品,因此,如果能做到這一點,我該如何做出這樣的事情?Magento在結帳購物車中的相關(推薦)產品列表

回答

0

如果您在Mage_Catalog_Block_Product_List_Related::_prepareData方法看,你會發現它是使用下面的代碼再加上一些看家:

$this->_itemCollection = $product->getRelatedProductCollection() 
     ... 

你可以創建自己的塊,抓住了產品從車,並通過相同的代碼循環。喜歡的東西:

$cartHelper = Mage::helper('checkout/cart'); 
$cart = $cartHelper->getCart(); 
$cartItems = $cart->getQuote()->getAllItems(); 
$relatedCollection = new Varien_Data_Collection(); 
foreach ($cartItems as $cartItem) { 
    $tempColl = $cartItem->getRelatedProductCollection(); 
    ... insert housekeeping code from Related block 
    ... add $tempColl to $relatedCollection 
} 

您可能需要刪除重複的集合(toArray()然後array_unique),因爲它有可能是在車中的物品具有相同的相關產品,但至少應該讓你在遊戲中。

HTH, JD

相關問題