public function testGetAvailableSortByOptions()
 {
     $options = $this->_model->getAvailableSortByOptions();
     $this->assertContains('price', array_keys($options));
     $this->assertContains('position', array_keys($options));
     $this->assertContains('name', array_keys($options));
 }
Example #2
0
 /**
  * Prepare Sort By fields from Category Data
  *
  * @param \Magento\Catalog\Model\Category $category
  * @return \Magento\Catalog\Block\Product\ListProduct
  */
 public function prepareSortableFieldsByCategory($category)
 {
     if (!$this->getAvailableOrders()) {
         $this->setAvailableOrders($category->getAvailableSortByOptions());
     }
     $availableOrders = $this->getAvailableOrders();
     if (!$this->getSortBy()) {
         $categorySortBy = $category->getDefaultSortBy();
         if ($categorySortBy) {
             if (!$availableOrders) {
                 $availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray();
             }
             if (isset($availableOrders[$categorySortBy])) {
                 $this->setSortBy($categorySortBy);
             }
         }
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function getAvailableSortByOptions()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAvailableSortByOptions');
     if (!$pluginInfo) {
         return parent::getAvailableSortByOptions();
     } else {
         return $this->___callPlugins('getAvailableSortByOptions', func_get_args(), $pluginInfo);
     }
 }