Mage_Catalog_Model_Layer_Filter_Price Class Reference

Inheritance diagram for Mage_Catalog_Model_Layer_Filter_Price:

Mage_Catalog_Model_Layer_Filter_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 getPriceRange ()
 getMaxPriceInt ()
 getRangeItemCounts ($range)
 apply (Zend_Controller_Request_Abstract $request, $filterBlock)

Public Attributes

const MIN_RANGE_POWER = 10

Protected Member Functions

 _renderItemLabel ($range, $value)
 _getCacheKey ()
 _getItemsData ()


Detailed Description

Definition at line 34 of file Price.php.


Constructor & Destructor Documentation

__construct (  ) 

Class constructor

Reimplemented from Varien_Object.

Definition at line 42 of file Price.php.

00043     {
00044         parent::__construct();
00045         $this->_requestVar = 'price';
00046     }


Member Function Documentation

_getCacheKey (  )  [protected]

Get price aggreagation data cache key

Returns:
string

Definition at line 131 of file Price.php.

00132     {
00133         $key = $this->getLayer()->getStateKey()
00134             . '_PRICES_GRP_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
00135             . '_CURR_' . Mage::app()->getStore()->getCurrentCurrencyCode()
00136             . '_LOC_'
00137             ;
00138         $taxReq = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
00139         $key.= $taxReq->__toString(array(), '_');
00140         return $key;
00141     }

_getItemsData (  )  [protected]

Get data for build price filter items

Returns:
array

Reimplemented from Mage_Catalog_Model_Layer_Filter_Abstract.

Definition at line 148 of file Price.php.

00149     {
00150         $key = $this->_getCacheKey();
00151 
00152         $data = $this->getLayer()->getAggregator()->getCacheData($key);
00153         if ($data === null) {
00154             $range      = $this->getPriceRange();
00155             $dbRanges   = $this->getRangeItemCounts($range);
00156             $data       = array();
00157 
00158             foreach ($dbRanges as $index=>$count) {
00159                 $data[] = array(
00160                     'label' => $this->_renderItemLabel($range, $index),
00161                     'value' => $index . ',' . $range,
00162                     'count' => $count,
00163                 );
00164             }
00165 
00166             $tags = array(
00167                 Mage_Catalog_Model_Product_Type_Price::CACHE_TAG,
00168             );
00169             $tags = $this->getLayer()->getStateTags($tags);
00170             $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags);
00171         }
00172         return $data;
00173     }

_renderItemLabel ( range,
value 
) [protected]

Prepare text of item label

Parameters:
int $range
float $value
Returns:
string

Definition at line 118 of file Price.php.

00119     {
00120         $store      = Mage::app()->getStore();
00121         $fromPrice  = $store->formatPrice(($value-1)*$range);
00122         $toPrice    = $store->formatPrice($value*$range);
00123         return Mage::helper('catalog')->__('%s - %s', $fromPrice, $toPrice);
00124     }

apply ( Zend_Controller_Request_Abstract $  request,
filterBlock 
)

Apply price range filter to collection

Returns:
Mage_Catalog_Model_Layer_Filter_Price

Filter must be string: $index,$range

Reimplemented from Mage_Catalog_Model_Layer_Filter_Abstract.

Definition at line 180 of file Price.php.

00181     {
00182         /**
00183          * Filter must be string: $index,$range
00184          */
00185         $filter = $request->getParam($this->getRequestVar());
00186         if (!$filter) {
00187             return $this;
00188         }
00189 
00190         $filter = explode(',', $filter);
00191         if (count($filter) != 2) {
00192             return $this;
00193         }
00194 
00195         list($index, $range) = $filter;
00196 
00197         if ((int)$index && (int)$range) {
00198             $this->setPriceRange((int)$range);
00199 
00200             Mage::getSingleton('catalogindex/price')->applyFilterToCollection(
00201                 $this->getLayer()->getProductCollection(),
00202                 $this->getAttributeModel(),
00203                 $range,
00204                 $index
00205             );
00206 
00207             $this->getLayer()->getState()->addFilter(
00208                 $this->_createItem($this->_renderItemLabel($range, $index), $filter)
00209             );
00210 
00211             $this->_items = array();
00212         }
00213         return $this;
00214     }

getMaxPriceInt (  ) 

Get maximum price from layer products set

Returns:
float

Definition at line 76 of file Price.php.

00077     {
00078         $maxPrice = $this->getData('max_price_int');
00079         if (is_null($maxPrice)) {
00080             $maxPrice = Mage::getSingleton('catalogindex/price')->getMaxValue(
00081                 $this->getAttributeModel(),
00082                 $this->_getBaseCollectionSql()
00083             );
00084 
00085             $maxPrice = floor($maxPrice);
00086             $this->setData('max_price_int', $maxPrice);
00087         }
00088         return $maxPrice;
00089     }

getPriceRange (  ) 

Get price range for building filter steps

Returns:
int

Definition at line 53 of file Price.php.

00054     {
00055         $range = $this->getData('price_range');
00056         if (is_null($range)) {
00057             $maxPrice = $this->getMaxPriceInt();
00058             $index = 1;
00059             do {
00060                 $range = pow(10, (strlen(floor($maxPrice))-$index));
00061                 $items = $this->getRangeItemCounts($range);
00062                 $index++;
00063             }
00064             while($range>self::MIN_RANGE_POWER && count($items)<2);
00065 
00066             $this->setData('price_range', $range);
00067         }
00068         return $range;
00069     }

getRangeItemCounts ( range  ) 

Get information about products count in range

Parameters:
int $range
Returns:
int

Definition at line 97 of file Price.php.

00098     {
00099         $items = $this->getData('range_item_counts_'.$range);
00100         if (is_null($items)) {
00101             $items = Mage::getSingleton('catalogindex/price')->getCount(
00102                 $this->getAttributeModel(),
00103                 $range,
00104                 $this->_getBaseCollectionSql()
00105             );
00106             $this->setData('range_item_counts_'.$range, $items);
00107         }
00108         return $items;
00109     }


Member Data Documentation

const MIN_RANGE_POWER = 10

Definition at line 36 of file Price.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:39 2009 for Magento by  doxygen 1.5.8