views:

45

answers:

2

Hi, i'm tring to put a list of recommended items in checkout cart page, i was trying to use the related products block that is in layaout/catalog.xml, but it works for a single product in product view page, and in the checkout cart page can be more than one product, so, how can i make something like this, if it can be done??

A: 

If you look in the Mage_Catalog_Block_Product_List_Related::_prepareData method, you'll see that it is using the following code plus some house-keeping:

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

You could create your own Block that grabs the products from the cart, and loops through the same code. Something like:

$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
}

you might need to deduplicate the collection (toArray() then array_unique) as it's possible that items in the cart have the same related products, but that should get you in the game at least.

HTH, JD

Jonathan Day
+2  A: 

To achieve what you require simply adding "Cross Sell" product relationships will achieve this.

Read: http://www.magentocommerce.com/knowledge-base/entry/how-do-i-set-up-product-relations/

Flipmedia