コード例 #1
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);
        }
コード例 #2
0
ファイル: shop.view.php プロジェクト: haegyung/xe-module-shop
 /**
  * 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());
     }
 }