Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this questioni'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 开发者_StackOverflow社区something like this, if it can be done??
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/
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
精彩评论