示例#1
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);
 }
示例#2
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;
 }
示例#3
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);
 }
示例#4
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;
 }
示例#5
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'));
 }
示例#6
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);
 }
 /**
  * Enter description here...
  *
  * @return Category
  */
 public function getCurrentCategory()
 {
     return $this->_catalogLayer->getCurrentCategory();
 }