Ejemplo n.º 1
0
 /**
  * Apply attribute filter to product collection
  *
  * @param Mage_Catalog_Model_Layer_Filter_Price $filter
  * @param int $range
  * @param int $index    the range factor
  *
  * @return Enterprise_Search_Model_Catalog_Layer_Filter_Decimal
  */
 public function applyFilterToCollection($filter, $range, $index)
 {
     $productCollection = $filter->getLayer()->getProductCollection();
     $attributeCode = $filter->getAttributeModel()->getAttributeCode();
     $field = 'attr_decimal_' . $attributeCode;
     $value = array($field => array('from' => $range * ($index - 1), 'to' => $range * $index - 0.001));
     $productCollection->addFqFilter($value);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve array with products counts per price range
  *
  * @param Mage_Catalog_Model_Layer_Filter_Price $filter
  * @param int $range
  * @return array
  */
 public function getCountAttributePrice($filter, $range)
 {
     $ret = array();
     $rate = $this->getCurrentCurrencyRate($this->store);
     if (empty($filter) || empty($rate)) {
         return $ret;
     }
     $attribute = $filter->getAttributeModel();
     if (empty($attribute)) {
         return $ret;
     }
     // hook, it is need for 'union' and this attribute defined in the 'price' field
     if ($attribute->getAttributeCode() == 'price') {
         $label = 'price';
     } else {
         $label = 'attribute_' . $attribute->getId();
     }
     if (!$this->checkAttributesCountLabel($label)) {
         $vals = array();
         $res = $this->getSearchResult();
         if (!empty($res['facets'])) {
             foreach ($res['facets'] as $facet) {
                 if ($facet['attribute'] == $label) {
                     if (!empty($facet['buckets'])) {
                         foreach ($facet['buckets'] as $bucket) {
                             // Example
                             //~ [value] => 1000-2000
                             //~ [title] => 1000 - 2000
                             //~ [from] => 1000
                             //~ [to] => 2000
                             //~ [count] => 2
                             $numberStep = round($bucket['to'] * $rate / $range);
                             if ($numberStep > 0) {
                                 $vals[$numberStep] = $bucket['count'];
                             }
                         }
                     }
                 }
             }
         }
         $this->setAttributesCountLabel($vals, $label);
     }
     return $this->getAttributesCountLabel($label);
 }