Example #1
0
 private function CheckIdExist()
 {
     if (!Db_Orders::checkExists($this->Id, 'id')) {
         $this->Msg->SetMsg($this->_T('error_id_not_exist') . ' ' . $this->Id);
         $this->Msg->SetError(true);
         $this->Redirect($this->PageUrl);
     }
 }
Example #2
0
 public function __construct($title = '')
 {
     parent::__construct($title);
     switch ($this->Url) {
         case 'addToCart':
             $id = getPost('id');
             $_SESSION['cart'][$id] = Db_Product::getWithTrans($id);
             $_SESSION['cart'][$id]['qty'] = 1;
             $this->TPL->display('/parts/widgets/header/shopping-cart');
             die;
             break;
         case 'removeFromCart':
             $id = getPost('id');
             unset($_SESSION['cart'][$id]);
             $this->TPL->display('/parts/widgets/header/shopping-cart');
             die;
             break;
         case 'setProductQty':
             $id = getPost('id');
             $qty = getPost('qty');
             $_SESSION['cart'][$id]['qty'] = $qty;
             die;
             break;
         case 'checkTransExists':
             $key = getPost('key');
             $id = getPost('id');
             if (Db_Trans::checkKey($key, $id)) {
                 echo '1';
             } else {
                 echo '0';
             }
             die;
             break;
         case 'filter':
             $types = isset($_POST['types']) ? getPost('types') : array();
             $colors = isset($_POST['colors']) ? getPost('colors') : array();
             $brands = isset($_POST['brands']) ? getPost('brands') : array();
             $price = getPost('price');
             $products = Db_Product::filter($types, $colors, $brands, $price);
             if (empty($products)) {
                 die;
             }
             $this->TPL->assign('products', $products);
             $this->TPL->display('/parts/section/category/category-v1-grid');
             die;
             break;
         case 'saveOrder':
             if (!isset($_SESSION['cart']) || empty($_SESSION['cart'])) {
                 die;
             }
             $first_name = getPost('first_name');
             $last_name = getPost('last_name');
             $address = getPost('address');
             $city = getPost('city');
             $email = getPost('email');
             $mobile = getPost('mobile');
             $Order = new Db_Orders();
             $Order->first_name = $first_name;
             $Order->last_name = $last_name;
             $Order->address = $address;
             $Order->city = $city;
             $Order->email = $email;
             $Order->mobile = $mobile;
             $Order->date_add = date('Y-m-d H:i:s');
             $Order->status = 'new';
             $Order->save();
             foreach ($_SESSION['cart'] as $product) {
                 $Product = new Db_OrderProducts();
                 $Product->op_order_id = $Order->id;
                 $Product->op_product_id = $product['id'];
                 $Product->op_coupon = '10%';
                 $Product->op_qty = $product['qty'];
                 $Product->save();
             }
             $this->_S->Set('buy', true);
             unset($_SESSION['cart']);
             die;
             break;
     }
 }