/** * @param FilterItem $subject * @param \Closure $proceed * @return string * @throws \Magento\Framework\Exception\LocalizedException * * @see \Magento\Catalog\Model\Layer\Filter\Item::getUrl() */ public function aroundGetUrl(FilterItem $subject, \Closure $proceed) { $this->filter = $subject->getFilter(); $this->eavAttribute = $this->filter->getAttributeModel(); if ($this->canBeSubstituted()) { $result = $this->urlHelper->getOptionUrl($this->eavAttribute, $subject->getValue()); } else { $result = $proceed(); } return $result; }
/** * {@inheritDoc} */ protected function getOptionViewData(FilterItem $filterItem, Option $swatchOption) { $customStyle = ''; $linkToOption = $filterItem->getUrl(); if ($this->isOptionDisabled($filterItem)) { $customStyle = 'disabled'; $linkToOption = 'javascript:void();'; } if ($filterItem->getIsSelected()) { $customStyle = 'selected'; } return ['label' => $swatchOption->getLabel(), 'link' => $linkToOption, 'custom_style' => $customStyle]; }
/** * LayerFilterItem constructor. * @param \Magento\Framework\UrlInterface $url * @param \Magento\Theme\Block\Html\Pager $htmlPagerBlock * @param \Boxalino\Intelligence\Helper\Data $bxDataHelper * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param \Magento\Framework\App\Request\Http $request * @param array $data */ public function __construct(\Magento\Framework\UrlInterface $url, \Magento\Theme\Block\Html\Pager $htmlPagerBlock, \Boxalino\Intelligence\Helper\Data $bxDataHelper, \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\App\Request\Http $request, array $data = []) { $this->_request = $request; $this->objectManager = $objectManager; $this->bxDataHelper = $bxDataHelper; parent::__construct($url, $htmlPagerBlock, $data); }
/** * Append url and is_selected computed fields to the result array. * * {@inheritDoc} */ public function toArray(array $keys = []) { $data = parent::toArray($keys); if (in_array('url', $keys) || empty($keys)) { $data['url'] = $this->getUrl(); } if (in_array('is_selected', $keys) || empty($keys)) { $data['is_selected'] = (bool) $this->getIsSelected(); } return $data; }
public function testApply() { $stateKey = 'sk'; $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->will($this->returnValue($this->category)); $this->stateKeyGenerator->expects($this->once())->method('toString')->with($this->equalTo($this->category))->will($this->returnValue($stateKey)); $this->state->expects($this->any())->method('getFilters')->will($this->returnValue([$this->filter])); $this->filter->expects($this->once())->method('getFilter')->will($this->returnValue($this->abstractFilter)); $this->filter->expects($this->once())->method('getValueString')->will($this->returnValue('t')); $this->abstractFilter->expects($this->once())->method('getRequestVar')->will($this->returnValue('t')); $result = $this->model->apply(); $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Layer', $result); }
public function getRemoveUrl() { if ($this->helper->isActiveEngine()) { if (!$this->hasSelectedValues() || empty($this->getSelectedValues())) { return parent::getRemoveUrl(); } /** @var array $values */ $values = $this->getSelectedValues(); $values = array_diff($values, [$this->getValue()]); if (empty($values)) { return parent::getRemoveUrl(); } $query = [$this->getFilter()->getRequestVar() => implode(',', $values), $this->_htmlPagerBlock->getPageVarName() => null]; return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]); } return parent::getRemoveUrl(); }
/** * @param FilterItem $filterItem * @return bool */ protected function isOptionDisabled(FilterItem $filterItem) { return !$filterItem->getCount(); }
public function testGetValueString() { $this->assertEquals('valuePart1,valuePart2', $this->_model->getValueString()); }