Posted on

How to get the productCount to display using Sebwite sidebar?

I’m trying to display the product Count next to each category and child category. I’m using $category->getProductCount() but nothing is showing up.

Here is my sidebar.phtml

<?php
/**
* Category sidebar
*
* @var $block SebwiteSidebarBlockSidebar
*/
$isEnabled = $block->isEnabled();
$titleText = $block->getTitleText();
$isOpenOnLoad = $block->isOpenOnLoad();
$categories = $block->getCategories();

if ($isEnabled && count($categories)>0) {
?>

<h3><?= $titleText; ?></h3>
<ul class=”o-list”>

<?php
// Loop through categories
foreach ( $categories as $category ) :
?>
<li class=”level0<?php echo($block->isActive($category) ? ‘ active’ : ”); ?>”>
<a href=”<?php echo $block->getCategoryUrl($category); ?>” title=”<?php echo $category->getName(); ?>” class=”<?php echo($block->isActive($category) ? ‘ active’ : ”); ?>”>
<?php echo $category->getName(); ?>
<?php
echo $category->getProductCount();?>
</a>
<?php if ( $category->hasChildren() ) : ?>
<span class=”expand”><?php echo $block->isActive($category) ? ‘<i class=”fa fa-minus”></i>’ : ‘<i class=”fa fa-plus”></i>’; ?></span>
<?php endif; ?>

<?php echo $block->getChildCategoryView($category); ?>
</li>
<?php endforeach; ?>
</ul>
<?php if ($isOpenOnLoad) { ?>
<script>
require([‘jquery’, ‘sidebarmodule’], function($) {
$(‘.is-active’).parents(‘ul’).css(‘display’,’block’);
$(‘.is-active’).parents(‘li’).addClass(‘active’);
$(‘.is-active’).parents(‘li’).find(‘> span i’).removeClass(‘fa-plus’).addClass(‘fa-minus’);
});
</script>
<?php } else { ?>
<script>
require([‘jquery’, ‘sidebarmodule’], function($) {});
</script>
<?php }
} ?>

Leave a Reply

Your email address will not be published.