Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Product Count Per Category in Magento


<ul>              
  <?php $id = 42;?>
  <?php $cat = Mage::getModel('catalog/category')->load($id);?>
  <?php $subcats = $cat->getChildren();?>
  <?php foreach(explode(',',$subcats) as $subCatid):?>
  <?php $_category = Mage::getModel('catalog/category')->load($subCatid);?>
  <?php if($_category->getIsActive()):?>  
  <?php $productCount = Mage::getModel('catalog/category')->load($_category->getId())->getProductCount();?>

 <li><a href="<?php echo $_category->getURL();?>"><span><?php echo $_category->getName();?><?php echo '('.$productCount.')'?></span></a></li>

<?php endif;?>
<?php endforeach;?>
</ul>

Get Current Category Name on Product Details Page Magento

IF you want to display current category name on Product details page, you can easily do it. Just added following few lines of code in your view.phtml file.

<?php $_helper = $this->helper('catalog/output');?>
<?php $_category_detail = Mage::registry('current_category');?>
<?php echo $_category_detail->getName();?>
<?php echo $_category_detail->getId(); ?>



How to get attribute Value and label by attribute ID without product in Magento

Get attribute Value and label by attribute ID without product in Magento

<?php $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', '136');?>
<?php foreach ( $attribute->getSource()->getAllOptions(true, true) as $option):?>
 <?php $attributeArray[$option['value']] = $option['label'];?>
 <?php echo "<pre>";?>
<?php $option['value'].'==>'.$option['label'];?>
 ?>
<?php endforeach;?>

136 is my Attribute id.




How to get Selected category to the top navigation in Magento

IF you want to show Selected category to the top navigation

Go to
/app/design/frontend/default/YOURTHEMENAME/template/catalog/navigation/top.phtml

The original contents of the top.phtml file should look like below.


<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
    <ul id="nav">
        <?php echo $_menu ?>
    </ul>
</div>
<?php endif ?>

Replace the code above with this code below.


<?php $_menu = ''?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div class="nav-container">
    <ul id="nav">
    <?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php if (in_array($_category->getId(), array(10,12,15))) : ?> <?php echo $this->drawItem($_category) ?>
    <?php endif; ?>
    <?php endforeach ?>
    </ul>
</div>
<?php endif; ?>


10,12,15 is the category id which you want to display in the navigation.  

 

Copyright @ 2017 HKBlog.