/** * @param \Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter * @return string */ public function render(\Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter) { $this->assign('filterItems', $filter->getItems()); $html = $this->_toHtml(); $this->assign('filterItems', array()); return $html; }
public function testAroundRenderFalse() { $attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $this->filterMock->expects($this->atLeastOnce())->method('getAttributeModel')->willReturn($attributeMock); $this->filterMock->expects($this->once())->method('hasAttributeModel')->willReturn(true); $this->swatchHelperMock->expects($this->once())->method('isSwatchAttribute')->with($attributeMock)->willReturn(false); $result = $this->plugin->aroundRender($this->filterRendererMock, $this->closureMock, $this->filterMock); $this->assertEquals($result, $this->filterMock); }
/** * Construct * * @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Framework\Escaper $escaper * @param CategoryFactory $categoryDataProviderFactory * @param array $data */ public function __construct(\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Framework\Escaper $escaper, CategoryFactory $categoryDataProviderFactory, array $data = []) { parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); $this->_escaper = $escaper; $this->_requestVar = 'cat'; $this->dataProvider = $categoryDataProviderFactory->create(['layer' => $this->getLayer()]); }
/** * @param ItemFactory $filterItemFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Catalog\Model\Resource\Layer\Filter\AttributeFactory $filterAttributeFactory * @param \Magento\Framework\Stdlib\String $string * @param \Magento\Framework\Filter\StripTags $tagFilter * @param array $data */ public function __construct(\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Catalog\Model\Resource\Layer\Filter\AttributeFactory $filterAttributeFactory, \Magento\Framework\Stdlib\String $string, \Magento\Framework\Filter\StripTags $tagFilter, array $data = []) { $this->_resource = $filterAttributeFactory->create(); $this->string = $string; $this->_requestVar = 'attribute'; $this->tagFilter = $tagFilter; parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); }
/** * Construct * * @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory * @param \Magento\Framework\Escaper $escaper * @param \Magento\Framework\Registry $coreRegistry * @param array $data */ public function __construct(\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Framework\Escaper $escaper, \Magento\Framework\Registry $coreRegistry, array $data = array()) { $this->_categoryFactory = $categoryFactory; $this->_escaper = $escaper; $this->_coreRegistry = $coreRegistry; parent::__construct($filterItemFactory, $storeManager, $layer, $data); $this->_requestVar = 'cat'; }
/** * @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Framework\Search\Dynamic\Algorithm $priceAlgorithm * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory $algorithmFactory * @param \Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct(\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Search\Dynamic\Algorithm $priceAlgorithm, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory $algorithmFactory, \Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory, array $data = []) { $this->_requestVar = 'price'; $this->priceCurrency = $priceCurrency; $this->resource = $resource; $this->customerSession = $customerSession; $this->priceAlgorithm = $priceAlgorithm; parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); $this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]); }
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); }
/** * @return array */ public function getSwatchData() { if (false === $this->eavAttribute instanceof Attribute) { throw new \RuntimeException('Magento_Swatches: RenderLayered: Attribute has not been set.'); } $attributeOptions = []; foreach ($this->eavAttribute->getOptions() as $option) { if ($currentOption = $this->getFilterOption($this->filter->getItems(), $option)) { $attributeOptions[$option->getValue()] = $currentOption; } elseif ($this->isShowEmptyResults()) { $attributeOptions[$option->getValue()] = $this->getUnusedOption($option); } } $attributeOptionIds = array_keys($attributeOptions); $swatches = $this->swatchHelper->getSwatchesByOptionsId($attributeOptionIds); $data = ['attribute_id' => $this->eavAttribute->getId(), 'attribute_code' => $this->eavAttribute->getAttributeCode(), 'attribute_label' => $this->eavAttribute->getStoreLabel(), 'options' => $attributeOptions, 'swatches' => $swatches]; return $data; }
/** * Apply decimal range filter to product collection * * @param \Magento\Framework\App\RequestInterface $request * @return $this */ public function apply(\Magento\Framework\App\RequestInterface $request) { parent::apply($request); /** * Filter must be string: $index, $range */ $filter = $request->getParam($this->getRequestVar()); if (!$filter || is_array($filter)) { return $this; } $filter = explode(',', $filter); if (count($filter) != 2) { return $this; } list($index, $range) = $filter; if ((int) $index && (int) $range) { $this->dataProvider->setRange((int) $range); $this->dataProvider->getResource()->applyFilterToCollection($this, $range, $index); $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderItemLabel($range, $index), $filter)); $this->_items = []; } return $this; }
/** * Apply decimal range filter to product collection * * @param \Zend_Controller_Request_Abstract $request * @return $this */ public function apply(\Zend_Controller_Request_Abstract $request) { parent::apply($request); /** * Filter must be string: $index, $range */ $filter = $request->getParam($this->getRequestVar()); if (!$filter || is_array($filter)) { return $this; } $filter = explode(',', $filter); if (count($filter) != 2) { return $this; } list($index, $range) = $filter; if ((int) $index && (int) $range) { $this->setRange((int) $range); $this->_getResource()->applyFilterToCollection($this, $range, $index); $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderItemLabel($range, $index), $filter)); $this->_items = array(); } return $this; }
/** * @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Framework\Filter\StripTags $tagFilter * @param array $data */ public function __construct(\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Framework\Filter\StripTags $tagFilter, array $data = []) { parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); $this->tagFilter = $tagFilter; }
/** * @param RenderLayered $subject * @param AbstractFilter $filter * @return void * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSetSwatchFilter(RenderLayered $subject, AbstractFilter $filter) { $this->filter = $filter; $this->eavAttribute = $filter->getAttributeModel(); }
/** * Get 'clear price' link text * * @return false|string */ public function getClearLinkText() { if ($this->_scopeConfig->getValue(self::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) == self::RANGE_CALCULATION_IMPROVED && $this->getPriorIntervals()) { return __('Clear Price'); } return parent::getClearLinkText(); }
/** * @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Catalog\Model\Resource\Layer\Filter\DecimalFactory $filterDecimalFactory * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param array $data */ public function __construct(\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Catalog\Model\Resource\Layer\Filter\DecimalFactory $filterDecimalFactory, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, array $data = []) { parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); $this->resource = $filterDecimalFactory->create(); $this->priceCurrency = $priceCurrency; }
/** * Get 'clear price' link text * * @return \Magento\Framework\Phrase|bool */ public function getClearLinkText() { if ($this->dataProvider->getPriorIntervals()) { return __('Clear Price'); } return parent::getClearLinkText(); }
public function __construct(Layer\Filter\ItemFactory $filterItemFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, Layer $layer, Layer\Filter\Item\DataBuilder $itemDataBuilder, \Celebros\ConversionPro\Helper\Data $helper, \Celebros\ConversionPro\Helper\Search $searchHelper, array $data = []) { $this->helper = $helper; $this->searchHelper = $searchHelper; parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); }