Ejemplo n.º 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     /** @var \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory */
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     /** @var \Magento\Framework\Store\StoreManagerInterface $storeManager */
     $this->storeManager = $this->getMockBuilder('\\Magento\\Framework\\Store\\StoreManagerInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     /** @var \Magento\Catalog\Model\Layer $layer */
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState'])->getMock();
     /** @var \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder */
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterAttribute = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Layer\\Filter\\Attribute')->disableOriginalConstructor()->setMethods(['getCount', 'applyFilterToCollection'])->getMock();
     $this->filterAttribute->expects($this->any())->method('applyFilterToCollection')->will($this->returnSelf());
     $this->filterAttributeFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Layer\\Filter\\AttributeFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->filterAttributeFactory->expects($this->once())->method('create')->will($this->returnValue($this->filterAttribute));
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $this->frontend = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend')->disableOriginalConstructor()->setMethods(['getOption', 'getSelectOptions'])->getMock();
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $this->attribute->expects($this->atLeastOnce())->method('getFrontend')->will($this->returnValue($this->frontend));
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     $stripTagsFilter = $this->getMockBuilder('\\Magento\\Framework\\Filter\\StripTags')->disableOriginalConstructor()->setMethods(['filter'])->getMock();
     $stripTagsFilter->expects($this->any())->method('filter')->will($this->returnArgument(0));
     $string = $this->getMockBuilder('\\Magento\\Framework\\Stdlib\\String')->disableOriginalConstructor()->setMethods(['strlen'])->getMock();
     $string->expects($this->any())->method('strlen')->will($this->returnCallback(function ($value) {
         return strlen($value);
     }));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\Attribute', ['filterItemFactory' => $this->filterItemFactory, 'storeManager' => $this->storeManager, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterAttributeFactory' => $this->filterAttributeFactory, 'tagFilter' => $stripTagsFilter, 'string' => $string]);
 }
Ejemplo n.º 2
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParam'])->getMockForAbstractClass();
     $dataProviderFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\PriceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->dataProvider = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Price')->disableOriginalConstructor()->setMethods(['setPriceId', 'getPrice', 'getResource'])->getMock();
     $this->resource = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Layer\\Filter\\Price')->disableOriginalConstructor()->setMethods(['applyPriceRange'])->getMock();
     $this->dataProvider->expects($this->any())->method('getResource')->will($this->returnValue($this->resource));
     $dataProviderFactory->expects($this->once())->method('create')->will($this->returnValue($this->dataProvider));
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState'])->getMock();
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $filterItem = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item')->disableOriginalConstructor()->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])->getMock();
     $filterItem->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $this->filterItemFactory->expects($this->any())->method('create')->will($this->returnValue($filterItem));
     $escaper = $this->getMockBuilder('\\Magento\\Framework\\Escaper')->disableOriginalConstructor()->setMethods(['escapeHtml'])->getMock();
     $escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0));
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $algorithmFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Dynamic\\AlgorithmFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->algorithm = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Dynamic\\Auto')->disableOriginalConstructor()->setMethods(['getItemsData'])->getMock();
     $algorithmFactory->expects($this->any())->method('create')->will($this->returnValue($this->algorithm));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\Price', ['dataProviderFactory' => $dataProviderFactory, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterItemFactory' => $this->filterItemFactory, 'escaper' => $escaper, 'algorithmFactory' => $algorithmFactory]);
 }
Ejemplo n.º 3
0
 /**
  * Set order options
  *
  * @return void
  */
 public function setListOrders()
 {
     /* @var $category \Magento\Catalog\Model\Category */
     $category = $this->_catalogLayer->getCurrentCategory();
     $availableOrders = $category->getAvailableSortByOptions();
     unset($availableOrders['position']);
     $this->getChildBlock('search_result_list')->setAvailableOrders($availableOrders);
 }
Ejemplo n.º 4
0
 /**
  * Apply sort params to the collection.
  *
  * @param \Magento\Catalog\Model\Layer                                       $layer      Catalog / search layer.
  * @param \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection Product collection.
  *
  * @return $this
  */
 private function setSortParams(\Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection)
 {
     $searchQuery = $this->queryFactory->get();
     if (!$searchQuery->getQueryText() && $layer->getCurrentCategory()) {
         $categoryId = $layer->getCurrentCategory()->getId();
         $collection->addSortFilterParameters('position', 'category.position', 'category', ['category.category_id' => $categoryId]);
     }
     return $this;
 }
Ejemplo n.º 5
0
 protected function setUp()
 {
     $this->productCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->disableOriginalConstructor()->setMethods(['getMaxPrice'])->getMock();
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getProductCollection'])->getMock();
     $this->layer->expects($this->any())->method('getProductCollection')->will($this->returnValue($this->productCollection));
     $this->coreRegistry = $this->getMockBuilder('\\Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry'])->getMock();
     $this->scopeConfig = $this->getMockBuilder('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
     $this->resource = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\Price')->disableOriginalConstructor()->setMethods(['getCount'])->getMock();
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Price', ['layer' => $this->layer, 'coreRegistry' => $this->coreRegistry, 'scopeConfig' => $this->scopeConfig, 'resource' => $this->resource]);
 }
Ejemplo n.º 6
0
 /**
  * @param \Magento\Catalog\Model\Layer\AvailabilityFlagInterface $subject
  * @param callable $proceed
  * @param \Magento\Catalog\Model\Layer $layer
  * @param array $filters
  * @return bool
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundIsEnabled(\Magento\Catalog\Model\Layer\AvailabilityFlagInterface $subject, \Closure $proceed, $layer, $filters)
 {
     $_isLNAllowedByEngine = $this->engineProvider->get()->isLayeredNavigationAllowed();
     if (!$_isLNAllowedByEngine) {
         return false;
     }
     $availableResCount = (int) $this->scopeConfig->getValue(self::XML_PATH_DISPLAY_LAYER_COUNT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if (!$availableResCount || $availableResCount > $layer->getProductCollection()->getSize()) {
         return $proceed($layer, $filters);
     }
     return false;
 }
 /**
  * Retrieve list of filterable attributes
  *
  * @return array|\Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getList()
 {
     $setIds = $this->layer->getProductCollection()->getSetIds();
     if (!$setIds) {
         return [];
     }
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->collectionFactory->create();
     $collection->setItemObjectClass('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->setAttributeSetFilter($setIds)->addStoreLabel($this->storeManager->getStore()->getId())->setOrder('position', 'ASC');
     $collection = $this->_prepareAttributeCollection($collection);
     $collection->load();
     return $collection;
 }
Ejemplo n.º 8
0
 /**
  * @param \Magento\Catalog\Model\Category $category
  * @param int $storeId
  * @return $this
  */
 public function getProductCollection(\Magento\Catalog\Model\Category $category, $storeId)
 {
     /** @var $layer \Magento\Catalog\Model\Layer */
     $layer = $this->catalogLayer->setStore($storeId);
     $collection = $category->getResourceCollection();
     $collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->load();
     /** @var $productCollection \Magento\Catalog\Model\ResourceModel\Product\Collection */
     $productCollection = $this->collectionFactory->create();
     $currentCategory = $layer->setCurrentCategory($category);
     $layer->prepareProductCollection($productCollection);
     $productCollection->addCountToCategories($collection);
     $category->getProductCollection()->setStoreId($storeId);
     $products = $currentCategory->getProductCollection()->addAttributeToSort('updated_at', 'desc')->setVisibility($this->visibility->getVisibleInCatalogIds())->setCurPage(1)->setPageSize(50);
     return $products;
 }
Ejemplo n.º 9
0
 public function testGetCategoryWithAppliedId()
 {
     $storeId = 1234;
     $categoryId = 4321;
     $this->store->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->layer->expects($this->any())->method('getCurrentCategory')->will($this->returnValue($this->category));
     $this->category->expects($this->once())->method('setStoreId')->with($this->equalTo($storeId))->will($this->returnSelf());
     $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId))->will($this->returnSelf());
     $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId));
     $this->category->expects($this->any())->method('getPathIds')->will($this->returnValue([20, 10]));
     $this->coreRegistry->expects($this->once())->method('register')->with($this->equalTo('current_category_filter'), $this->equalTo($this->category), $this->equalTo(true))->will($this->returnSelf());
     $this->target->setCategoryId($categoryId);
     $this->assertSame($this->category, $this->target->getCategory());
     $this->assertSame(20, $this->target->getResetValue());
     return $this->target;
 }
Ejemplo n.º 10
0
 /**
  * Get comparing value sql part
  *
  * @param float $price
  * @param bool $decrease
  * @return float
  */
 protected function _getComparingValue($price, $decrease = true)
 {
     $currencyRate = $this->layer->getProductCollection()->getCurrencyRate();
     if ($decrease) {
         return ($price - self::MIN_POSSIBLE_PRICE / 2) / $currencyRate;
     }
     return ($price + self::MIN_POSSIBLE_PRICE / 2) / $currencyRate;
 }
Ejemplo n.º 11
0
 /**
  * @dataProvider currentCategoryProvider
  */
 public function testGetCurrentCategory($currentCategory)
 {
     $rootCategoryId = 333;
     $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->will($this->returnValue($currentCategory));
     $this->category->expects($this->any())->method('load')->with($this->equalTo($rootCategoryId))->will($this->returnValue($this->category));
     $this->store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
     $result = $this->model->getCurrentCategory();
     $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Category', $result);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function prepareProductCollection($collection)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'prepareProductCollection');
     if (!$pluginInfo) {
         return parent::prepareProductCollection($collection);
     } else {
         return $this->___callPlugins('prepareProductCollection', func_get_args(), $pluginInfo);
     }
 }
Ejemplo n.º 13
0
 /**
  * Set search available list orders
  *
  * @return $this
  */
 public function setListOrders()
 {
     $category = $this->catalogLayer->getCurrentCategory();
     /* @var $category \Magento\Catalog\Model\Category */
     $availableOrders = $category->getAvailableSortByOptions();
     unset($availableOrders['position']);
     $this->getListBlock()->setAvailableOrders($availableOrders)->setDefaultDirection('desc')->setSortBy('relevance');
     return $this;
 }
Ejemplo n.º 14
0
 public function testGetCurrentCategoryIfCurrentCategoryIsNotSet()
 {
     $rootCategoryId = 333;
     $this->currentCategory->getData('current_category', null);
     $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->willReturn(null);
     $this->categoryRepository->expects($this->once())->method('get')->with($rootCategoryId)->willReturn($this->category);
     $this->store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
     $this->assertEquals($this->currentCategory, $this->model->getCurrentCategory());
     $this->assertEquals($this->currentCategory, $this->model->getData('current_category'));
 }
Ejemplo n.º 15
0
 /**
  * @dataProvider pricesSegmentationDataProvider
  */
 public function testPricesSegmentation($categoryId, $intervalsNumber, $intervalItems)
 {
     $this->_layer->setCurrentCategory($categoryId);
     $collection = $this->_layer->getProductCollection();
     $memoryUsedBefore = memory_get_usage();
     $this->_model->setPricesModel($this->_filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize());
     if (!is_null($intervalsNumber)) {
         $this->assertEquals($intervalsNumber, $this->_model->getIntervalsNumber());
     }
     $items = $this->_model->calculateSeparators();
     $this->assertEquals(array_keys($intervalItems), array_keys($items));
     for ($i = 0; $i < count($intervalItems); ++$i) {
         $this->assertInternalType('array', $items[$i]);
         $this->assertEquals($intervalItems[$i]['from'], $items[$i]['from']);
         $this->assertEquals($intervalItems[$i]['to'], $items[$i]['to']);
         $this->assertEquals($intervalItems[$i]['count'], $items[$i]['count']);
     }
     // Algorythm should use less than 10M
     $this->assertLessThan(10 * 1024 * 1024, memory_get_usage() - $memoryUsedBefore);
 }
Ejemplo n.º 16
0
 protected function setUp()
 {
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParam'])->getMockForAbstractClass();
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState', 'getProductCollection'])->getMock();
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->filterItem = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item')->disableOriginalConstructor()->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])->getMock();
     $this->filterItem->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $this->filterItemFactory->expects($this->any())->method('create')->will($this->returnValue($this->filterItem));
     $this->fulltextCollection = $this->fulltextCollection = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection')->disableOriginalConstructor()->getMock();
     $this->layer->expects($this->any())->method('getProductCollection')->will($this->returnValue($this->fulltextCollection));
     $filterDecimalFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\DecimalFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resource = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\Decimal')->disableOriginalConstructor()->setMethods([])->getMock();
     $filterDecimalFactory->expects($this->once())->method('create')->will($this->returnValue($resource));
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Layer\\Filter\\Decimal', ['filterItemFactory' => $this->filterItemFactory, 'layer' => $this->layer, 'filterDecimalFactory' => $filterDecimalFactory]);
     $this->target->setAttributeModel($this->attribute);
 }
Ejemplo n.º 17
0
 /**
  * Checks whether category belongs to active category's path
  *
  * @param \Magento\Framework\Data\Tree\Node $category
  * @return bool
  */
 protected function _isActiveMenuCategory($category)
 {
     if (!$this->_catalogLayer) {
         return false;
     }
     $currentCategory = $this->_catalogLayer->getCurrentCategory();
     if (!$currentCategory) {
         return false;
     }
     $categoryPathIds = explode(',', $currentCategory->getPathInStore());
     return in_array($category->getId(), $categoryPathIds);
 }
Ejemplo n.º 18
0
 protected function setUp()
 {
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParam'])->getMockForAbstractClass();
     $dataProviderFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\CategoryFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->dataProvider = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Category')->disableOriginalConstructor()->setMethods(['setCategoryId', 'getCategory'])->getMock();
     $dataProviderFactory->expects($this->once())->method('create')->will($this->returnValue($this->dataProvider));
     $this->category = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getChildrenCategories', 'getIsActive'])->getMock();
     $this->dataProvider->expects($this->any())->method('getCategory', 'isValid')->will($this->returnValue($this->category));
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState', 'getProductCollection'])->getMock();
     $this->fulltextCollection = $this->fulltextCollection = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\Resource\\Fulltext\\Collection')->disableOriginalConstructor()->setMethods(['addCategoryFilter', 'getFacetedData', 'getSize'])->getMock();
     $this->layer->expects($this->any())->method('getProductCollection')->will($this->returnValue($this->fulltextCollection));
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $filterItem = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item')->disableOriginalConstructor()->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])->getMock();
     $filterItem->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $this->filterItemFactory->expects($this->any())->method('create')->will($this->returnValue($filterItem));
     $escaper = $this->getMockBuilder('\\Magento\\Framework\\Escaper')->disableOriginalConstructor()->setMethods(['escapeHtml'])->getMock();
     $escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Layer\\Filter\\Category', ['categoryDataProviderFactory' => $dataProviderFactory, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterItemFactory' => $this->filterItemFactory, 'escaper' => $escaper]);
 }
Ejemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function getItemsData(array $intervals = [], $additionalRequestData = '')
 {
     $collection = $this->layer->getProductCollection();
     $appliedInterval = $intervals;
     if ($appliedInterval && $collection->getPricesCount() <= $this->getIntervalDivisionLimit()) {
         return [];
     }
     $this->algorithm->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getPricesCount());
     if ($appliedInterval) {
         if ($appliedInterval[0] == $appliedInterval[1] || $appliedInterval[1] === '0') {
             return [];
         }
         $this->algorithm->setLimits($appliedInterval[0], $appliedInterval[1]);
     }
     $interval = $this->intervalFactory->create();
     $items = [];
     foreach ($this->algorithm->calculateSeparators($interval) as $separator) {
         $items[] = ['label' => $this->render->renderRangeLabel($separator['from'], $separator['to']), 'value' => ($separator['from'] == 0 ? '' : $separator['from']) . '-' . $separator['to'] . $additionalRequestData, 'count' => $separator['count']];
     }
     return $items;
 }
Ejemplo n.º 20
0
 protected function setUp()
 {
     /** @var \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory */
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     /** @var \Magento\Catalog\Model\Layer $layer */
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState', 'getProductCollection'])->getMock();
     $this->fulltextCollection = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection')->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'getFacetedData', 'getSize'])->getMock();
     $this->layer->expects($this->atLeastOnce())->method('getProductCollection')->will($this->returnValue($this->fulltextCollection));
     /** @var \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder */
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterAttributeFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\AttributeFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $this->frontend = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend')->disableOriginalConstructor()->setMethods(['getOption', 'getSelectOptions'])->getMock();
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->setMethods(['getParam'])->getMockForAbstractClass();
     $stripTagsFilter = $this->getMockBuilder('\\Magento\\Framework\\Filter\\StripTags')->disableOriginalConstructor()->setMethods(['filter'])->getMock();
     $stripTagsFilter->expects($this->any())->method('filter')->will($this->returnArgument(0));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Layer\\Filter\\Attribute', ['filterItemFactory' => $this->filterItemFactory, 'storeManager' => $this->storeManager, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterAttributeFactory' => $this->filterAttributeFactory, 'tagFilter' => $stripTagsFilter]);
 }
Ejemplo n.º 21
0
 /**
  * Check if category display mode is "Static Block Only"
  * For anchor category with applied filter Static Block Only mode not allowed
  *
  * @return bool
  */
 public function isContentMode()
 {
     $category = $this->getCurrentCategory();
     $res = false;
     if ($category->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PAGE) {
         $res = true;
         if ($category->getIsAnchor()) {
             $state = $this->_catalogLayer->getState();
             if ($state && $state->getFilters()) {
                 $res = false;
             }
         }
     }
     return $res;
 }
Ejemplo n.º 22
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     $categoryId = $this->getRequest()->getParam('cid');
     $storeId = $this->_getStoreId();
     /** @var $rssModel \Magento\Rss\Model\Rss */
     $rssModel = $this->_rssFactory->create();
     if ($categoryId) {
         $category = $this->_categoryFactory->create();
         $category->load($categoryId);
         if ($category && $category->getId()) {
             /** @var $layer \Magento\Catalog\Model\Layer */
             $layer = $this->_catalogLayer->setStore($storeId);
             //want to load all products no matter anchor or not
             $category->setIsAnchor(true);
             $newUrl = $category->getUrl();
             $title = $category->getName();
             $rssModel->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
             $_collection = $category->getCollection();
             $_collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->load();
             /** @var $productCollection \Magento\Catalog\Model\Resource\Product\Collection */
             $productCollection = $this->_collectionFactory->create();
             $currentCategory = $layer->setCurrentCategory($category);
             $layer->prepareProductCollection($productCollection);
             $productCollection->addCountToCategories($_collection);
             $category->getProductCollection()->setStoreId($storeId);
             /*
             only load latest 50 products
             */
             $_productCollection = $currentCategory->getProductCollection()->addAttributeToSort('updated_at', 'desc')->setVisibility($this->_visibility->getVisibleInCatalogIds())->setCurPage(1)->setPageSize(50);
             if ($_productCollection->getSize() > 0) {
                 $args = array('rssObj' => $rssModel);
                 foreach ($_productCollection as $_product) {
                     $args['product'] = $_product;
                     $this->addNewItemXmlCallback($args);
                 }
             }
         }
     }
     return $rssModel->createRssXml();
 }
Ejemplo n.º 23
0
 /**
  * Enter description here...
  *
  * @return Category
  */
 public function getCurrentCategory()
 {
     return $this->_catalogLayer->getCurrentCategory();
 }
Ejemplo n.º 24
0
 /**
  * @param ContextInterface $context
  * @param StateFactory $layerStateFactory
  * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory
  * @param \Magento\Catalog\Model\ResourceModel\Product $catalogProduct
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Registry $registry
  * @param CategoryRepositoryInterface $categoryRepository
  * @param array $data
  */
 public function __construct(ContextInterface $context, StateFactory $layerStateFactory, \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product $catalogProduct, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Registry $registry, CategoryRepositoryInterface $categoryRepository, array $data = [])
 {
     parent::__construct($context, $layerStateFactory, $attributeCollectionFactory, $catalogProduct, $storeManager, $registry, $categoryRepository, $data);
 }
Ejemplo n.º 25
0
 /**
  * Is filter enabled
  *
  * @param \Magento\Catalog\Model\Layer $layer
  * @param array $filters
  * @return bool
  */
 public function isEnabled($layer, array $filters = [])
 {
     return $this->canShowOptions($filters) || count($layer->getState()->getFilters());
 }
Ejemplo n.º 26
0
 /**
  * Get maximum price from layer products set
  *
  * @return float
  */
 public function getMaxPriceInt()
 {
     $maxPrice = $this->layer->getProductCollection()->getMaxPrice();
     $maxPrice = floor($maxPrice);
     return $maxPrice;
 }
Ejemplo n.º 27
0
 /**
  * @param Category\Context $context
  * @param StateFactory $layerStateFactory
  * @param CategoryFactory $categoryFactory
  * @param Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory
  * @param Resource\Product $catalogProduct
  * @param \Magento\Framework\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Registry $registry
  * @param array $data
  */
 public function __construct(Category\Context $context, StateFactory $layerStateFactory, CategoryFactory $categoryFactory, Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory, Resource\Product $catalogProduct, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Framework\Registry $registry, array $data = array())
 {
     parent::__construct($context, $layerStateFactory, $categoryFactory, $attributeCollectionFactory, $catalogProduct, $storeManager, $registry, $data);
 }
Ejemplo n.º 28
0
 /**
  * Return the current layer product collection.
  *
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 private function getProductCollection()
 {
     return $this->layer->getProductCollection();
 }