コード例 #1
0
ファイル: IndexController.php プロジェクト: anunay/stentors
 /**
  * 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;
 }
コード例 #2
0
ファイル: Cart.php プロジェクト: anunay/stentors
 /**
  * Tests if the total of the cart is compliant with promo data to insert product.
  *
  * @param int   $id
  * @param int   $itemId
  * @param array $promo
  *
  * @return void
  */
 private function _testByTotal($promo, $oItem)
 {
     //  Récupérer le total du cart
     $data = $this->getTotalItem();
     //  Si Total sup A champ IP_ConditionAmount
     $gte = (bool) Cible_FunctionsGeneral::compareFloats((double) $data['Subtotal'], '>=', (double) $promo['IP_ConditionAmount']);
     $itemData = $oItem->getAll(null, true, $promo['IP_ItemId']);
     $promo['I_ProductID'] = $itemData[0]['I_ProductID'];
     if ($gte && $promo['IP_NbItem'] == 0 && !$this->alreadyInCart($promo['I_ProductID'], $promo['IP_ItemId'], $promo['IP_ID'])) {
         //  Ajouter dans la table CartItems
         $this->_insertPromo($promo);
     } elseif (!$gte) {
         $this->_db->delete('CartItems', array("CI_PromoId = {$promo['IP_ID']}", 'CI_Disable != 1'));
     }
 }
コード例 #3
0
ファイル: ItemsObject.php プロジェクト: anunay/stentors
 /**
  * Calculate the items price before tax.
  * 
  * @param int $quantity Number of items to calculate.
  *
  * @return float
  */
 public function getPrice($quantity = 0, $unitPrice = false)
 {
     $amount = (double) 0;
     $specialPrice = (double) 0;
     $tmp = $this->getAll(null, true, $this->_id);
     $item = $tmp[0];
     $special = $item['I_Special'];
     $amount = $item['I_PricePro'] * $quantity;
     if ($quantity <= $item['I_LimitVol1']) {
         $amount = $item['I_PriceVol1'] * $quantity;
     } elseif ($quantity > $item['I_LimitVol1'] && $quantity <= $item['I_LimitVol2']) {
         $amount = $item['I_PriceVol2'] * $quantity;
     } elseif ($quantity > $item['I_LimitVol2']) {
         $amount = $item['I_PriceVol3'] * $quantity;
     }
     if ($special) {
         $specialPrice = $quantity * $item['I_PrixSpecial'];
         $isBigger = Cible_FunctionsGeneral::compareFloats($amount, '>', $specialPrice);
         if ($isBigger) {
             $amount = $specialPrice;
         }
     }
     if ($unitPrice) {
         $amount = $amount / $quantity;
     }
     return $amount;
 }