Created
June 1, 2015 21:56
-
-
Save justindocanto/9ce1ece82deb64b1b3d5 to your computer and use it in GitHub Desktop.
Magento - get all the products in a category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get products from within a category | |
function getCatProds($catid) { | |
$baseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); | |
$category = new Mage_Catalog_Model_Category(); | |
$category->load($catid); // this is your category id | |
$collection = $category->getProductCollection(); | |
foreach($collection as $product) { | |
$id[] = $product->getId(); | |
} | |
$html = "<ul'>"; | |
foreach($id as $id){ | |
$product = Mage::getModel('catalog/product')->load($id); /* Load each product by ID*/ | |
$name = trim($product->getName()); | |
$link = Mage::getModel('catalog/product_url')->getUrlPath($product); | |
$subtitle = trim($product->getData('subtitle')); // get attribute text | |
$html .= "<li><a href='".$baseURL.$link."' title='".$name."'><strong>".$name."</strong> (".$subtitle.")</a></li>"; | |
} | |
$html .= "</ul>"; | |
echo $html; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment