Get Related Product Collection – php

This post will give all detail about Realted, Upsell, Cross sell Product. By adding product id we can abel to get data of Realted, Upsell, Cross sell Product.

Get Related Product Collection


$product_id = "17"; // add youtr poduct id

$product_obj = Mage::getModel('catalog/product');

// Enter your Product Id in $product_id
$_products = $product_obj->load($product_id);

$get_related_product = $_products->getRelatedProductCollection();
$get_related_product->AddStoreFilter();
// check for count record for related product collection
$count = count($get_related_product);
if(empty($count)) {
// if not empty found
echo "No Record found of related product collection";
}
else
{
foreach($get_related_product as $prodcut_val)
{
$prodcut_val_id = $prodcut_val->getId();
// getting product model
$model_rel = Mage::getModel('catalog/product');
// getting product object for particular product id
$related_products   = $model_rel->load($prodcut_val_id);
/*
// get all detail of related product
echo "<pre>";
print_r($related_products);
echo "</pre>";
*/

$prodcut_name = $related_products->getName();
$rel_price = number_format($related_products->getPrice(),2);
// resize image with resize function
$rel_img_url = $this->helper('catalog/image')->init($related_products  , 'image')->keepFrame(false)->resize(250,150);

}
}

Get Upsell Product Collection

$product_id = "17"; // add youtr poduct id

$product_obj = Mage::getModel('catalog/product');

// Enter your Product Id in $product_id
$_products = $product_obj->load($product_id);

$get_upsell_product = $_products->getUpSellProductCollection();
$get_upsell_product->AddStoreFilter();
// check for count record for upsell product collection
$count = count($get_upsell_product);
if(empty($count)) {
// if not empty found
echo "No Record found of upsell product collection";
}
else
{
foreach($get_upsell_product as $prodcut_val)
{
$prodcut_val_id = $prodcut_val->getId();
$model_upsell = Mage::getModel('catalog/product');
$upsell_products = $model_upsell->load($prodcut_val_id);
/*
// get all detail of upsell product
echo "<pre>";
print_r($upsell_products);
echo "</pre>";
*/
$upsell_name= $upsell_products->getName();
$upsell_price = number_format($upsell_products->getPrice(),2);
$upsell_img_url = $this->helper('catalog/image')->init($upsell_products, 'image')->keepFrame(false)->resize(250,150);
}
}

Get Cross Sell Product Collection

$product_id = "17"; // add youtr poduct id

$product_obj = Mage::getModel('catalog/product');

// Enter your Product Id in $product_id
$_products = $product_obj->load($product_id);

// Enter your Product Id in $product_id
$_products = $product_obj->load($product_id);

$get_crossselll_product = $_products->getCrossSellProducts();
$get_crossselll_product->AddStoreFilter();
// check for count record for crossselll product collection
$count = count($get_crossselll_product);
if(empty($count)) {
// if not empty found
echo "No Record found of crossselll product collection";
}
else
{
foreach($get_crossselll_product as $prodcut_val)
{
$prodcut_val_id = $prodcut_val->getId();
$model_crosssell = Mage::getModel('catalog/product');
$crosssell_products = $model_crosssell>load($prodcut_val_id);
/*
// get all detail of crossselll product
echo "<pre>";
print_r($crosssell_products);
echo "</pre>";
*/

$crosssell_name = $crosssell_products->getName();
$crosssell_price = number_format($crosssell_products->getPrice(),2);
$crosssell_img_url = $this->helper('catalog/image')->init($crosssell_products, 'image')->keepFrame(false)->resize(250,150);
}
}

Leave a Comment

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

19  +    =  26

We accept paid advance and paid guest Posting on our Site : Contact US