Skip to content

Commit

Permalink
Merge pull request #713 from afoucret/feature-facet-display-product-c…
Browse files Browse the repository at this point in the history
…ount

Fix #711 : Do not show product count if disabled in config.
  • Loading branch information
afoucret authored Jan 29, 2018
2 parents 3e0402b + 0612451 commit 430db42
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\LayeredNavigation\Block\Navigation\FilterRendererInterface;
use Magento\Catalog\Model\Layer\Filter\FilterInterface;
use Magento\Framework\View\Element\Template;
use \Magento\Catalog\Helper\Data as CatalogHelper;

/**
* Abstract facet renderer block.
Expand All @@ -31,6 +32,25 @@ abstract class AbstractRenderer extends Template implements FilterRendererInterf
*/
private $filter;

/**
* @var CatalogHelper
*/
private $catalogHelper;

/**
* Constructor.
*
* @param Template\Context $context Block context.
* @param CatalogHelper $catalogHelper Catalog helper.
* @param array $data Additionnal block data.
*/
public function __construct(Template\Context $context, CatalogHelper $catalogHelper, array $data = [])
{
parent::__construct($context, $data);
$this->catalogHelper = $catalogHelper;
}


/**
* {@inheritDoc}
*/
Expand All @@ -56,6 +76,16 @@ public function getFilter()
return $this->filter;
}

/**
* Indicates if the product count should be displayed or not.
*
* @return boolean
*/
public function displayProductCount()
{
return $this->catalogHelper->shouldDisplayProductCountOnLayer();
}

/**
* Check if the current block can render a filter (previously set through ::setFilter).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public function getJsLayout()
$filterItems = $this->getFilter()->getItems();

$jsLayoutConfig = [
'component' => self::JS_COMPONENT,
'maxSize' => (int) $this->getFilter()->getAttributeModel()->getFacetMaxSize(),
'hasMoreItems' => (bool) $this->getFilter()->hasMoreItems(),
'ajaxLoadUrl' => $this->getAjaxLoadUrl(),
'component' => self::JS_COMPONENT,
'maxSize' => (int) $this->getFilter()->getAttributeModel()->getFacetMaxSize(),
'displayProductCount' => (bool) $this->displayProductCount(),
'hasMoreItems' => (bool) $this->getFilter()->hasMoreItems(),
'ajaxLoadUrl' => $this->getAjaxLoadUrl(),
];

foreach ($filterItems as $item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Locale\FormatInterface;
use Magento\Framework\Json\EncoderInterface;
use \Magento\Catalog\Helper\Data as CatalogHelper;

/**
* This block handle standard decimal slider rendering.
Expand Down Expand Up @@ -49,18 +50,20 @@ class Slider extends AbstractRenderer

/**
*
* @param Context $context Template context.
* @param EncoderInterface $jsonEncoder JSON Encoder.
* @param FormatInterface $localeFormat Price format config.
* @param array $data Custom data.
* @param Context $context Template context.
* @param CatalogHelper $catalogHelper Catalog helper.
* @param EncoderInterface $jsonEncoder JSON Encoder.
* @param FormatInterface $localeFormat Price format config.
* @param array $data Custom data.
*/
public function __construct(
Context $context,
CatalogHelper $catalogHelper,
EncoderInterface $jsonEncoder,
FormatInterface $localeFormat,
array $data = []
) {
parent::__construct($context, $data);
parent::__construct($context, $catalogHelper, $data);

$this->jsonEncoder = $jsonEncoder;
$this->localeFormat = $localeFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ define([
this.initSearchPlaceholder();
this.onShowLess();
this.displaySearch = this.displayShowMore();

},

/**
Expand Down Expand Up @@ -211,6 +212,7 @@ define([
*/
addItemId: function (item) {
item.id = _.uniqueId(this.index + "_option_");
item.displayProductCount = this.displayProductCount && (item.count >= 1)
return item;
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
onclick="this.parentNode.click();" />
<label data-bind="attr: {for: id}">
<span data-bind="html: label"></span>
<span class="count" data-bind="text: count"></span>
<span class="count" data-bind="text: count, visible: $parent.displayProductCount"></span>
</label>
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Framework\View\Element\Template\Context;
use Magento\Swatches\Helper\Data as SwatchHelper;
use Smile\ElasticsuiteCatalog\Block\Navigation\Renderer\AbstractRenderer;
use \Magento\Catalog\Helper\Data as CatalogHelper;

/**
* This block handle swatches slider rendering.
Expand All @@ -39,13 +40,14 @@ class Swatches extends AbstractRenderer
/**
* Constructor.
*
* @param Context $context Template context.
* @param SwatchHelper $swatchHelper Swatch helper.
* @param array $data Custom data.
* @param Context $context Template context.
* @param CatalogHelper $catalogHelper Catalog helper.
* @param SwatchHelper $swatchHelper Swatch helper.
* @param array $data Custom data.
*/
public function __construct(Context $context, SwatchHelper $swatchHelper, array $data = [])
public function __construct(Context $context, CatalogHelper $catalogHelper, SwatchHelper $swatchHelper, array $data = [])
{
parent::__construct($context, $data);
parent::__construct($context, $catalogHelper, $data);
$this->swatchHelper = $swatchHelper;
}

Expand Down

0 comments on commit 430db42

Please sign in to comment.