Exemplo n.º 1
0
 public function action_item()
 {
     $product_id = $this->request->param('id');
     if (empty($product_id)) {
         throw new Exception("ID must not be empty!");
     }
     $view = View::factory('products/info');
     $products = new Model_Product();
     $clients = new Model_Client();
     $view->products = $products->get_product_by_id($product_id);
     $user_email = Session::instance()->get('email');
     $view->valute = $clients->get_user_valute($user_email);
     $this->template->content = $view->render();
 }
Exemplo n.º 2
0
 public function action_item()
 {
     if (Auth::is_admin_signed_in() === true) {
         $id = $this->request->param('id');
         if (empty($id)) {
             throw new Exception('ID Must Be Set!');
         }
         $view = View::factory('acp/products/info');
         $products = new Model_Product();
         $get_product_by_id = $products->get_product_by_id($id);
         $view->products = $get_product_by_id;
         if ($this->request->method() === Request::POST) {
             $name = strip_tags($this->request->post('name'));
             $is_discount = $this->request->post('is_discount');
             $discount = $this->request->post('discount');
             $description = $this->request->post('description');
             $price = $this->request->post('price') * 100;
             $img_url = $this->request->post('img_url');
             $count = $this->request->post('count');
             $token = $this->request->param('id');
             if (Security::check($token)) {
                 throw new Exception("Token is not valid!");
             }
             if (empty($is_discount) && empty($discount)) {
                 $is_discount = 0;
                 $discount = 0;
             } else {
                 $is_discount = 1;
             }
             if (empty($name) && empty($description) && empty($price)) {
                 throw new Exception("Please fill all fields!");
             }
             $products = new Model_Product();
             $data = array('is_discount' => $is_discount, 'discount' => $discount, 'name' => $name, 'description' => $description, 'price' => $price, 'image_url' => $img_url, 'count' => $count);
             $update_product_info = $products->update_product_info($data, $id);
             if (!$update_product_info) {
                 throw new Exception("Error with database");
             }
             $this->request->redirect('acp/products');
         }
         $this->template->content = $view->render();
     } else {
         $this->request->redirect('acp');
     }
 }