Friday, 5 February 2016

Get all prodcuts by category ID

// Let's load the category Model and grab the product collection of that category

$product_collection = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();

// Now let's loop through the product collection and print the ID of every product in the collection

foreach($product_collection as $product) {

  $product_id = $product->getId();

  // Load the full product model based on the product ID

  $full_product = Mage::getModel('catalog/product')->load($product_id);


  // Let's get the Product Name
  $product_name = $full_product->getName();

  // Let's get the Product URL path
  $product_url = $full_product->getProductUrl();

  // Let's get the Product Image URL
  $product_image_url = $full_product->getImageUrl();

  // Let's print the product information we gathered and continue onto the next one
  echo'<a href="'.$product_url.'">'.$product_name.'</a>';
  echo '<img src="'.$product_image_url.'"/>';

No comments:

Post a Comment