Ejemplo n.º 1
0
 /**
  * Apply price range filter to product collection
  *
  * @param Mage_Catalog_Model_Layer_Filter_Price $filter
  * @return Mage_Catalog_Model_Resource_Layer_Filter_Price
  */
 public function applyPriceRange($filter)
 {
     $interval = $filter->getInterval();
     if (!$interval) {
         return $this;
     }
     list($from, $to) = $interval;
     if ($from === '' && $to === '') {
         return $this;
     }
     $select = $filter->getLayer()->getProductCollection()->getSelect();
     $priceExpr = $this->_getPriceExpression($filter, $select, false);
     if ($to !== '') {
         $to = (double) $to;
         if ($from == $to) {
             $to += self::MIN_POSSIBLE_PRICE;
         }
     }
     if ($from !== '') {
         $select->where($priceExpr . ' >= ' . $this->_getComparingValue($from, $filter));
     }
     if ($to !== '') {
         $select->where($priceExpr . ' <= ' . $this->_getComparingValue($to, $filter));
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Prepare price filter model
  *
  * @param Magento_Test_Request|null $request
  * @return void
  */
 protected function _prepareFilter($request = null)
 {
     $layer = new Mage_Catalog_Model_Layer();
     $layer->setCurrentCategory(4);
     $layer->setState(new Mage_Catalog_Model_Layer_State());
     $filter = new Mage_Catalog_Model_Layer_Filter_Price();
     $filter->setLayer($layer)->setAttributeModel(new Varien_Object(array('attribute_code' => 'price')));
     if (!is_null($request)) {
         $filter->apply($request, new Mage_Core_Block_Text());
         $interval = $filter->getInterval();
         if ($interval) {
             $this->_model->setLimits($interval[0], $interval[1]);
         }
     }
     $collection = $layer->getProductCollection();
     $this->_model->setPricesModel($filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize());
 }
Ejemplo n.º 3
0
 /**
  * Apply price range filter to product collection
  *
  * @param Mage_Catalog_Model_Layer_Filter_Price $filter
  * @return Mage_Catalog_Model_Resource_Layer_Filter_Price
  */
 public function applyPriceRange($filter)
 {
     $interval = $filter->getInterval();
     if (!$interval) {
         return $this;
     }
     list($from, $to) = $interval;
     if ($from === '' && $to === '') {
         return $this;
     }
     list($select, $priceExpr) = $this->_prepareApply($filter);
     if ($from == $to && !empty($to)) {
         $select->where($priceExpr . ' = ?', $from);
     } else {
         if ($from !== '') {
             $select->where($priceExpr . ' >= ?', $from);
         }
         if ($to !== '') {
             $select->where($priceExpr . ' < ?', $to);
         }
     }
     return $this;
 }