Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
How to show inventory in category link, ex. shirts (10)? -please :)
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

I have the category links on the left side of the homepage ( and in the top dropdown menu) and would like it to show how many products are in that category, right in the link.
for eample:
shirts (10)

how can I do this? any help is appreciated.
Thx,
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

please, this can’t be that hard, right in the backend if you click on manage categories, it shows this exact listing, shirts (10), I want to show it on the frontpage.
Thx,
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

Thanks for the reply.
I am not sure where to add the edits?
I tried adding the 1st in /public_html/app/code/core/Mage/Catalog/Model/category.php
and the second in /public_html/app/design/frontend/default/f002/template/catalog/navigation/sidebar.phtml,
which seems to be where they should go, but just got php errors for the site, could you help me out some more?
Thx,
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

Parse error: syntax error, unexpected T_STRING in /home/nepadyes/public_html/app/code/core/Mage/Catalog/Model/Category.php on line 130

protected function _construct()
    
{
        
if (Mage::helper('catalog/category_flat')->isEnabled()) {
            $this
->_init('catalog/category_flat');
            
$this->_useFlatResource true;
        
else {
            $this
->_init('catalog/category');
        
}
    }
    
public function getFrontentProductCount()
    
{
$collection 
Mage::getResourceModel('catalog/product_collection')
            ->
addCategoryFilter($this)
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
return 
$collection->count();
}

    
/**
     * Retrieve URL instance
     *
     * @return Mage_Core_Model_Url
     */

and

<?php 
/**
 * Top menu for store
 *
 * @see Mage_Catalog_Block_Navigation
 */
?>
<div class="box base-mini mini-navigation">
    <
div class="head"><h4><?php echo $this->__('NepaDyes Products'?></h4></div>
    <
div class="content">
        <
ul id="nav-sidebox">
        
<?php foreach ($this->getStoreCategories() as $_category): ?>
          <?php 
echo $this->drawItem($_category)  ?><?php echo $_category->getName(). '('.$_category->getFrontentProductCount().')' ?>
        <?php 
endforeach ?>
        
</ul>
    </
div>
</
div>

is what I’ve got so far

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

hmm something is still wrong. now I don’t get any errors, but the page will only load up to the header and logo then nothing smile, never seen that 1 b4 smile
I think we r getting close tho,
thx 4 the help
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

protected function _construct()
    
{
        
if (Mage::helper('catalog/category_flat')->isEnabled()) {
            $this
->_init('catalog/category_flat');
            
$this->_useFlatResource true;
        
else {
            $this
->_init('catalog/category');
        
}
    }
    
public function getFrontentProductCount()
    
{
    $collection 
Mage::getResourceModel('catalog/product_collection')
            ->
addCategoryFilter($this);
    
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
    return 
$collection->count();
    
}

    
/**
     * Retrieve URL instance
     *
     * @return Mage_Core_Model_Url
     */

}
        $html
.= '">'."\n";
        
$html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'('.$_category->getFrontentProductCount().')'.'</span></a>'."\n";

        if (
$hasChildren){
 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

sorry, I just noticed this error, if you hover over the top nav menu

Fatal errorCall to a member function getFrontentProductCount() on a non-object in /home/nepadyes/public_html/app/code/core/Mage/Catalog/Block/Navigation.php on line 242
 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

It’s nepadyes.com, I set the original files back so it is up and running, thanks for trying. I think it was getting close smile
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

AHHH so close! it is showing the () but not populating the inventory counts smile
No errors now tho

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

protected function _construct()
    
{
        
if (Mage::helper('catalog/category_flat')->isEnabled()) {
            $this
->_init('catalog/category_flat');
            
$this->_useFlatResource true;
        
else {
            $this
->_init('catalog/category');
        
}
    }
    
public function getFrontentProductCount()
    
{
    $collection 
Mage::getResourceModel('catalog/product_collection')
            ->
addCategoryFilter($this);
    
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
    return 
$collection->count();
    
}

    
/**
     * Retrieve URL instance
     *
     * @return Mage_Core_Model_Url
     */

}
        $html
.= '">'."\n";
        
$html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'('.$category->getFrontentProductCount().')'.'</span></a>'."\n"

        if (
$hasChildren)

Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

all the code looks good to me, I am not great at code, but I can usually spot the bugs, would the calls still be the same in the 1.4 alpha version? or would that not matter?
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

Thanks so much for trying, I really appreciate it, it is 5 in the morning here, I will try to figure this out in the morning, at least I have a good start now, if you come up with anything let me know,
Thanks again, getting answers in this forum is not always easy, let alone someone that sticks in and works it out post by post. I really appreciate it.
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

$loadedCategory Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($category->getEntityId()); 
        
$html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).' ('.$loadedCategory ->getFrontentProductCount() ' )'.'</span></a>'."\n";

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/nepadyes/public_html/app/code/core/Mage/Catalog/Block/Navigation.php on line 222

Do I have the link right?

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

THAT"S IT!!!
I was missing a period.

Thank You So Much!!
You are awesome smile

Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

Hey 1,2,...758 as long as it’s right in the end. smile
Thank you, I owe you a pizza!
I wish I could figure this stuff out, if I knew all the variables I could make my site even better, where did you learn all the variable names that you can call? I wish I was as good as you at coding.
Have a great day!
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
k1nG
Jr. Member
 
Total Posts:  10
Joined:  2009-05-27
 

Hey, seems like there where some more posts in this thread.
What was the code that finally worked?

THX

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2