コード例 #1
0
ファイル: Decimal.php プロジェクト: shabbirvividads/magento2
 /**
  * Retrieve clean select with joined index table
  * Joined table has index
  *
  * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return \Magento\Framework\DB\Select
  */
 protected function _getSelect($filter)
 {
     $collection = $filter->getLayer()->getProductCollection();
     // clone select from collection with filters
     $select = clone $collection->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(\Zend_Db_Select::COLUMNS);
     $select->reset(\Zend_Db_Select::ORDER);
     $select->reset(\Zend_Db_Select::LIMIT_COUNT);
     $select->reset(\Zend_Db_Select::LIMIT_OFFSET);
     $attributeId = $filter->getAttributeModel()->getId();
     $storeId = $collection->getStoreId();
     $select->join(['decimal_index' => $this->getMainTable()], 'e.entity_id = decimal_index.entity_id' . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.attribute_id = ?', $attributeId) . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.store_id = ?', $storeId), []);
     return $select;
 }
コード例 #2
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return array
  */
 public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(\Magento\Framework\DB\Select::COLUMNS);
     $select->reset(\Magento\Framework\DB\Select::ORDER);
     $select->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
     $select->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
     $connection = $this->getConnection();
     $attribute = $filter->getAttributeModel();
     $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
     $conditions = ["{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId())];
     $select->join([$tableAlias => $this->getMainTable()], join(' AND ', $conditions), ['value', 'count' => new \Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")])->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
コード例 #3
0
ファイル: Price.php プロジェクト: pradeep-wagento/magento2
 /**
  * Apply price range filter to product collection
  *
  * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
  * @param mixed $interval
  * @return $this
  */
 public function applyPriceRange(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter, $interval)
 {
     if (!$interval) {
         return $this;
     }
     list($from, $to) = $interval;
     if ($from === '' && $to === '') {
         return $this;
     }
     $select = $filter->getLayer()->getProductCollection()->getSelect();
     $priceExpr = $this->_getPriceExpression($select, false);
     if ($to !== '') {
         $to = (double) $to;
         if ($from == $to) {
             $to += self::MIN_POSSIBLE_PRICE;
         }
     }
     if ($from !== '') {
         $select->where($priceExpr . ' >= ' . $this->_getComparingValue($from));
     }
     if ($to !== '') {
         $select->where($priceExpr . ' < ' . $this->_getComparingValue($to));
     }
     return $this;
 }