/**
  * 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;
 }
예제 #2
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;
 }
예제 #3
0
 public function testGetProductCollection()
 {
     $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->will($this->returnValue($this->category));
     $this->category->expects($this->any())->method('getId')->will($this->returnValue(333));
     $this->collectionFilter->expects($this->once())->method('filter')->with($this->equalTo($this->collection), $this->equalTo($this->category));
     $this->collectionProvider->expects($this->once())->method('getCollection')->with($this->equalTo($this->category))->will($this->returnValue($this->collection));
     $result = $this->model->getProductCollection();
     $this->assertInstanceOf('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', $result);
     $result = $this->model->getProductCollection();
     $this->assertInstanceOf('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', $result);
 }
예제 #4
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);
 }
예제 #5
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;
 }
예제 #6
0
파일: Plugin.php 프로젝트: aiesh/magento2
 /**
  * @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;
 }
예제 #7
0
 /**
  * Get maximum price from layer products set
  *
  * @return float
  */
 public function getMaxPriceInt()
 {
     $maxPrice = $this->layer->getProductCollection()->getMaxPrice();
     $maxPrice = floor($maxPrice);
     return $maxPrice;
 }
예제 #8
0
 /**
  * Return the current layer product collection.
  *
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 private function getProductCollection()
 {
     return $this->layer->getProductCollection();
 }