public function AddCartAction()
 {
     $user = $this->app['session']->get('user', '');
     $shopcart = $this->app['session']->get('cart_' . $user, '');
     if ($shopcart == '') {
         $shopcart = array();
     }
     $iss = '';
     if ($input = $this->getPostData()) {
         $total_price = $input['total_price'];
         for ($i = 0; $i < count($shopcart); $i++) {
             if ($input['id_'] == $shopcart[$i]['id']) {
                 $shopcart[$i]['quantity']++;
                 $shopcart[$i]['total'] = $shopcart[$i]['quantity'] * $shopcart[$i]['price'];
                 $shopcart[$i]['total_price'] = $total_price = $shopcart[$i]['total_price'] + $shopcart[$i]['price'];
                 $iss = true;
             } else {
                 $shopcart[$i]['total_price'] = $total_price = $total_price + $shopcart[$i]['total'];
             }
         }
         if ($iss == '') {
             $pro = Model::getById('products', $input['id_']);
             $total_price = $total_price + $pro->price;
             $cart = array('id' => $pro->id, 'images' => $pro->images, 'price' => $pro->price, 'total' => $pro->price, 'name' => $pro->name, 'num' => $pro->num, 'quantity' => 1, 'total_price' => $total_price);
             array_push($shopcart, $cart);
         }
         $data['total_price'] = $total_price;
         $this->app['session']->set('cart_' . $user, $shopcart);
         echo $pro['id'];
         exit;
     }
 }
 public function FormAction($id = '')
 {
     //set
     if ($id != '') {
         $action = 'update';
         $data['action'] = 'update';
         $data['category'] = Model::getById('cate', $id);
     } else {
         $action = 'add';
     }
     $data['title'] = '';
     $data['fullname'] = '';
     //enter
     if ($input = $this->getPostData()) {
         $url = $this->app['slugify']->slugify($input['name']);
         $post = array('name' => $input['name'], 'target' => $url);
         if ($action == 'update') {
             $cate = Model::update('cate', $post, $id);
         } else {
             $cate = Model::add('cate', $post);
         }
         //check
         if ($cate == true) {
             return $this->redirect('list_category');
         } else {
             $data['notification'] = 'Co loi xay ra';
         }
     }
     return $this->render('admin/category/form.html.twig', $data);
 }
 public function FormAction($idcate, $id = '')
 {
     //
     if ($id != '') {
         $data['action'] = 'update';
         $action = 'Cập nhật';
         $data['product'] = Model::getById('products', $id);
     } else {
         $data['action'] = 'add';
         $action = 'Thêm mới';
     }
     $data['title'] = $action . ' sản phẩm ';
     $data['fullname'] = $this->app['session']->get('admin', '');
     //
     if ($input = $this->getPostData()) {
         $url = $this->app['slugify']->slugify($input['name']);
         $input = array('name' => $input['name'], 'images' => $input['images'], 'target' => $url, 'cate' => $idcate, 'made' => $input['made'], 'num' => $input['num'], 'price' => $input['price']);
         if ($data['action'] == 'add') {
             $product = Model::add('products', $input);
         } else {
             $product = Model::update('products', $input, $id);
         }
         if ($product == true) {
             return $this->redirect('list_Products', array('idcate' => $idcate));
         } else {
             $data['notification'] = 'co loi xay ra';
         }
     }
     return $this->render('admin/post/form.html.twig', $data);
 }