public function indexAction($id)
 {
     $products = new \modules\commerce\models\Commerce_products();
     $category = new \modules\commerce\models\Commerce_categories();
     $category->commerce_category_id = $id;
     $products->commerce_category_id = $id;
     return $this->render('commerce_category', ['item' => $category->get(), 'products' => $products->get(), 'product_model' => $products]);
 }
 public function deleteAction($id = false)
 {
     $this->permission('delete');
     if (!$id) {
         return Brightery::error404();
     }
     $commerce = new \modules\commerce\models\Commerce_products();
     $commerce->commerce_product_id = $id;
     if ($commerce->delete()) {
         Uri_helper::redirect("management/commerce_products");
     }
 }
 public function indexAction()
 {
     $order = new \modules\commerce\models\Commerce_orders('order');
     $order_details = new \modules\commerce\models\Commerce_order_details(false);
     $product = new \modules\commerce\models\Commerce_products(false);
     $invoice = new \modules\commerce\models\Commerce_invoices(false);
     $payment_method = Form_helper::queryToDropdown('commerce_payment_method', 'commerce_payment_method_id', 'name', false);
     $addresses = Form_helper::queryToDropdown('user_addresses', 'user_address_id', 'address', false, "WHERE user_id = " . $this->user->user_id);
     $order->set('subtotal', $this->cart->total());
     $order->set('total', $this->cart->total());
     $order->set('commerce_payment_method_id', $this->input->post('commerce_payment_method_id'));
     $order->set('user_id', $this->user->user_id);
     $order->set('billing_address', $addresses[$this->input->post('billing_address')]);
     $order->set('shipping_address', $addresses[$this->input->post('shipping_address')]);
     $order->set('status', $this->input->post('commerce_payment_method_id') == 2 ? 'confirmed' : 'pending');
     if ($order_id = $order->save()) {
         foreach ($this->cart->get() as $item) {
             $order_details->commerce_order_id = $order_id;
             $order_details->product_total = $product->discount($item->price, $item->discount) * $item->qty;
             $order_details->price = $product->discount($item->price, $item->discount);
             $order_details->commerce_product_id = $item->commerce_product_id;
             $order_details->weight = $item->weight;
             $order_details->qty = $item->qty;
             $order_details->save();
         }
         // INVOICE
         $invoice->commerce_order_id = $order_id;
         $invoice->status = 'pending';
         $invoice->save();
         if ($this->input->post('commerce_payment_method_id') == '1') {
             $this->layout = 'ajax';
             return $this->render('payments/paypal', ['total' => $this->cart->total()]);
         }
         // THANK YOU FOR YOUR ORDER
         return $this->render('commerce_orders/commerce_order_confirmed');
     } else {
         return $this->render('commerce_orders/commerce_make_order', ['user' => $this->user, 'payment' => $payment_method, 'addresses' => $addresses, 'cart' => $this->cart]);
     }
 }
 public function indexAction($offset = 0)
 {
     $category = new \modules\commerce\models\Commerce_categories();
     $brands = new \modules\commerce\models\Commerce_brands();
     $product = new \modules\commerce\models\Commerce_products();
     $category->_select = "commerce_category_id, title, parent";
     $category->parent = 0;
     $sorting = ['' => 'Sort By', 'name' => 'Name', 'low_price' => 'Low Price', 'heigh_price' => 'Heigh Price'];
     if (is_array($this->input->get('category_id')) && count($this->input->get('category_id')) && !empty($this->input->get('category_id.0'))) {
         $product->where('commerce_category_id IN (SELECT commerce_category_id FROM commerce_categories WHERE parent IN ("' . implode('","', $this->input->get('category_id')) . '")) ');
     }
     //UNION ALL SELECT ("'. implode('","', $this->input->get('category_id')) .'
     if ($this->input->get('brand_id')) {
         $product->where('commerce_brand_id IN ("' . implode('","', $this->input->get('brand_id')) . '")');
     }
     if ($this->input->get('q')) {
         $product->like('commerce_products.name', $this->input->get('q'));
     }
     if ($this->input->get('from_price')) {
         $product->like('commerce_products.price >=', $this->input->get('from_price'));
     }
     if ($this->input->get('to_price')) {
         $product->like('commerce_products.price <=', $this->input->get('to_price'));
     }
     if ($this->input->get('sorting')) {
         if ($this->input->get('sorting') == 'name') {
             $product->_order_by['name'] = 'ASC';
         } elseif ($this->input->get('sorting') == 'low_price') {
             $product->_order_by['price'] = 'ASC';
         } elseif ($this->input->get('sorting') == 'heigh_price') {
             $product->_order_by['price'] = 'DESC';
         }
     }
     $this->load->library('pagination');
     $product->_limit = $this->config->get('limit');
     $product->_offset = $offset;
     return $this->render('commerce_search', ['categories' => $category->get(), 'brands' => $brands->get(), 'sorting' => $sorting, 'products' => $product->get(), 'product_model' => $product, 'pagination' => $this->Pagination->generate(['url' => Uri_helper::url('commerce_search/index'), 'total' => $product->get(true), 'limit' => $product->_limit, 'offset' => $product->_offset])]);
 }