Suppose you want to show the related products of the products that ordered. In the order success page you will see those related products. lets do this & enjoy :
>> Create a block in checkout.xml
<reference name="right">
<block type="catalog/product_list_relatedsuccess" name="catalog.product.relatedsuccess" before="-" template="catalog/product/list/related.phtml"/>
</reference>
>> Then create the Relatedsuccess.php page copy from Related.php under app/code/core/Mage/Catalog/Block/Product/List
>> Change the class name Mage_Catalog_Block_Product_List_Related to Mage_Catalog_Block_Product_List_Relatedsuccess
>> Then find this method _prepareData() and replace with following...
protected function _prepareData()
{
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getModel('sales/order');
$order->loadByIncrementId($order_id);
$items = $order->getAllItems();
$relIds = array();
foreach($items as $_item){
$relprodColl = Mage::getModel("catalog/product")->load($_item->getProductId())->getRelatedProductCollection();
foreach($relprodColl as $prod){
array_push($relIds, $prod->getId());
}
}
$this->_itemCollection = Mage::getSingleton('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => array_unique($relIds)));
return $this;
}
>> And load the product in the related.phtml page to get all contents.
No comments:
Post a Comment