Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 public function testGetItems()
 {
     $attributeCode = 'attributeCode';
     $attributeValue = 'attributeValue';
     $attributeLabel = 'attributeLabel';
     $this->attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->target->setAttributeModel($this->attribute);
     $this->request->expects($this->once())->method('getParam')->with($attributeCode)->will($this->returnValue($attributeValue));
     $this->frontend->expects($this->once())->method('getOption')->with($attributeValue)->will($this->returnValue($attributeLabel));
     $filterItem = $this->createFilterItem(0, $attributeLabel, $attributeValue, 0);
     $this->state->expects($this->once())->method('addFilter')->with($filterItem)->will($this->returnSelf());
     $expectedFilterItems = [];
     $result = $this->target->apply($this->request)->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }
Ejemplo n.º 3
0
 public function testAddFilter()
 {
     $expect = [$this->item];
     $this->model->addFilter($this->item);
     $this->assertEquals($expect, $this->model->getFilters());
 }
Ejemplo n.º 4
0
 /**
  * Get applied to layer filter items
  *
  * @return Item[]
  */
 public function getFilters()
 {
     try {
         if ($this->bxHelperData->isFilterLayoutEnabled($this->_layer)) {
             $category = $this->_categoryViewBlock->getCurrentCategory();
             if ($category != null && $category->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PAGE) {
                 return parent::getFilters();
             }
             $filters = array();
             $facets = $this->p13nHelper->getFacets();
             if ($facets) {
                 foreach ($this->bxHelperData->getAllFacetFieldNames() as $fieldName) {
                     if ($facets->isSelected($fieldName)) {
                         $filter = $this->objectManager->create("Boxalino\\Intelligence\\Model\\LayerFilterItem");
                         $filter->setFacets($facets);
                         $filter->setFieldName($fieldName);
                         $filters[] = $filter;
                     }
                 }
             }
             return $filters;
         }
         return parent::getFilters();
     } catch (\Exception $e) {
         $this->bxHelperData->setFallback(true);
         $this->_logger->critical($e);
         return parent::getFilters();
     }
 }