<?php $cats = Mage::getModel('catalog/category')->load(2)->getChildrenCategories(); ?>
<ul>
<?php foreach($cats as $category): ?>
<?php $category_id = $category->getId() ?>
<?php $count = Mage::getModel('catalog/category')->load($category_id)->getProductCount(); ?>
<?php if($count > 0): ?>
<li><a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?> </a>
<?php $category_id = $category->getId() ?>
(<?php echo $count = Mage::getModel('catalog/category')->load($category_id)->getProductCount(); ?>)
<?php $catagory_model = Mage::getModel('catalog/category')->load($category_id); //where $category_id is the id of the category ?>
<?php
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($catagory_model); //category filter
$collection->addAttributeToFilter('status',1); //only enabled product
$collection->addAttributeToSelect(array('name','url','small_image','price','special_price','description','short_description')); //add product attribute to be fetched
//$collection->getSelect()->order('rand()'); //uncomment to get products in random order
$collection->addStoreFilter();
if($count > 0)
{ ?>
<table>
<tr>
<?php
$z=1;
foreach ($collection as $_product): ?>
<td><table>
<tr>
<td><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product_img_link"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a></td>
</tr>
<tr>
<td><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $_product->getName(); ?></a></td>
</tr>
<tr>
<tr>
<td><?php $_pci = $this->htmlEscape($_product->getPrice());
echo number_format($_pci,2); ?>
</td>
</tr>
<td><?php $_splprice = $_product->getSpecialPrice(); //get Product's Special price
if(!$_splprice==''){
echo number_format($_splprice,2); } ?></td>
</tr>
<tr>
<td><?php echo $_product->getShortDescription(); //get product's short description ?></td>
</tr>
<tr>
<td><?php echo $_product->getDescription(); //get Product's Long Description ?></td>
</tr>
</tr>
</table>
<?php /*?><?php echo $_product->getId(); ?><?php */?>
<?php //echo Mage::getBaseUrl(); ?>
<?php if($_product->isSaleable()): ?>
<?php /*?><p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p><?php */?>
<p>
<button onclick="setLocation('<?php echo Mage::getBaseUrl(); ?>checkout/cart/add?product=<?php echo $_product->getId(); ?>&qty;=1')" class="button btn-cart"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
</p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</td>
<?php if($z%3==0){?>
</tr>
<tr>
<?php } $z++; ?>
<?php endforeach; ?>
</tr>
</table>
<?php } else { ?>
<table>
<tr>
<td><?php echo 'No products Assigned in this Category'; ?> </td>
</tr>
</table>
<?php } ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach($cats as $category): ?>
<?php $category_id = $category->getId() ?>
<?php $count = Mage::getModel('catalog/category')->load($category_id)->getProductCount(); ?>
<?php if($count > 0): ?>
<li><a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?> </a>
<?php $category_id = $category->getId() ?>
(<?php echo $count = Mage::getModel('catalog/category')->load($category_id)->getProductCount(); ?>)
<?php $catagory_model = Mage::getModel('catalog/category')->load($category_id); //where $category_id is the id of the category ?>
<?php
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($catagory_model); //category filter
$collection->addAttributeToFilter('status',1); //only enabled product
$collection->addAttributeToSelect(array('name','url','small_image','price','special_price','description','short_description')); //add product attribute to be fetched
//$collection->getSelect()->order('rand()'); //uncomment to get products in random order
$collection->addStoreFilter();
if($count > 0)
{ ?>
<table>
<tr>
<?php
$z=1;
foreach ($collection as $_product): ?>
<td><table>
<tr>
<td><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product_img_link"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a></td>
</tr>
<tr>
<td><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $_product->getName(); ?></a></td>
</tr>
<tr>
<tr>
<td><?php $_pci = $this->htmlEscape($_product->getPrice());
echo number_format($_pci,2); ?>
</td>
</tr>
<td><?php $_splprice = $_product->getSpecialPrice(); //get Product's Special price
if(!$_splprice==''){
echo number_format($_splprice,2); } ?></td>
</tr>
<tr>
<td><?php echo $_product->getShortDescription(); //get product's short description ?></td>
</tr>
<tr>
<td><?php echo $_product->getDescription(); //get Product's Long Description ?></td>
</tr>
</tr>
</table>
<?php /*?><?php echo $_product->getId(); ?><?php */?>
<?php //echo Mage::getBaseUrl(); ?>
<?php if($_product->isSaleable()): ?>
<?php /*?><p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p><?php */?>
<p>
<button onclick="setLocation('<?php echo Mage::getBaseUrl(); ?>checkout/cart/add?product=<?php echo $_product->getId(); ?>&qty;=1')" class="button btn-cart"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
</p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</td>
<?php if($z%3==0){?>
</tr>
<tr>
<?php } $z++; ?>
<?php endforeach; ?>
</tr>
</table>
<?php } else { ?>
<table>
<tr>
<td><?php echo 'No products Assigned in this Category'; ?> </td>
</tr>
</table>
<?php } ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
No comments:
Post a Comment