当前位置: 首页>>代码示例>>PHP>>正文


PHP Cart::getCount方法代码示例

本文整理汇总了PHP中Cart::getCount方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::getCount方法的具体用法?PHP Cart::getCount怎么用?PHP Cart::getCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cart的用法示例。


在下文中一共展示了Cart::getCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addtocart

 public function addtocart($goods_id)
 {
     $msg = array();
     if (!$goods_id) {
         $msg['error'] = '-1';
         $msg['msg'] = '加入购物车失败!';
         echo json_encode($msg);
         throw new Exception('exit');
     }
     $goods_id = (int) $goods_id;
     //模拟下单start
     $uid = LuS::get('uid');
     $data['goods_id'] = $goods_id;
     $data['goods_num'] = 1;
     // $data = $goods_id;
     //购物车已经存在$goods_id商品的数量
     $cart_goods_info = Cart::getCartGoodsInfoByGoodsId($uid, $goods_id);
     //检查库存
     $goods_info = AdminGoodsM::getGoodsInfoByGoodsId($goods_id);
     if ($goods_info['goods_num'] < $data['goods_num'] + $cart_goods_info['goods_num']) {
         $msg['error'] = '-2';
         $msg['msg'] = '库存不足!';
         echo json_encode($msg);
         throw new Exception('exit');
     }
     //添加
     $add_rs = Cart::add($uid, $data);
     if ($add_rs) {
         //模拟下单end
         $msg['error'] = '1';
         $msg['msg'] = '加入购物车成功!';
         $msg['num'] = Cart::getCount($uid);
     } else {
         //模拟下单end
         $msg['error'] = '-1';
         $msg['msg'] = '加入购物车失败!';
     }
     echo json_encode($msg);
     throw new Exception('exit');
 }
开发者ID:lughong,项目名称:shop,代码行数:40,代码来源:goods.php

示例2: _show

 public function _show($smarty)
 {
     $uid = LuS::get('uid');
     if ($uid) {
         $is_login = true;
     } else {
         $is_login = false;
     }
     $smarty->assign('is_login', $is_login);
     //首页
     $home_url = HOMEURL;
     $smarty->assign('home_url', $home_url);
     //登录
     $login_url = url('login', 'login::index');
     $smarty->assign('login_url', $login_url);
     //注册
     $reg_url = url('reg', 'reg::index');
     $smarty->assign('reg_url', $reg_url);
     //退出登录
     $outlogin_url = url('home', 'home::outlogin');
     $smarty->assign('outlogin_url', $outlogin_url);
     //个人中心
     $usercenter_url = url('usercenter', 'usercenter::index');
     $smarty->assign('usercenter_url', $usercenter_url);
     $my_order_url = url('usercenter', 'usercenter::orderlist');
     $smarty->assign('my_order_url', $my_order_url);
     //用户名
     $username = LuS::get('username');
     $smarty->assign('username', $username);
     //购物车数量
     $cart_num = Cart::getCount($uid);
     $smarty->assign('cart_num', $cart_num);
     //购物车
     $cart_url = url('goods', 'goods::cart');
     $smarty->assign('cart_url', $cart_url);
 }
开发者ID:lughong,项目名称:shop,代码行数:36,代码来源:GoodsM.class.php

示例3: checkout

 public function checkout()
 {
     $cartModel = new Cart();
     //Check cart is not empty
     $cartData = $cartModel->getCount();
     if ($cartData <= 0) {
         $this->Session->setFlash('Your cart is empty, please back to homepage to shopping.', 'default', array(), 'success');
         $this->redirect(array('controller' => 'carts', 'action' => 'view'));
     }
     //Check and save Customer data to database
     if ($this->request->is('post') && !empty($this->request->data)) {
         $this->Customer->create();
         if ($this->Customer->save($this->request->data)) {
             $customerId = $this->Customer->getLastInsertID();
             //Save data to "invoices" table
             $invoiceModel = new Invoice();
             $invoiceData = array();
             $invoiceData['Invoice']['customer_id'] = $customerId;
             $invoiceData['Invoice']['order_date'] = date('Y-d-m H:i:s', strtotime('+1day'));
             $foodModel = new Food();
             $cartArray = $cartModel->readFood();
             $totalPrice = $foodModel->getTotalPriceByCart($cartArray);
             $invoiceData['Invoice']['total_price'] = $totalPrice;
             $invoiceData['Invoice']['note'] = $this->request->data['Customer']['note'];
             $invoiceData['Invoice']['price_temp'] = $totalPrice;
             $invoiceData['Invoice']['price_refund'] = 0;
             $invoiceData['Invoice']['payment_type'] = 'Cash';
             if ($invoiceModel->save($invoiceData)) {
                 $invoiceId = $invoiceModel->getLastInsertID();
                 //Save data to "invoice_details" table
                 foreach ($cartArray as $foodId => $amount) {
                     $invoiceDetailModel = new InvoiceDetail();
                     $invoiceDetailData = array();
                     $invoiceDetailData['InvoiceDetail']['invoice_id'] = $invoiceId;
                     $invoiceDetailData['InvoiceDetail']['food_id'] = $foodId;
                     $invoiceDetailData['InvoiceDetail']['amount'] = $amount;
                     $foodData = $foodModel->getFoodDataById($foodId);
                     $invoiceDetailData['InvoiceDetail']['price'] = $foodData['Food']['price'];
                     $invoiceDetailData['InvoiceDetail']['is_choose'] = 0;
                     $invoiceDetailModel->save($invoiceDetailData);
                 }
                 //Set invoice_id to session after insert data to "invoices" table
                 CakeSession::write('invoice_id', $invoiceId);
                 //Remove cart ordered
                 $cartModel->resetCart();
                 $this->Session->setFlash('Thanks for your ordered.', 'default', array(), 'success');
                 $this->redirect(array('controller' => 'customers', 'action' => 'order'));
             }
         } else {
             $this->Session->setFlash('Please input correct data.', 'default', array(), 'error');
         }
     }
     //Show carts list
     $carts = $cartModel->readFood();
     $foods = array();
     if (null != $carts) {
         foreach ($carts as $foodId => $count) {
             $foodModel = new Food();
             $food = $foodModel->read(null, $foodId);
             $food['Food']['count'] = $count;
             $foods[] = $food;
         }
     }
     $this->set(compact('foods'));
 }
开发者ID:vinacode,项目名称:CakePHP-ShoppingCart-with-Admin-Managements,代码行数:65,代码来源:CustomersController.php

示例4: getResponse

 public function getResponse()
 {
     $this->doorGets->checkAjaxMode();
     $response = array('code' => 404, 'data' => array());
     $arrayAction = array('index' => 'Home', 'add' => 'add', 'plus' => 'plus', 'minus' => 'minus', 'remove' => 'remove', 'shippingMethod' => 'shippingMethod');
     $out = '';
     $params = $this->doorGets->Params();
     $modules = $this->doorGets->getAllActiveModules();
     $lgActuel = $this->doorGets->getLangueTradution();
     $lg = 'en';
     if (array_key_exists('lg', $params['GET']) && array_key_exists($params['GET']['lg'], $this->doorGets->allLanguages)) {
         $lg = $this->doorGets->myLanguage = $params['GET']['lg'];
     }
     if (array_key_exists($this->Action, $arrayAction)) {
         switch ($this->Action) {
             case 'index':
                 break;
             case 'add':
                 if (true) {
                     $uri = array_key_exists('uri', $params['GET']) && !empty($params['GET']['uri']) ? $params['GET']['uri'] : '';
                     $quantity = array_key_exists('qty', $params['GET']) && !empty($params['GET']['qty']) ? (int) $params['GET']['qty'] : 1;
                     $id = array_key_exists('id', $params['GET']) && !empty($params['GET']['id']) ? $params['GET']['id'] : '';
                     if (empty($quantity)) {
                         $quantity = 1;
                     }
                     if (!empty($uri) && !empty($id) && array_key_exists($uri, $modules)) {
                         $sqlUri = $this->doorGets->getRealUri($uri);
                         $table = '_m_' . $sqlUri;
                         $tableTraduction = $table . '_traduction';
                         $isContent = $this->doorGets->dbQS($id, $table);
                         if (!empty($isContent)) {
                             $idTraduction = $this->doorGets->getIdContentTraduction($isContent);
                             if (!is_null($idTraduction)) {
                                 $isContentTraduction = $this->doorGets->dbQS($idTraduction, $tableTraduction);
                                 if (!empty($isContentTraduction)) {
                                     $product = array('uri' => $uri, 'id' => $id, 'quantity' => $quantity);
                                     $Cart = new Cart($this->doorGets);
                                     $Cart->addProduct($product);
                                     $Cart->save();
                                     $products = $Cart->getProducts();
                                     $productName = $products[$uri . '-' . $id]['title'];
                                     $response = array('code' => 200, 'data' => array('message' => $productName . ' ' . $this->doorGets->__("est dans votre panier") . '.', 'products' => $Cart->getProducts(), 'count' => $Cart->getCount(), 'totalAmount' => number_format($Cart->getTotalAmount(), 2, ',', ' '), 'totalAmountVat' => number_format($this->vat * $Cart->getTotalAmount() + $Cart->shippingAmount, 2, ',', ' '), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => number_format($Cart->getTotalAmountPromo(), 2, ',', ' '), 'totalAmountPromoVat' => number_format($this->vat * $Cart->getTotalAmountPromo() + $Cart->shippingAmount, 2, ',', ' '), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'uri' => $uri));
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'minus':
                 if (array_key_exists('uri', $params['GET'])) {
                     $uri = $params['GET']['uri'];
                     $Cart = new Cart($this->doorGets);
                     $newAmount = $Cart->minusProduct($uri);
                     $Cart->save();
                     $response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le quantité du produit a été mise à jour") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'newAmount' => $newAmount, 'uri' => $uri));
                 }
                 break;
             case 'plus':
                 if (array_key_exists('uri', $params['GET'])) {
                     $uri = $params['GET']['uri'];
                     $Cart = new Cart($this->doorGets);
                     $newAmount = $Cart->plusProduct($uri);
                     $Cart->save();
                     $response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le quantité du produit a été mise à jour") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'newAmount' => $newAmount, 'uri' => $uri));
                 }
                 break;
             case 'remove':
                 if (array_key_exists('uri', $params['GET'])) {
                     $uri = $params['GET']['uri'];
                     $Cart = new Cart($this->doorGets);
                     $Cart->removeProduct($uri);
                     $Cart->save();
                     $response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le produit a été supprimé de votre panier") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'uri' => $uri));
                 }
                 break;
             case 'shippingMethod':
                 if (array_key_exists('key', $params['GET'])) {
                     $key = $params['GET']['key'];
                     $Cart = new Cart($this->doorGets);
                     $Cart->setShippingMethod($key);
                     $Cart->save();
                     $response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le prix de la livraison est à jour") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg));
                 }
                 break;
         }
     }
     return json_encode($response, JSON_FORCE_OBJECT);
 }
开发者ID:doorgets,项目名称:cms,代码行数:88,代码来源:cartView.php


注:本文中的Cart::getCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。