/** * Apply decimal range filter to product collection * * @param Zend_Controller_Request_Abstract $request * @param Mage_Catalog_Block_Layer_Filter_Decimal $filterBlock * @return Mage_Catalog_Model_Layer_Filter_Decimal */ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { $attributeCode = $this->getAttributeModel()->getAttributeCode(); /** @var Amasty_Shopby_Helper_Attributes $attributeHelper */ $attributeHelper = Mage::helper('amshopby/attributes'); if (!$attributeHelper->lockApplyFilter($attributeCode, 'attr')) { return $this; } if (!$this->calculateRanges()) { $this->_items = array($this->_createItem('', 0, 0)); } $filterBlock->setValueFrom(Mage::helper('amshopby')->__('From')); $filterBlock->setValueTo(Mage::helper('amshopby')->__('To')); $input = $request->getParam($this->getRequestVar()); $fromTo = $this->_parseRequestedValue($input); if (is_null($fromTo)) { return $this; } list($from, $to) = $fromTo; $this->_getResource()->applyFilterToCollection($this, $from, $to); $filterBlock->setValueFrom($from); if ($to > 0) { $filterBlock->setValueTo($to); } else { $filterBlock->setValueTo(''); } $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderItemLabel($from, $to, true), $input)); if ($this->hideAfterSelection()) { $this->_items = array(); } elseif ($this->calculateRanges()) { $this->_items = array($this->_createItem('', 0, 0)); } return $this; }
/** * Apply decimal range filter to product collection * * @param Zend_Controller_Request_Abstract $request * @param Mage_Catalog_Block_Layer_Filter_Decimal $filterBlock * @return Mage_Catalog_Model_Layer_Filter_Decimal */ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { if (!$this->calculateRanges()) { $this->_items = array($this->_createItem('', 0, 0)); } $filterBlock->setValueFrom(Mage::helper('amshopby')->__('From')); $filterBlock->setValueTo(Mage::helper('amshopby')->__('To')); /** * Filter must be string: $index, $range */ $filter = $request->getParam($this->getRequestVar()); if (!$filter) { return $this; } $isFromTo = false; $range = array(); /* * Try range */ $range = explode($this->_rangeSeparator, $filter); if (count($range) != 2) { /* * Try from to */ $range = explode($this->_fromToSeparator, $filter); if (count($range) == 2) { $isFromTo = true; } else { return $this; } } list($from, $to) = $range; $from = floatval($from); $to = floatval($to); if ($from || $to) { if (!$isFromTo) { $index = $from; $range = $to; $from = ($index - 1) * $range; $to = $index * $range; } $this->_getResource()->applyFilterToCollection($this, $from, $to); $filterBlock->setValueFrom($from); if ($to > 0) { $filterBlock->setValueTo($to); } else { $filterBlock->setValueTo(''); } $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderItemLabel($from, $to, true), $filter)); if ($this->hideAfterSelection()) { $this->_items = array(); } elseif ($this->calculateRanges()) { $this->_items = array($this->_createItem('', 0, 0)); } } return $this; }