public function change_quantity()
 {
     import('@.ORG.Cart');
     $cart = new \Cart();
     $goodId = I('post.itemId', '', 'intval');
     $quantity = I('post.quantity', '', 'intval');
     $item = api('Document/get_detail', array('id' => $goodId));
     if ($item['shop_goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '该商品的库存不足');
     } else {
         $cart->modNum($goodId, $quantity);
         $data = array('status' => 1, 'item' => $cart->getItem($goodId), 'sumPrice' => $cart->getPrice());
     }
     echo json_encode($data);
 }
 public function change_quantity()
 {
     import('Think.ORG.Cart');
     // 导入购物车类
     $cart = new Cart();
     $itemId = $this->_post('itemId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $item = M('item')->field('goods_stock')->find($itemId);
     if ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '该商品的库存不足');
     } else {
         $cart->modNum($itemId, $quantity);
         $data = array('status' => 1, 'item' => $cart->getItem($itemId), 'sumPrice' => $cart->getPrice());
     }
     echo json_encode($data);
 }
Exemple #3
0
 function add($item_id, $item_table, $qty = false, $table = false)
 {
     global $CFG;
     $table = $table ? $table : 'cart';
     $item = DB::getRecord($item_table, $item_id, false, true);
     $item_name = $item['name'];
     if (!($item_id > 0) && !$item) {
         $errors[$item_id] = $CFG->cart_item_error;
         Errors::merge($errors);
         return false;
     }
     if (empty($item_table)) {
         $errors[$item_id] = $CFG->cart_table_error;
         Errors::merge($errors);
         return false;
     }
     if (!($qty > 0)) {
         $errors[$item_id] = $CFG->cart_qty_error;
         Errors::merge($errors);
         return false;
     }
     if ($c_item = Cart::getItem($item_id, $item_table, $table)) {
         return Cart::update($item_id, $item_table, $c_item['qty'] + $qty, $table);
     }
     if (User::isLoggedIn()) {
         $id = DB::insert($table, array('item_id' => $item_id, 'item_table' => $item_table, 'qty' => $qty, 'user_id' => User::$info['id']));
         $messages[$item_name] = str_ireplace('[qty]', $qty, $CFG->cart_add_message);
         Messages::merge($messages);
         return $id;
     } else {
         $_SESSION['cart'][$item_table . '_' . $item_id] = array('item_id' => $item_id, 'item_table' => $item_table, 'qty' => $qty);
         $messages[$item_name] = str_ireplace('[qty]', $qty, $CFG->cart_add_message);
         Messages::merge($messages);
         return true;
     }
 }
Exemple #4
0
 /**
  * Controller action to manage the details of the cart.
  * Update/delete items or load the list.
  *
  * @return void
  */
 public function cartdetailsAction()
 {
     $account = Cible_FunctionsGeneral::getAuthentication();
     if (!$account) {
         $this->_redirect(Cible_FunctionsPages::getPageNameByID(1, Zend_Registry::get('languageID')));
     }
     $productData = array();
     $cart = new Cart();
     if ($this->_isXmlHttpRequest) {
         $this->disableLayout();
         $this->disableView();
         $action = $this->_getParam('do');
         $productId = $this->_getParam('pId');
         $itemId = $this->_getParam('itemId');
         $quantity = $this->_getParam('quantity');
         $size = $this->_getParam('size');
         $category = $this->_getParam('category');
         $disable = $this->_getParam('disable');
         $cartId = $this->_getParam('cartItemsId');
         if ($action == 'update' && !empty($productId)) {
             if (!empty($size)) {
                 $cart->updateItem($productId, -1, array('CI_TailleID' => $size, 'CI_ItemID' => $itemId, 'CI_CartItemsID' => $cartId));
             } elseif (!empty($category)) {
                 $cart->updateItem($productId, -1, array('CI_CatTailleID' => $category, 'CI_ItemID' => $itemId, 'CI_CartItemsID' => $cartId));
             } else {
                 $oItem = new ItemsObject();
                 $oItem->setId($itemId);
                 $amount = $oItem->getPrice($quantity);
                 $cart->updateItem($productId, $quantity, array('CI_ItemID' => $itemId, 'CI_Total' => $amount, 'CI_CartItemsID' => $cartId));
             }
             echo 'updated';
         } elseif ($action == 'delete' && !empty($productId)) {
             if ($itemId && $cartId) {
                 $cart->updateItem($productId, 0, array('CI_ItemID' => $itemId, 'CI_CartItemsID' => $cartId));
                 echo 'deletedRow';
             } else {
                 $cart->updateItem($productId);
                 echo 'deleted';
             }
         } elseif ($action == 'disable' && !empty($productId)) {
             $cart->updateItem($productId, -1, array('CI_IsToSend' => $disable, 'CI_ItemID' => $itemId));
         } elseif ($action == 'addSize' && !empty($productId)) {
             $lastId = $cart->addSize(array('CI_ID' => $productId, 'CI_Quantity' => 1, 'CI_CatTailleID' => $category, 'CI_ItemID' => $itemId));
         } elseif ($action == 'getSizes' && !empty($category)) {
             $oSize = new TailleObject();
             $langId = $this->_getParam('langId');
             $size = $oSize->getDataByCategoryTailleId($category, $langId);
             echo json_encode($size);
             exit;
         }
     } else {
         $url = $this->view->absolute_web_root . $this->getRequest()->getPathInfo();
         $exclude = preg_match('/resume-order/', $url);
         if (!$exclude) {
             Cible_View_Helper_LastVisited::saveThis($url);
         }
         $urlBack = '';
         $urlNextStep = '';
         $urls = Cible_View_Helper_LastVisited::getLastVisited();
         if (count($urls) > 1) {
             $urlBack = $urls[1];
         }
         $account = Cible_FunctionsGeneral::getAuthentication();
         $profile = new MemberProfile();
         $memberData = $profile->findMember(array('email' => $account['email']));
         $memberData = $profile->addTaxRate($memberData);
         //            if ($memberData['validatedEmail'] == '')
         //                $this->view->assign('valide', true);
         //            else
         //                $this->view->assign('valide', false);
         $cartData = $cart->getAllIds();
         $allIds = $cartData['cartId'];
         if (count($allIds)) {
             $urlNextStep = $this->view->baseUrl() . '/' . Cible_FunctionsPages::getPageNameByID($this->_orderPageId, Zend_Registry::get('languageID')) . '/auth-order/';
         }
         $this->view->assign('itemCount', count($allIds));
         $this->view->assign('cartTotal', $cart->getTotalItem());
         $oProduct = new ProductsCollection();
         //            $orderPageId = Cible_FunctionsCategories::getPagePerCategoryView(0, 'order', 17);
         $resume = false;
         if ($this->_registry->pageID == $this->_orderPageId) {
             $resume = true;
         }
         foreach ($allIds as $key => $id) {
             $itemId = $cartData['itemId'][$key];
             $prodId = $cartData['prodId'][$key];
             $productData[$id] = $oProduct->getDetails($prodId, $itemId, $resume);
             $cartDetails = $cart->getItem($id, $itemId);
             if ($resume) {
                 $renderItem = $cart->renderResume($cartDetails, $itemId);
             } else {
                 $renderItem = $cart->renderCartLine($cartDetails, $itemId);
             }
             $productData[$id]['items']['render'] = $renderItem;
             $productData[$id]['cart']['disable'] = $cartDetails['Disable'];
             $productData[$id]['cart']['promoId'] = $cartDetails['PromoId'];
         }
         $hasBonus = $oProduct->getBonus();
         $orderParams = Cible_FunctionsGeneral::getParameters();
         $parameters = array('nbPoint' => 0, 'taxeProv' => $memberData['taxProv'], 'taxeCode' => $memberData['taxCode'], 'tpsFee' => $orderParams['CP_ShippingFees'], 'limitTpsFee' => $orderParams['CP_ShippingFeesLimit'], 'CODFees' => $orderParams['CP_MontantFraisCOD'], 'noProvTax' => $memberData['noProvTax'], 'noFedTax' => $memberData['noFedTax']);
         if ($memberData['taxCode'] == 'QC') {
             $parameters['taxeFed'] = $orderParams['CP_TauxTaxeFed'];
         }
         if ($hasBonus) {
             $parameters['nbPoint'] = $orderParams['CP_BonusPointDollar'];
         }
         $this->view->assign('productData', $productData);
         $this->view->assign('urlBack', $urlBack);
         $this->view->assign('nextStep', $urlNextStep);
         $this->view->assign('step', 1);
         $this->view->assign('hasBonus', $oProduct->getBonus());
         $this->view->assign('parameters', $parameters);
         if ($this->_registry->pageID == $this->_orderPageId) {
             $this->renderScript('index/cart-summary.phtml');
         } else {
             $this->renderScript('index/cart-details.phtml');
         }
     }
 }
 public function change_quantity()
 {
     import('Think.ORG.Cart');
     // 导入购物车类
     $cart = new Cart();
     $itemId = $this->_post('itemId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $spec_id = $this->_post('spec_id', 'intval');
     //购买数量
     $goods_stock = 0;
     $spec_1 = '';
     $spec_2 = '';
     $price = 0;
     $item = M('item')->field('id,title,img,price,goods_stock')->find($itemId);
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     }
     if ($spec_id == 0) {
         $goods_stock = $item['goods_stock'];
         $price = $item['price'];
     } else {
         $item_spec = M('item_spec')->field('spec_1,spec_2,price,stock')->find($spec_id);
         $goods_stock = $item_spec['stock'];
         $price = $item_spec['price'];
         $spec_1 = $item_spec['spec_1'];
         $spec_2 = $item_spec['spec_2'];
     }
     if ($goods_stock < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $cart->modNum($itemId, $spec_id, $quantity);
         $data = array('status' => 1, 'item' => $cart->getItem($itemId, $spec_id), 'sumPrice' => $cart->getPrice());
     }
     echo json_encode($data);
 }
Exemple #6
0
 /**
  * Calculation of taxes and amounts for orders rendrering.
  *
  * @param array $memberInfos
  * @param bool $lines
  *
  * @return array
  */
 public function calculateTotal($memberInfos, $lines = false)
 {
     $session = new Zend_Session_Namespace('order');
     $data = array();
     $oCart = new Cart();
     $oItem = new ItemsObject();
     $oProd = new ProductsCollection();
     $subTotProv = 0;
     $subTotFed = 0;
     $subTot = 0;
     $total = 0;
     $taxProv = 0;
     $taxFed = 0;
     $tmpSum = 0;
     $nbPoint = 0;
     $cartData = $oCart->getAllIds();
     $orderParams = Cible_FunctionsGeneral::getParameters();
     if (!$memberInfos['noFedTax'] && $session->stateId == 11) {
         foreach ($cartData['cartId'] as $key => $id) {
             $itemId = $cartData['itemId'][$key];
             $prodId = $cartData['prodId'][$key];
             $itemDetails = $oItem->getAll(null, true, $itemId);
             $cartDetails = $oCart->getItem($id, $itemId, true);
             if ($itemDetails[0]['I_TaxFed']) {
                 $subTotFed += $cartDetails['Total'];
             }
         }
         $addShipFee = Cible_FunctionsGeneral::compareFloats($subTotFed, '<', $orderParams['CP_ShippingFeesLimit'], 2);
         if ($addShipFee) {
             $subTotFed += $orderParams['CP_ShippingFees'];
         }
         if (isset($session->order['cod'])) {
             $subTotFed += $orderParams['CP_MontantFraisCOD'];
         }
         $taxFed = Cible_FunctionsGeneral::federalTax($subTotFed);
     }
     if (!$memberInfos['noProvTax']) {
         foreach ($cartData['cartId'] as $key => $id) {
             $itemId = $cartData['itemId'][$key];
             $prodId = $cartData['prodId'][$key];
             $itemDetails = $oItem->getAll(null, true, $itemId);
             $cartDetails = $oCart->getItem($id, $itemId, true);
             if ($itemDetails[0]['I_TaxProv']) {
                 $subTotProv += $cartDetails['Total'];
             }
         }
         $addShipFee = Cible_FunctionsGeneral::compareFloats($subTotProv, '<', $orderParams['CP_ShippingFeesLimit'], 2);
         if ($addShipFee) {
             $subTotProv += $orderParams['CP_ShippingFees'];
         }
         if (isset($session->order['cod'])) {
             $subTotProv += $orderParams['CP_MontantFraisCOD'];
         }
         $taxProv = Cible_FunctionsGeneral::provinceTax($subTotProv);
     }
     foreach ($cartData['cartId'] as $key => $id) {
         $itemId = $cartData['itemId'][$key];
         $prodId = $cartData['prodId'][$key];
         $productData = $oProd->getDetails($prodId);
         $cartDetails = $oCart->getItem($id, $itemId, true);
         $subTot += $cartDetails['Total'];
         if ($oProd->getBonus()) {
             $nbPoint += ceil($cartDetails['Total'] * $orderParams['CP_BonusPointDollar']);
         }
     }
     $addShipFee = Cible_FunctionsGeneral::compareFloats($subTot, '<', $orderParams['CP_ShippingFeesLimit'], 2);
     if ($addShipFee) {
         $tmpSum += $orderParams['CP_ShippingFees'];
     }
     if (isset($session->order['cod'])) {
         $tmpSum += $orderParams['CP_MontantFraisCOD'];
     }
     $total = $subTot + $tmpSum + round($taxFed, 2) + round($taxProv, 2);
     $data = array('subTotProv' => $subTotProv, 'subTotFed' => $subTotFed, 'subTot' => $subTot, 'total' => $total, 'taxProv' => $taxProv, 'nbPoint' => $nbPoint, 'taxFed' => $taxFed);
     return $data;
 }