Get Related, Upsell, Cross sell Product collection in Magento.?

Get Realted, Upsell, Cross sell Product collection in magento

In this post we will guide you on how to add related, upsell and cross sell product collection in Magento. Before starting, first lets explain about what are Related, Upsell and Cross-sell Products respectively. These are the up-sale techniques that websites offer to increase their revenues from getting more products in the eyes of the user.

Related Products: It displays on the product page and they are related to the product that customer is viewing with respect to category or type itself.

Upsell Products: It displays on the product page and they are an upgrade to the products the customer may bought, and are generally priced higher with their regular prices.

Cross-sell Products: It mostly display on the shopping cart page and they are the products which customers usually buy along with the products that are in the cart itself.

Get Related Product Collection

Here is the syntax to add related product collection to your viewers page

$relatedProduct = $product->getRelatedProductCollection();
foreach($relatedProduct as $product)
    $model_rel = Mage::getModel('catalog/product'); //getting product model
    $product_rel = $model_rel->load($productid); //getting product 
     object for particular product id
    $rel_name= $_product_rel->getName();
    $rel_price= number_format($product_rel->getPrice(),2);
    $rel_img_url = $this->helper('catalog/image')->
     init($_product_rel, 'image')->keepFrame(false)->resize(100,100);   //Image resize code

Get Upsell Product Collection

With this code you will be able to add upsell product collection to the website programmatically.

$upsellproduct_collection = $_product->getUpSellProductCollection();
foreach($upsellproduct_collection as $prduct)
    $model_upsell = Mage::getModel('catalog/product');
    $product_upsell = $model_upsell->load($productid);
    $upsell_name= $product_upsell->getName();
    $upsell_price= number_format($product_upsell->getPrice(),2);
    $upsell_img_url = $this->helper('catalog/image')
     ->init($_product_upsell, 'image')
       ->keepFrame(false)->resize(150,100);//Image resize code

Get Cross Sell Product Collection

This code allow to add Cross sell product collection to the whole website set up programmatically.

$crossselllproduct_collection = $_product->getCrossSellProducts(); 
foreach($crossselllproduct_collection as $product)
    $model_crosssell = Mage::getModel('catalog/product');
    $product_crosssell = $model_crosssell>load($productid);
    $crosssell_name= $product_crosssell->getName();
    $crosssell_price= number_format($product_crosssell->getPrice(),2);
    $crosssell_img_url = $this->helper('catalog/image')
    ->init($_product_crosssell, 'image')
    ->keepFrame(false)->resize(150,150);//Image resize code

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *