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; }
/** * Retrieve currently selected category children categories. * * @return \Magento\Catalog\Model\ResourceModel\Category\Collection|\Magento\Catalog\Model\Category[] */ protected function getChildrenCategories() { if ($this->childrenCategories === null) { $currentCategory = $this->dataProvider->getCategory(); $this->childrenCategories = $currentCategory->getChildrenCategories(); } return $this->childrenCategories; }
public function testApply() { $categoryId = 123; $requestVar = 'test_request_var'; $this->target->setRequestVar($requestVar); $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnCallback(function ($field) use($requestVar, $categoryId) { $this->assertTrue(in_array($field, [$requestVar, 'id'])); return $categoryId; })); $this->dataProvider->expects($this->once())->method('setCategoryId')->with($categoryId)->will($this->returnSelf()); $this->category->expects($this->once())->method('getId')->will($this->returnValue($categoryId)); $this->fulltextCollection->expects($this->once())->method('addCategoryFilter')->with($this->category)->will($this->returnSelf()); $this->target->apply($this->request); }
/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { $category = $this->dataProvider->getCategory(); $categories = $category->getChildrenCategories(); $this->getLayer()->getProductCollection()->addCountToCategories($categories); if ($category->getIsActive()) { foreach ($categories as $category) { if ($category->getIsActive() && $category->getProductCount()) { $this->itemDataBuilder->addItemData($this->_escaper->escapeHtml($category->getName()), $category->getId(), $category->getProductCount()); } } } return $this->itemDataBuilder->build(); }
/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ $productCollection = $this->getLayer()->getProductCollection(); $optionsFacetedData = $productCollection->getFacetedData('category'); $category = $this->dataProvider->getCategory(); $categories = $category->getChildrenCategories(); $collectionSize = $productCollection->getSize(); if ($category->getIsActive()) { foreach ($categories as $category) { if ($category->getIsActive() && isset($optionsFacetedData[$category->getId()]) && $this->isOptionReducesResults($optionsFacetedData[$category->getId()]['count'], $collectionSize)) { $this->itemDataBuilder->addItemData($this->escaper->escapeHtml($category->getName()), $category->getId(), $optionsFacetedData[$category->getId()]['count']); } } } return $this->itemDataBuilder->build(); }