.

.

Get Product List by category id in magento


Create folder webservice under magento project
& create file getprodlistbycatid.php
Get All Sale Products List By Category ID in Magento LIKE for sarree catid= 55


<?php
require_once '../app/Mage.php';
Mage::app();
header("Content-Type: application/json");
?>

<?php
$categoryid=$_REQUEST['catid'];
if($categoryid!='')
{

//getting webstoreId
  $storeId    = Mage::app()->getStore()->getId();
 
$category = Mage::getModel('catalog/category')->load($categoryid);
//print_r($category);

$collection = $category->getProductCollection()->addAttributeToSort('name', 'asc');
 
   //print_r($collection);
   $i=0;
   foreach($collection as $pc)
   {
   ?>
    
    <?php
    //get product id
     $prodid = $pc->getId();
  
    // get producturl
     $producturl= $pc->getProductUrl();
  
    // get productname
     $productname = $pc->getName();
  
  
// get product category model
$product2 = Mage::getModel('catalog/product')->load($pc->getId());

// get original images of product    section
$productMediaConfig = Mage::getModel('catalog/product_media_config');
 $baseImageUrl = $productMediaConfig->getMediaUrl($product2->getImage());
 $smallImageUrl = $productMediaConfig->getMediaUrl($product2->getSmallImage());

  $thumbnailUrl = $productMediaConfig->getMediaUrl($product2->getThumbnail());
    ?>


<?php


// get current currency
 $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();

//get Product's Regular Price
 $regularprice= $product2->getPrice();



//get Product's Special price

 $specialprice= $product2->getSpecialPrice();



// get short Description

 $shortdescription= $product2->getShortDescription();

?>

      <?php
     $productlist[$i]=array("productId"=>$prodid,"productUrl"=>$producturl,"productName"=>$productname,"thumbnailUrl"=>$thumbnailUrl,"currencyCode"=>$currency_code,"regularPrice"=>$regularprice,"specialPrice"=>$specialprice);
     $i++;
     }
    
     $data['responseCode']="1";
    $data['msg']="successful";
    $data['result']=$productlist;
  
  
    }
    else
    {
    $data['responseCode']="0";
    $data['msg']="failed";
  
  
    }
    
$data2 = json_encode($data);
echo $data2;
 
?>


EmoticonEmoticon