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);
 }
Ejemplo n.º 2
0
        /**
         * call it through ajax (json)
         * @throws ShopException
         */
        public function procShopToolCheckFriendlyUrlAvailability()
        {
            if (!$type = Context::get('type')) $type = 'product';
            if (!$slug = Context::get('slug')) {
                //throw new ShopException('Missing slug');
                $this->add('notAvailable', FALSE);
                return;
            }

            if ($type == 'product') {
                $repo = new ProductRepository();
                $object = $repo->getProductByFriendlyUrl($slug);
            }
            elseif ($type == 'category') {
                $repo = new CategoryRepository();
                $object = $repo->getCategoryByFriendlyUrl($slug);
            }
            else throw new ShopException('Invalid entity type');

            $this->add('notAvailable', (boolean) $object);
        }
Ejemplo n.º 3
0
 /**
  * route
  * @return Object|void
  * @throws ShopException
  */
 public function route()
 {
     try {
         if (!$type = Context::get('type')) throw new ShopException('Routing: no type');
         if (!$identifier = Context::get('identifier')) throw new ShopException('Routing: no identifier');
         if ($type == 'product') {
             $repo = new ProductRepository();
             if (!$product = $repo->getProductByFriendlyUrl($identifier)) throw new ShopException('Product does not exist');
             Context::set('product', $product);
             return $this->dispShopProduct();
         }
         elseif ($type == 'category') {
             $repo = new CategoryRepository();
             if (!$cat = $repo->getCategoryByFriendlyUrl($identifier)) throw new ShopException('Category does not exist');
             Context::set('category', $cat);
             return $this->dispShop();
         }
         else throw new ShopException("Routing: invalid type: $type");
     }
     catch (ShopException $e) {
         $this->setRedirectUrl(getNotEncodedUrl('', 'act', 'dispShopHome'));
         return new Object(-1, $e->getMessage());
     }
 }