Ejemplo n.º 1
0
 public static function setValuesForTemplate($module_srl)
 {
     $productRepo = new ProductRepository();
     $maxPrice = $productRepo->getMaxPrice($module_srl);
     $minPrice = 0;
     $priceFilter = array($minPrice, Context::get(self::TO_PRICE_MIN) ? Context::get(self::TO_PRICE_MIN) : $minPrice, Context::get(self::TO_PRICE_MAX) ? Context::get(self::TO_PRICE_MAX) : $maxPrice, $maxPrice);
     Context::set('priceFilter', $priceFilter);
     $attributeRepo = new AttributeRepository();
     $catSrls = array();
     if (is_numeric($catSrl = Context::get('category_srl'))) {
         $catSrls[] = $catSrl;
     } elseif (Context::get('type') == 'category' && ($slug = Context::get('identifier'))) {
         //friendly url
         $cRepo = new CategoryRepository();
         $cat = $cRepo->getCategoryByFriendlyUrl($slug);
         $catSrls[] = $cat->category_srl;
     }
     $attrs = $attributeRepo->getFilterAttributes($module_srl, $catSrls);
     foreach ($attrs as $i => $attribute) {
         /** @var $attribute Attribute */
         if ($attribute->isNumeric()) {
             $min = $attribute->getMinValue();
             $min |= 0;
             //if there is no max value for this attribute unset it
             if (!($max = (int) $attribute->getMaxValue())) {
                 unset($attrs[$i]);
                 continue;
             }
             $attribute->setMeta('min', $min);
             $attribute->setMeta('max', $max);
             $minKey = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_NUMERIC_MIN);
             if (isset($_GET[$minKey]) && is_numeric($minValue = $_GET[$minKey])) {
                 $attribute->setMeta('minValue', $minValue);
             }
             $maxKey = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_NUMERIC_MAX);
             if (isset($_GET[$maxKey]) && is_numeric($maxValue = $_GET[$maxKey])) {
                 $attribute->setMeta('maxValue', $maxValue);
             }
         } elseif ($attribute->isSelect()) {
             $key = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_SELECT);
             if (isset($_GET[$key]) && ($val = $_GET[$key])) {
                 $attribute->setMeta('filterValue', $val);
             }
         } elseif ($attribute->isMultipleSelect()) {
             $key = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_SELECT_MULTIPLE);
             if (isset($_GET[$key]) && ($val = $_GET[$key])) {
                 $values = explode(self::SEPARATOR_MULTIPLE, $val);
                 $attribute->setMeta('filterValues', $values);
             }
         }
     }
     Context::set('filter_attributes', $attrs);
 }