Esempio n. 1
0
 /**
  * Retourne le prix total à payer (prix des produits + taxes 21% + shipping)
  * Sous forme de table ('amount_products', 'amount_tax', 'shipping', 'amount_to_pay')
  * Avec vérification dans le cas ou le prix encodé serait différent du prix du catalog
  * Update le prix si nécessaire
  * @access private
  * @param int id_cart
  * @return array
  */
 public function load_cart_amount($id_cart)
 {
     $amount_to_pay = null;
     $amount_products = '0.00';
     $amount_product_hvat = '0.00';
     $quantity_total = '0';
     $promo_amount = 0;
     $profil_amount = 0;
     $amount_tva = 0;
     $shipping_ttc = 0;
     $impact = array();
     $data_cart = parent::s_cart_items($id_cart);
     $getConfigCart = $this->getConfigData();
     $tva_rate = $this->calculate_tva($id_cart);
     // Formate la TVA
     $tva = 1 + floatval($tva_rate) / 100;
     //$tva = floatval('1.' . sprintf("%.02d", $tva_rate));
     /**
      * --- Cart Amount
      */
     if ($data_cart != null) {
         foreach ($data_cart as $item) {
             $price_catalog = parent::s_catalog_price($item['idcatalog']);
             $price_catalog = $price_catalog['price'];
             $price_item = $item['price_items'];
             $quantity_item = $item['quantity_items'];
             /*if($item['weight'] != null){
                   $weight = ($quantity_item*$item['weight']);
               }else{
                   $weight = '0';
               }*/
             if ($price_item != $price_catalog) {
                 //update et réasigne
                 //parent::u_cart_item_price($item['id_item'],$price_catalog);
                 parent::u_cart_item_price($item['id_item'], $price_item);
                 $price = $price_catalog * $quantity_item;
             } else {
                 $price = $price_item * $quantity_item;
             }
             $amount_products += $price;
             $quantity_total += $quantity_item;
         }
         $amount_product_hvat = floatval($amount_products) / $tva;
         $amount_tva = $amount_tva + round($amount_products - $amount_product_hvat, 2);
     }
     /*
             $member = new plugins_profil_public();
             if(isset($_SESSION['idprofil'])){
                 $profilData = $member->setAccountData($_SESSION['idprofil']);
             }
             if(isset($_SESSION['idprofil'])){
                 $country = $profilData['country'];
             }else{
                 $country = 'BE';
             }
             $shipping = null;
             if(isset($_POST['period_ship'])){
                 $period_ship = $_POST['period_ship'];
             }else{
                 $period_ship = 'day';
             }
     
             $dataShip = $collectionShipping->getItemData($country,$quantity_total,$period_ship);
     
             $shipping = $dataShip['price'];*/
     //$shipping_tva = number_format($dataShip['price']*floatval('0.21'), 2, '.', '');
     //$shipping_ttc = $shipping+$shipping_tva;
     /**
      * --- Cashback system
      */
     if (class_exists('plugins_cashback_public')) {
         $collectionCashback = new plugins_cashback_public();
         if (isset($_POST['v_code'])) {
             $promo_amount = $collectionCashback->selectPromo($_POST['v_code']);
         } else {
             $promo_amount = 0;
         }
         /*if(isset($_POST['profil_cashback'])){
               $setTotalProfil = $collectionCashback->setTotalProfil();
               $profil_amount = $setTotalProfil['sumount'];
           }else{
               $profil_amount = 0;
           }*/
     }
     /**
      * --- Total amount
      */
     $total = $amount_products;
     if ($total <= $promo_amount || $total <= $profil_amount) {
         $amount_to_pay = $total;
     } elseif ($total <= $promo_amount + $profil_amount) {
         $amount_to_pay = $total;
     } else {
         //$amount_to_pay =  $total - $promo_amount - $profil_amount;
         $amount_to_pay = $total - $promo_amount;
     }
     /**
      * --- Pass through active mods and search after cart impact
      */
     if (!empty($this->activeMods)) {
         foreach ($this->activeMods as $name => $mod) {
             if (method_exists($mod, 'cart_impact')) {
                 $impact[$name] = $mod->cart_impact($getConfigCart, $amount_products, $tva);
                 foreach ($impact[$name]['update'] as $var => $upd) {
                     switch ($var) {
                         case 'amount_tva':
                             $amount_tva = $amount_tva + $upd;
                             break;
                         case 'total':
                             $amount_to_pay = $amount_to_pay + $upd;
                             break;
                     }
                 }
                 unset($impact[$name]['update']);
             }
         }
     }
     //$shipping = ($amount_products < $this->free_shipping_amount) ? $this->shipping_price : '0.00';
     /**
      * retourne un tableau de données formatée
      */
     $prices = array('amount_hvat' => number_format($amount_product_hvat, 2, '.', ''), 'amount_products' => number_format($amount_products, 2, '.', ''), 'amount_vat' => number_format($amount_tva, 2, '.', ''), 'tax_rate' => $tva_rate, 'amount_promo' => number_format($promo_amount, 2, '.', ''), 'amount_profil' => number_format($profil_amount, 2, '.', ''), 'amount_to_pay' => number_format($amount_to_pay, 2, '.', ''), 'quantity_total' => $quantity_total, 'shipping_ttc' => $shipping_ttc);
     if (isset($impact) && !empty($impact)) {
         foreach ($impact as $name => $var) {
             $prices = $prices + $var;
         }
     }
     return $prices;
 }