Example #1
0
 public function edit(Product $product)
 {
     $query = "Update products Set name = ?, categoryId = ?, price = ?, quantity = ?, editorId = ?\n        WHERE products.id = ?";
     $params = [$product->getName(), $product->getCategoryId(), $product->getPrice(), $product->getQuantity(), $product->getEditorId(), $product->getId()];
     $this->db->query($query, $params);
     $result = $this->db->row();
     return $result;
 }
Example #2
0
 public function addToCart()
 {
     $product_id = $this->http->get('product_id');
     $product_name = $this->http->get('product_name');
     $product_quantity = $this->http->get('product_quantity');
     $product_price = $this->http->get('product_price');
     $product = new Product($product_id);
     if (!empty($product)) {
         $db = Register::get('db');
         $quantity = $product->getQuantity();
         if ($quantity > 0 && $quantity >= $product_quantity && $product_quantity >= 0) {
             $product->setQuantity($quantity - $product_quantity);
             $product->changeProductSold($product_quantity);
             $cart = \Lib\Session::get('cart');
             if (!empty($cart)) {
                 foreach ($cart as $p) {
                     if ($p['product_id'] == $product_id) {
                         $order = new Order($p['order_id']);
                         if ($order->getQuantity()) {
                             $quantity = $order->getQuantity();
                             $order->setQuantity($quantity + $product_quantity);
                             $db->query('START TRANSACTION');
                             if ($product->writeData(true) && $order->writeData(true)) {
                                 $order_id = $db->getLastInsertedId();
                                 $db->query('COMMIT');
                                 \Lib\Session::set('cart', array('order_id' => $order_id, 'product_id' => $product_id), 2);
                             } else {
                                 $db->query('ROLLBACK');
                             }
                             $this->ActNumberOfProducts();
                             Location::To(URL . 'cart/show');
                         }
                     }
                 }
             }
             $order = new Order();
             $order->setDate();
             $order->setActive(false);
             $order->setProductId($product_id);
             $order->setProductName($product_name);
             $order->setQuantity($product_quantity);
             $order->setPrice($product->getPrice());
             $order->setStatus(1);
             $db->query('START TRANSACTION');
             if ($product->writeData(true) && $order->writeData()) {
                 $order_id = $db->getLastInsertedId();
                 $db->query('COMMIT');
                 \Lib\Session::set('cart', array('order_id' => $order_id, 'product_id' => $product_id), 2);
             } else {
                 $db->query('ROLLBACK');
             }
             $this->ActNumberOfProducts();
             \Lib\Location::To(URL . 'cart/show');
         } else {
             \Lib\Location::To(URL . 'cart/show');
         }
     }
 }
Example #3
0
 public function addToSlider()
 {
     $http = new Http();
     $return = array();
     $id = $http->post('id_new_product');
     if (!empty($id)) {
         $slider_m = new Slider();
         $slider_m->setProductId($id);
         $slider_m->writeData();
         $product = new Product($id);
         $return['id'] = $id;
         $return['name'] = $product->getName();
         $return['img'] = $product->getImage();
         $return['price'] = $product->getPrice();
     }
     echo json_encode($return);
 }