Beispiel #1
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');
         }
     }
 }
Beispiel #2
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;
 }