Some Time we need to to get the the collection of products have related products:

You can do the job by following steps

1- Create a new blank file in magento root directory named: get-product-detail.php

2- Copy and paste the following code in that file:

<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
$j=0;
$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product){
 $_product =Mage::getModel('catalog/product')->load($product->getId());
 $up_products = $_product->getRelatedProductCollection();
 if(count($up_products)){
 echo "<br><b>".$_product->getId()."->".$_product->getSku()."=>";
 echo count($up_products)."</b>";
 $j++;
 }else{
  echo "<br>".$_product->getId()."->".$_product->getSku()."=>";
 echo count($up_products);
 }
}
echo "<hr>Total: ".$j.'<br/>';
?>
------------------------------------ Up Sell Producrs --------------------------
<?php
$k=0;
$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product){
 $_product =Mage::getModel('catalog/product')->load($product->getId());
 $up_products = $_product->getUpSellProductCollection();
 if(count($up_products)){
 echo "<br><b>".$_product->getId()."->".$_product->getSku()."=>";
 echo count($up_products)."</b>";
 $k++;
 }else{
  echo "<br>".$_product->getId()."->".$_product->getSku()."=>";
 echo count($up_products);
 }
}
echo "<hr>Total: ".$k.'<br/>';
?>

3-run the file in your browser

Categories: Magento

0 Comments

Leave a Reply

Avatar placeholder

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