function calc_schg()
 {
     global $order;
     if (MODULE_PAYMENT_BILLSAFE_2_SCHG != '') {
         $schg_tax_rate = xtc_get_tax_rate(MODULE_PAYMENT_BILLSAFE_2_SCHGTAX);
         $schg_tax_name = xtc_get_tax_description(MODULE_PAYMENT_BILLSAFE_2_SCHGTAX);
         if (stristr(MODULE_PAYMENT_BILLSAFE_2_SCHG, '%')) {
             $schg_amount = $this->amount * MODULE_PAYMENT_BILLSAFE_2_SCHG / 100;
             $schg_amount_calc = $this->amount * MODULE_PAYMENT_BILLSAFE_2_SCHG / 100;
         } else {
             $schg_amount = MODULE_PAYMENT_BILLSAFE_2_SCHG;
             $schg_amount_calc = MODULE_PAYMENT_BILLSAFE_2_SCHG;
         }
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
             $schg_tax = $schg_amount_calc * $schg_tax_rate / 100;
         } elseif ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) {
             $schg_tax = 0;
         } else {
             $schg_tax = $schg_amount_calc - $schg_amount_calc / (1 + $schg_tax_rate / 100);
         }
     } else {
         $schg_amount = 0;
         $schg_tax = 0;
     }
     if ($schg_tax_rate && $schg_tax > 0) {
         reset($order->info['tax_groups']);
         while (list($key, $value) = each($order->info['tax_groups'])) {
             if (strpos($key, $schg_tax_rate . '%')) {
                 $order->info['tax_groups'][$key] += $schg_tax;
             }
         }
     }
     $this->schg['amount'] = $schg_amount;
     $this->schg['tax'] = $schg_tax;
 }
 function process()
 {
     global $order, $xtPrice;
     //include needed functions
     require_once DIR_FS_INC . 'xtc_calculate_tax.inc.php';
     if (MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE == 'true') {
         switch (MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) {
             $tax = xtc_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_description = xtc_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
                 $order->info['tax'] += xtc_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['tax_groups'][TAX_ADD_TAX . "{$tax_description}"] += xtc_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['total'] += MODULE_ORDER_TOTAL_LOWORDERFEE_FEE + xtc_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $low_order_fee = xtc_add_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $low_order_fee = MODULE_ORDER_TOTAL_LOWORDERFEE_FEE;
                 $order->info['tax'] += xtc_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['tax_groups'][TAX_NO_TAX . "{$tax_description}"] += xtc_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['subtotal'] += $low_order_fee;
                 $order->info['total'] += $low_order_fee;
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] != 1) {
                 $low_order_fee = MODULE_ORDER_TOTAL_LOWORDERFEE_FEE;
                 $order->info['subtotal'] += $low_order_fee;
                 $order->info['total'] += $low_order_fee;
             }
             $this->output[] = array('title' => $this->title . ':', 'text' => $xtPrice->xtcFormat($low_order_fee, true), 'value' => $low_order_fee);
         }
     }
 }
Example #3
0
 function selection()
 {
     global $xtPrice, $order;
     if (MODULE_ORDER_TOTAL_COD_FEE_STATUS == 'true') {
         $cod_country = false;
         //process installed shipping modules
         // BOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
         if ($_SESSION['shipping']['id'] == 'flat_flat') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FLAT);
         }
         if ($_SESSION['shipping']['id'] == 'item_item') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ITEM);
         }
         if ($_SESSION['shipping']['id'] == 'table_table') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_TABLE);
         }
         if ($_SESSION['shipping']['id'] == 'zones_zones') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ZONES);
         }
         if ($_SESSION['shipping']['id'] == 'ap_ap') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_AP);
         }
         if ($_SESSION['shipping']['id'] == 'dp_dp') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DP);
         }
         if ($_SESSION['shipping']['id'] == 'chp_ECO') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
         }
         if ($_SESSION['shipping']['id'] == 'chp_PRI') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
         }
         if ($_SESSION['shipping']['id'] == 'chp_URG') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
         }
         if ($_SESSION['shipping']['id'] == 'chronopost_chronopost') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHRONOPOST);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_ECX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_DOX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_SDX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_MDX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_WPX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'ups_ups') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPS);
         }
         if ($_SESSION['shipping']['id'] == 'upse_upse') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPSE);
         }
         if ($_SESSION['shipping']['id'] == 'free_free') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREE);
         }
         if ($_SESSION['shipping']['id'] == 'freeamount_freeamount') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_FREEAMOUNT_FREE);
         }
         // EOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
         for ($i = 0; $i < count($cod_zones); $i++) {
             if ($cod_zones[$i] == $order->delivery['country']['iso_code_2']) {
                 $cod_cost = $cod_zones[$i + 1];
                 $cod_country = true;
                 break;
             } elseif ($cod_zones[$i] == '00') {
                 $cod_cost = $cod_zones[$i + 1];
                 $cod_country = true;
                 break;
             } else {
             }
             $i++;
         }
     } else {
         //COD selected, but no shipping module which offers COD
     }
     if ($cod_country) {
         $cod_tax = xtc_get_tax_rate(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
         $cod_tax_description = xtc_get_tax_description(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
             $cod_cost_value = xtc_add_tax($cod_cost, $cod_tax);
             $cod_cost = $xtPrice->xtcFormat($cod_cost_value, true);
         }
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
             $cod_cost_value = $cod_cost;
             $cod_cost = $xtPrice->xtcFormat($cod_cost, true);
         }
         if (!$cod_cost_value) {
             $cod_cost_value = $cod_cost;
             $cod_cost = $xtPrice->xtcFormat($cod_cost, true);
         }
         $this->cost = '+ ' . $cod_cost;
     }
     return array('id' => $this->code, 'module' => $this->title, 'description' => $this->info, 'module_cost' => $this->cost);
 }
Example #4
0
 function cart()
 {
     global $currencies, $xtPrice;
     $this->content_type = $_SESSION['cart']->get_content_type();
     $customer_address_query = xtc_db_query("select c.payment_unallowed,c.shipping_unallowed,c.customers_firstname,c.customers_cid, c.customers_gender,c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id) where c.customers_id = '" . $_SESSION['customer_id'] . "' and ab.customers_id = '" . $_SESSION['customer_id'] . "' and c.customers_default_address_id = ab.address_book_id");
     $customer_address = xtc_db_fetch_array($customer_address_query);
     $shipping_address_query = xtc_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . $_SESSION['customer_id'] . "' and ab.address_book_id = '" . $_SESSION['sendto'] . "'");
     $shipping_address = xtc_db_fetch_array($shipping_address_query);
     $billing_address_query = xtc_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . $_SESSION['customer_id'] . "' and ab.address_book_id = '" . $_SESSION['billto'] . "'");
     $billing_address = xtc_db_fetch_array($billing_address_query);
     $tax_address_query = xtc_db_query("select ab.entry_country_id, ab.entry_zone_id from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = '" . $_SESSION['customer_id'] . "' and ab.address_book_id = '" . ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'");
     $tax_address = xtc_db_fetch_array($tax_address_query);
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $xtPrice->currencies[$_SESSION['currency']]['value'], 'payment_method' => $_SESSION['payment'], 'cc_type' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_type']) ? $_SESSION['ccard']['cc_type'] : '', 'cc_owner' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_owner']) ? $_SESSION['ccard']['cc_owner'] : '', 'cc_number' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_number']) ? $_SESSION['ccard']['cc_number'] : '', 'cc_expires' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_expires']) ? $_SESSION['ccard']['cc_expires'] : '', 'cc_start' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_start']) ? $_SESSION['ccard']['cc_start'] : '', 'cc_issue' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_issue']) ? $_SESSION['ccard']['cc_issue'] : '', 'cc_cvv' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_cvv']) ? $_SESSION['ccard']['cc_cvv'] : '', 'shipping_method' => $_SESSION['shipping']['title'], 'shipping_cost' => $_SESSION['shipping']['cost'], 'comments' => $_SESSION['comments'], 'shipping_class' => $_SESSION['shipping']['id'], 'payment_class' => $_SESSION['payment']);
     if (isset($_SESSION['payment']) && is_object($_SESSION['payment'])) {
         $this->info['payment_method'] = $_SESSION['payment']->title;
         $this->info['payment_class'] = $_SESSION['payment']->title;
         if (isset($_SESSION['payment']->order_status) && is_numeric($_SESSION['payment']->order_status) && $_SESSION['payment']->order_status > 0) {
             $this->info['order_status'] = $_SESSION['payment']->order_status;
         }
     }
     $this->customer = array('firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'csID' => $customer_address['customers_cid'], 'gender' => $customer_address['customers_gender'], 'company' => $customer_address['entry_company'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => xtc_not_null($customer_address['entry_state']) ? $customer_address['entry_state'] : $customer_address['zone_name'], 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['customers_telephone'], 'payment_unallowed' => $customer_address['payment_unallowed'], 'shipping_unallowed' => $customer_address['shipping_unallowed'], 'email_address' => $customer_address['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'company' => $shipping_address['entry_company'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => xtc_not_null($shipping_address['entry_state']) ? $shipping_address['entry_state'] : $shipping_address['zone_name'], 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'format_id' => $shipping_address['address_format_id']);
     $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'company' => $billing_address['entry_company'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => xtc_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'zone_id' => $billing_address['entry_zone_id'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']), 'country_id' => $billing_address['entry_country_id'], 'format_id' => $billing_address['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         $products_price = $xtPrice->xtcGetPrice($products[$i]['id'], $format = false, $products[$i]['quantity'], $products[$i]['tax_class_id'], '') + $xtPrice->xtcFormat($_SESSION['cart']->attributes_price($products[$i]['id']), false);
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax_class_id' => $products[$i]['tax_class_id'], 'tax' => xtc_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => xtc_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'price' => $products_price, 'final_price' => $products_price * $products[$i]['quantity'], 'shipping_time' => $products[$i]['shipping_time'], 'weight' => $products[$i]['weight'], 'id' => $products[$i]['id']);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 $attributes_query = xtc_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $products[$i]['id'] . "' and pa.options_id = '" . $option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'");
                 $attributes = xtc_db_fetch_array($attributes_query);
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'], 'value' => $attributes['products_options_values_name'], 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']);
                 $subindex++;
             }
         }
         $shown_price = $this->products[$index]['final_price'];
         $this->info['subtotal'] += $shown_price;
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
             $shown_price_tax = $shown_price - $shown_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
         }
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '1') {
             if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                 $this->info['tax'] += $shown_price_tax - $shown_price_tax / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                 $this->info['tax_groups'][TAX_ADD_TAX . "{$products_tax_description}"] += $shown_price_tax / (100 + $products_tax) * $products_tax;
             } else {
                 $this->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                 $this->info['tax_groups'][TAX_ADD_TAX . "{$products_tax_description}"] += $shown_price / (100 + $products_tax) * $products_tax;
             }
         } else {
             if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                 $this->info['tax'] += $shown_price_tax / 100 * $products_tax;
                 $this->info['tax_groups'][TAX_NO_TAX . "{$products_tax_description}"] += $shown_price_tax / 100 * $products_tax;
             } else {
                 $this->info['tax'] += $shown_price / 100 * $products_tax;
                 $this->info['tax_groups'][TAX_NO_TAX . "{$products_tax_description}"] += $shown_price / 100 * $products_tax;
             }
         }
         $index++;
     }
     //$this->info['shipping_cost']=0;
     if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
         $this->info['total'] = $this->info['subtotal'] + $xtPrice->xtcFormat($this->info['shipping_cost'], false, 0, true);
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1') {
             $this->info['total'] -= $this->info['subtotal'] / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
         }
     } else {
         $this->info['total'] = $this->info['subtotal'] + $xtPrice->xtcFormat($this->info['shipping_cost'], false, 0, true);
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1') {
             $this->info['total'] -= $this->info['subtotal'] / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
         }
     }
 }
Example #5
0
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $order;
     switch ($method) {
         case 'Standard':
             $ratio1 = number_format($od_amount / $amount, 2);
             $tod_amount = 0;
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = xtc_get_tax_rate_from_desc($key);
                 $total_net += $tax_rate * $order->info['tax_groups'][$key];
             }
             if ($od_amount > $total_net) {
                 $od_amount = $total_net;
             }
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = xtc_get_tax_rate_from_desc($key);
                 $net = $tax_rate * $order->info['tax_groups'][$key];
                 if ($net > 0) {
                     $god_amount = $order->info['tax_groups'][$key] * $ratio1;
                     $tod_amount += $god_amount;
                     $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                 }
             }
             $order->info['tax'] -= $tod_amount;
             $order->info['total'] -= $tod_amount;
             break;
         case 'Credit Note':
             $tax_rate = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_desc = xtc_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate;
             $order->info['tax_groups'][$tax_desc] -= $tod_amount;
             //          $order->info['total'] -= $tod_amount;   //// ????? Strider
             break;
         default:
     }
     return $tod_amount;
 }
 function process()
 {
     global $order, $xtPrice, $free_shipping, $free_shipping_value_over;
     if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 $free_shipping_value_over = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER;
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 $free_shipping_value_over = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER_INTERNATIONAL;
                 break;
             case 'both':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $free_shipping_value_over = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER;
                 } else {
                     $free_shipping_value_over = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER_INTERNATIONAL;
                 }
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $xtPrice->xtcRemoveCurr($order->info['total'] - $order->info['shipping_cost']) >= $free_shipping_value_over) {
             $order->info['shipping_method'] = $this->title;
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
             $free_shipping = true;
         }
     }
     if (!isset($_SESSION['shipping'])) {
         return;
     }
     $module = substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_'));
     if (xtc_not_null($order->info['shipping_method']) && isset($GLOBALS[$module]) && is_object($GLOBALS[$module])) {
         $tax = 0;
         $shipping_tax = 0;
         $shipping_tax_description = '';
         $shipping_tax = xtc_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
         $shipping_tax_description = xtc_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
         $tax = xtc_add_tax($order->info['shipping_cost'], $shipping_tax) - $order->info['shipping_cost'];
         $tax = $xtPrice->xtcFormat($tax, false, 0, true);
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
             // price with tax
             $order->info['shipping_cost'] = xtc_add_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax'] += $tax;
             $order->info['tax_groups'][TAX_ADD_TAX . "{$shipping_tax_description}"] += $tax;
             $order->info['total'] += $tax;
         } else {
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $order->info['tax'] = $order->info['tax'] += $tax;
                 $order->info['tax_groups'][TAX_NO_TAX . "{$shipping_tax_description}"] = $order->info['tax_groups'][TAX_NO_TAX . "{$shipping_tax_description}"] += $tax;
             }
         }
         $this->output[] = array('title' => $order->info['shipping_method'] . ':', 'text' => $xtPrice->xtcFormat($order->info['shipping_cost'], true, 0, true), 'value' => $xtPrice->xtcFormat($order->info['shipping_cost'], false, 0, true));
     }
 }
 /**
  * Calculate the invoice fee and add the invoice fee tax to the order total
  * if it has one.
  *
  * @return float
  */
 public function calculateInvoiceFee()
 {
     global $order;
     $payment = $_SESSION['payment'];
     $customer_zone_id = $_SESSION['customer_zone_id'];
     $customer_country_id = $_SESSION['customer_country_id'];
     $currency = $_SESSION['currency'];
     if ($payment !== "klarna_invoice") {
         return 0;
     }
     $fee = $this->_utils->getInvoiceFee();
     if ($fee === 0 || MODULE_KLARNA_FEE_TAX_CLASS <= 0) {
         return $fee;
     }
     $showTax = KlarnaConstant::showPriceTax();
     $feeTax = 0;
     $rate = xtc_get_tax_rate(MODULE_KLARNA_FEE_TAX_CLASS);
     $feeExclTax = $fee / ($rate / 100 + 1);
     $feeTax = $fee - $feeExclTax;
     $tax_desc_prefix = "";
     if ($showTax === true) {
         $tax_desc_prefix = TAX_ADD_TAX;
     } else {
         if (KlarnaConstant::addTaxOT() === true) {
             $tax_desc_prefix = TAX_NO_TAX;
         }
     }
     $tax_desc = xtc_get_tax_description(MODULE_KLARNA_FEE_TAX_CLASS, $customer_country_id, $customer_zone_id);
     $order->info['tax_groups'][$tax_desc_prefix . $tax_desc] += $feeTax;
     $order->info['tax'] += $feeTax;
     return $showTax === true ? $fee : $feeExclTax;
 }
 function process()
 {
     global $order, $xtPrice, $cod_cost, $cod_country, $shipping;
     if (MODULE_ORDER_TOTAL_COD_FEE_STATUS == 'true') {
         //Will become true, if cod can be processed.
         $cod_country = false;
         //check if payment method is cod. If yes, check if cod is possible.
         if ($_SESSION['payment'] == 'cod') {
             //process installed shipping modules
             // BOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
             if ($_SESSION['shipping']['id'] == 'flat_flat') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FLAT);
             }
             if ($_SESSION['shipping']['id'] == 'item_item') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ITEM);
             }
             if ($_SESSION['shipping']['id'] == 'table_table') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_TABLE);
             }
             if ($_SESSION['shipping']['id'] == 'zones_zones') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ZONES);
             }
             if ($_SESSION['shipping']['id'] == 'ap_ap') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_AP);
             }
             if ($_SESSION['shipping']['id'] == 'dp_dp') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DP);
             }
             // module chp
             if ($_SESSION['shipping']['id'] == 'chp_ECO') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
             }
             if ($_SESSION['shipping']['id'] == 'chp_PRI') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
             }
             if ($_SESSION['shipping']['id'] == 'chp_URG') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
             }
             // module chronopost
             if ($_SESSION['shipping']['id'] == 'chronopost_chronopost') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHRONOPOST);
             }
             // module DHL
             if ($_SESSION['shipping']['id'] == 'dhl_ECX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_DOX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_SDX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_MDX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_WPX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             // UPS
             if ($_SESSION['shipping']['id'] == 'ups_ups') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPS);
             }
             if ($_SESSION['shipping']['id'] == 'upse_upse') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPSE);
             }
             // Free Shipping
             if ($_SESSION['shipping']['id'] == 'free_free') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREE);
             }
             if ($_SESSION['shipping']['id'] == 'freeamount_freeamount') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_FREEAMOUNT_FREE);
             }
             // EOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
             for ($i = 0; $i < count($cod_zones); $i++) {
                 if ($cod_zones[$i] == $order->delivery['country']['iso_code_2']) {
                     $cod_cost = $cod_zones[$i + 1];
                     $cod_country = true;
                     break;
                 } elseif ($cod_zones[$i] == '00') {
                     $cod_cost = $cod_zones[$i + 1];
                     $cod_country = true;
                     break;
                 } else {
                 }
                 $i++;
             }
         } else {
             //COD selected, but no shipping module which offers COD
         }
         if ($cod_country) {
             $cod_tax = xtc_get_tax_rate(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $cod_tax_description = xtc_get_tax_description(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
                 $order->info['tax'] += xtc_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $order->info['tax_groups'][TAX_ADD_TAX . "{$cod_tax_description}"] += xtc_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $order->info['total'] += $cod_cost + (xtc_add_tax($cod_cost, $cod_tax) - $cod_cost);
                 $cod_cost_value = xtc_add_tax($cod_cost, $cod_tax);
                 $cod_cost = $xtPrice->xtcFormat($cod_cost_value, true);
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $order->info['tax'] += xtc_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $order->info['tax_groups'][TAX_NO_TAX . "{$cod_tax_description}"] += xtc_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $cod_cost_value = $cod_cost;
                 $cod_cost = $xtPrice->xtcFormat($cod_cost, true);
                 $order->info['subtotal'] += $cod_cost_value;
                 $order->info['total'] += $cod_cost_value;
             }
             if (!$cod_cost_value) {
                 $cod_cost_value = $cod_cost;
                 $cod_cost = $xtPrice->xtcFormat($cod_cost, true);
                 $order->info['total'] += $cod_cost_value;
             }
             $this->output[] = array('title' => $this->title . ':', 'text' => $cod_cost, 'value' => $cod_cost_value);
         } else {
             //Following code should be improved if we can't get the shipping modules disabled, who don't allow COD
             // as well as countries who do not have cod
             //          $this->output[] = array('title' => $this->title . ':',
             //                                  'text' => 'No COD for this module.',
             //                                  'value' => '');
         }
     }
 }
 function process()
 {
     global $order, $xtPrice, $ps_cost, $ps_country, $shipping;
     $customer_id = $_SESSION['customer_id'];
     if (MODULE_ORDER_TOTAL_PS_FEE_STATUS == 'true') {
         //Will become true, if ps can be processed.
         $ps_country = false;
         //check if payment method is ps. If yes, check if ps is possible.
         $count_query = xtc_db_query("select count(*) as count from " . TABLE_CUSTOMERS_BASKET . " cb, " . TABLE_PRODUCTS . " p  where cb.customers_id = '" . $customer_id . "' and cb.products_id = p.products_id and p.products_fsk18 = '1'");
         $num = xtc_db_fetch_array($count_query);
         $age = $num['count'];
         if ($age > '0') {
             //process installed shipping modules
             // BOF -  Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
             if ($_SESSION['shipping']['id'] == 'flat_flat') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_FLAT);
             }
             if ($_SESSION['shipping']['id'] == 'item_item') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_ITEM);
             }
             if ($_SESSION['shipping']['id'] == 'table_table') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_TABLE);
             }
             if ($_SESSION['shipping']['id'] == 'zones_zones') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_ZONES);
             }
             if ($_SESSION['shipping']['id'] == 'ap_ap') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_AP);
             }
             if ($_SESSION['shipping']['id'] == 'dp_dp') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_DP);
             }
             // EOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
             for ($i = 0; $i < count($ps_zones); $i++) {
                 if ($ps_zones[$i] == $order->billing['country']['iso_code_2']) {
                     $ps_cost = $ps_zones[$i + 1];
                     $ps_country = true;
                     //print('match' . $ps_zones[$i] . ': ' . $ps_cost);
                     break;
                 } elseif ($ps_zones[$i] == '00') {
                     $ps_cost = $ps_zones[$i + 1];
                     $ps_country = true;
                     //print('match' . $i . ': ' . $ps_cost);
                     break;
                 } else {
                     //print('no match');
                 }
                 $i++;
             }
         } else {
             //PS selected, but no shipping module which offers PS
         }
         if ($ps_country) {
             $ps_tax = xtc_get_tax_rate(MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $ps_tax_description = xtc_get_tax_description(MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
                 $order->info['tax'] += xtc_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $order->info['tax_groups'][TAX_ADD_TAX . "{$ps_tax_description}"] += xtc_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $order->info['total'] += $ps_cost + (xtc_add_tax($ps_cost, $ps_tax) - $ps_cost);
                 $ps_cost_value = xtc_add_tax($ps_cost, $ps_tax);
                 $ps_cost = $xtPrice->xtcFormat($ps_cost_value, true);
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $order->info['tax'] += xtc_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $order->info['tax_groups'][TAX_NO_TAX . "{$ps_tax_description}"] += xtc_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $ps_cost_value = $ps_cost;
                 $ps_cost = $xtPrice->xtcFormat($ps_cost, true);
                 $order->info['subtotal'] += $ps_cost_value;
                 $order->info['total'] += $ps_cost_value;
             }
             if (!$ps_cost_value) {
                 $ps_cost_value = $ps_cost;
                 $ps_cost = $xtPrice->xtcFormat($ps_cost, true);
                 $order->info['total'] += $ps_cost_value;
             }
             $this->output[] = array('title' => $this->title . ':', 'text' => $ps_cost, 'value' => $ps_cost_value);
         } else {
             //Following pse should be improved if we can't get the shipping modules disabled, who don't allow PS
             // as well as countries who do not have ps
             //          $this->output[] = array('title' => $this->title . ':',
             //                                  'text' => 'No PS for this module.',
             //                                  'value' => '');
         }
     }
 }
Example #10
0
 function cart()
 {
     global $currencies, $xtPrice, $main;
     $this->content_type = $_SESSION['cart']->get_content_type();
     $default_select = "ab.entry_company, ab.entry_street_address, ab.entry_suburb,\n         ab.entry_postcode, ab.entry_city, ab.entry_zone_id, ab.entry_country_id, ab.entry_state,\n         co.countries_name,\n         co.countries_id, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id,\n         z.zone_name\n        ";
     $default_join = "LEFT JOIN " . TABLE_ZONES . " z ON (ab.entry_zone_id = z.zone_id)\n         LEFT JOIN " . TABLE_COUNTRIES . " co ON (ab.entry_country_id = co.countries_id)         \n        ";
     $customer_address_query = xtc_db_query("SELECT c.payment_unallowed, c.shipping_unallowed, c.customers_firstname,\n                                                     c.customers_cid, c.customers_gender, c.customers_lastname,\n                                                     c.customers_telephone, c.customers_email_address,\n                                                     " . $default_select . "\n                                                FROM " . TABLE_CUSTOMERS . " c\n                                           LEFT JOIN " . TABLE_ADDRESS_BOOK . " ab ON (ab.customers_id = '" . $_SESSION['customer_id'] . "' AND c.customers_default_address_id = ab.address_book_id)\n                                                     " . $default_join . "\n                                               WHERE c.customers_id = '" . $_SESSION['customer_id'] . "'\n                                            ");
     $customer_address = xtc_db_fetch_array($customer_address_query);
     $shipping_address_query = xtc_db_query("SELECT ab.entry_firstname, ab.entry_lastname,\n                                                     " . $default_select . "\n                                                FROM " . TABLE_ADDRESS_BOOK . " ab\n                                                     " . $default_join . "\n                                               WHERE ab.customers_id = '" . $_SESSION['customer_id'] . "'\n                                                 AND ab.address_book_id = '" . $_SESSION['sendto'] . "'\n                                            ");
     $shipping_address = xtc_db_fetch_array($shipping_address_query);
     $billing_address_query = xtc_db_query("SELECT ab.entry_firstname, ab.entry_lastname,\n                                                    " . $default_select . "\n                                               FROM " . TABLE_ADDRESS_BOOK . " ab\n                                                    " . $default_join . "\n                                              WHERE ab.customers_id = '" . $_SESSION['customer_id'] . "'\n                                                AND ab.address_book_id = '" . (isset($_SESSION['billto']) ? $_SESSION['billto'] : $_SESSION['sendto']) . "'\n                                           ");
     $billing_address = xtc_db_fetch_array($billing_address_query);
     $tax_address_query = xtc_db_query("SELECT ab.entry_country_id, ab.entry_zone_id\n                                           FROM " . TABLE_ADDRESS_BOOK . " ab\n                                      LEFT JOIN " . TABLE_ZONES . " z ON (ab.entry_zone_id = z.zone_id)\n                                          WHERE ab.customers_id = '" . $_SESSION['customer_id'] . "'\n                                            AND ab.address_book_id = '" . ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'\n                                       ");
     $tax_address = xtc_db_fetch_array($tax_address_query);
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $xtPrice->currencies[$_SESSION['currency']]['value'], 'payment_method' => isset($_SESSION['payment']) ? $_SESSION['payment'] : '', 'shipping_method' => isset($_SESSION['shipping']) && is_array($_SESSION['shipping']) ? $_SESSION['shipping']['title'] : '', 'shipping_cost' => isset($_SESSION['shipping']) && is_array($_SESSION['shipping']) ? $_SESSION['shipping']['cost'] : '', 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'shipping_class' => isset($_SESSION['shipping']) && is_array($_SESSION['shipping']) ? $_SESSION['shipping']['id'] : '', 'payment_class' => isset($_SESSION['payment']) ? $_SESSION['payment'] : '', 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array());
     if (isset($_SESSION['payment']) && is_object($_SESSION['payment'])) {
         $this->info['payment_method'] = $_SESSION['payment']->title;
         $this->info['payment_class'] = $_SESSION['payment']->title;
         if (isset($_SESSION['payment']->order_status) && is_numeric($_SESSION['payment']->order_status) && $_SESSION['payment']->order_status > 0) {
             $this->info['order_status'] = $_SESSION['payment']->order_status;
         }
     }
     $this->customer = array('firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'csID' => $customer_address['customers_cid'], 'gender' => $customer_address['customers_gender'], 'company' => $customer_address['entry_company'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => xtc_not_null($customer_address['entry_state']) ? $customer_address['entry_state'] : $customer_address['zone_name'], 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['customers_telephone'], 'payment_unallowed' => $customer_address['payment_unallowed'], 'shipping_unallowed' => $customer_address['shipping_unallowed'], 'email_address' => $customer_address['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'company' => $shipping_address['entry_company'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => xtc_not_null($shipping_address['entry_state']) ? $shipping_address['entry_state'] : $shipping_address['zone_name'], 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'format_id' => $shipping_address['address_format_id']);
     $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'company' => $billing_address['entry_company'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => xtc_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'zone_id' => $billing_address['entry_zone_id'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']), 'country_id' => $billing_address['entry_country_id'], 'format_id' => $billing_address['address_format_id']);
     $index = 0;
     $download_index = 0;
     $goods_index = 0;
     // BOF - web28 - 2010-05-06 - PayPal API Modul / Paypal Express Modul
     $this->tax_discount = array();
     // EOF - web28 - 2010-05-06 - PayPal API Modul / Paypal Express Modul
     $products = $_SESSION['cart']->get_products();
     //set in includes/classes/shopping_cart-php function get_products
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         $products_price = $xtPrice->xtcGetPrice($products[$i]['id'], $format = false, $products[$i]['quantity'], $products[$i]['tax_class_id'], '') + $xtPrice->xtcFormat($_SESSION['cart']->attributes_price($products[$i]['id']), false);
         //using short description  if order description is not defined or empty
         $products[$i]['short_description'] = CHECKOUT_USE_PRODUCTS_SHORT_DESCRIPTION == 'true' ? $products[$i]['short_description'] : '';
         $products[$i]['order_description'] = !empty($products[$i]['order_description']) ? nl2br($products[$i]['order_description']) : $products[$i]['short_description'];
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'short_description' => $products[$i]['short_description'], 'order_description' => $products[$i]['order_description'], 'image' => !empty($products[$i]['image']) ? $main->getProductPopupLink($products[$i]['id'], $products[$i]['image'], 'image') : '&nbsp;', 'link' => $main->getProductPopupLink($products[$i]['id'], $products[$i]['name'], 'details'), 'tax_class_id' => $products[$i]['tax_class_id'], 'tax' => xtc_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => xtc_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'price' => $xtPrice->xtcFormat($products_price, false), 'price_formated' => $xtPrice->xtcFormat($products_price, true), 'final_price' => $xtPrice->xtcFormat($products_price * $products[$i]['quantity'], false), 'final_price_formated' => $xtPrice->xtcFormat($products_price * $products[$i]['quantity'], true), 'vpe' => $products[$i]['vpe'], 'shipping_time' => $products[$i]['shipping_time'], 'weight' => $products[$i]['weight'], 'id' => $products[$i]['id']);
         $download_flag = 0;
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 $attributes = $main->getAttributes($products[$i]['id'], $option, $value);
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'], 'value' => $attributes['products_options_values_name'], 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price'], 'price_formated' => $xtPrice->xtcFormat($attributes['options_values_price'], true));
                 //if ($attributes['products_options_name'] == 'Downloads') {
                 if (strtoupper($attributes['products_options_name']) == 'DOWNLOADS') {
                     $download_flag = 1;
                 }
                 $subindex++;
             }
             if ($download_flag == 1) {
                 $this->downloads[$download_index] = $this->products[$index];
                 $download_index++;
             }
         }
         if ($download_flag == 0) {
             $this->goods[$goods_index] = $this->products[$index];
             $goods_index++;
         }
         $shown_price = $this->products[$index]['final_price'];
         $this->info['subtotal'] += $shown_price;
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
             $shown_price_tax = $shown_price - $xtPrice->xtcFormat($shown_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'], false);
         }
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '1') {
             $tax_index = TAX_ADD_TAX . $products_tax_description;
             if (!isset($this->info['tax_groups'][$tax_index])) {
                 $this->info['tax_groups'][$tax_index] = 0;
             }
             if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                 $this->info['tax'] += $xtPrice->xtcFormat($shown_price_tax - $shown_price_tax / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)), false);
                 $this->info['tax_groups'][$tax_index] += $xtPrice->xtcFormat($shown_price_tax / (100 + $products_tax) * $products_tax, false);
             } else {
                 $this->info['tax'] += $xtPrice->xtcFormat($shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)), false);
                 $this->info['tax_groups'][$tax_index] += $xtPrice->xtcFormat($shown_price / (100 + $products_tax) * $products_tax, false);
             }
         } else {
             $tax_index = TAX_NO_TAX . $products_tax_description;
             if (!isset($this->info['tax_groups'][$tax_index])) {
                 $this->info['tax_groups'][$tax_index] = 0;
             }
             if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                 $this->tax_discount[$products[$i]['tax_class_id']] += $xtPrice->xtcFormat($shown_price_tax / 100 * $products_tax, false);
                 $this->info['tax_groups'][$tax_index] += $xtPrice->xtcFormat($shown_price_tax / 100 * $products_tax, false);
             } else {
                 $this->info['tax'] += $xtPrice->xtcFormat($shown_price / 100 * $products_tax, false);
                 $this->info['tax_groups'][$tax_index] += $xtPrice->xtcFormat($shown_price / 100 * $products_tax, false);
             }
         }
         $index++;
     }
     // BOF - web28 - 2010-05-06 - PayPal API Modul / Paypal Express Modul
     foreach ($this->tax_discount as $value) {
         $this->info['tax'] += $xtPrice->xtcFormat($value, false);
     }
     // EOF - web28 - 2010-05-06 - PayPal API Modul / Paypal Express Modul
     //$this->info['shipping_cost']=0;
     if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
         $this->info['total'] = $this->info['subtotal'] + $xtPrice->xtcFormat($this->info['shipping_cost'], false, 0, true);
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1') {
             $this->info['total'] -= $xtPrice->xtcFormat($this->info['subtotal'] / 100 * $_SESSION['customers_status']['customers_status_ot_discount'], false);
         }
     } else {
         $this->info['total'] = $this->info['subtotal'] + $xtPrice->xtcFormat($this->info['shipping_cost'], false, 0, true);
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1') {
             $this->info['total'] -= $xtPrice->xtcFormat($this->info['subtotal'] / 100 * $_SESSION['customers_status']['customers_status_ot_discount'], false);
         }
     }
 }
 /**
  * calculate cart totals
  *
  * @return unknown
  */
 function calculate()
 {
     global $xtPrice;
     $this->total = 0;
     $this->weight = 0;
     $this->tax = array();
     $this->tax_discount = array();
     //Tomcraft - 2011-02-01 - Paypal Express Modul
     if (!is_array($this->contents)) {
         return 0;
     }
     reset($this->contents);
     while (list($products_id) = each($this->contents)) {
         $qty = $this->contents[$products_id]['qty'];
         // products price
         $product_query = xtc_db_query("select products_id,\n                                            products_price,\n                                            products_discount_allowed,\n                                            products_tax_class_id,\n                                            products_weight\n                                       from " . TABLE_PRODUCTS . "\n                                      where products_id='" . xtc_get_prid($products_id) . "'");
         if ($product = xtc_db_fetch_array($product_query)) {
             $products_price = $xtPrice->xtcGetPrice($product['products_id'], $format = false, $qty, $product['products_tax_class_id'], $product['products_price']);
             $this->total += $products_price * $qty;
             $this->weight += $qty * $product['products_weight'];
             //attributes price
             $attribute_price = 0;
             if (isset($this->contents[$products_id]['attributes'])) {
                 reset($this->contents[$products_id]['attributes']);
                 while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                     $values = $xtPrice->xtcGetOptionPrice($product['products_id'], $option, $value);
                     $this->weight += $values['weight'] * $qty;
                     $this->total += $values['price'] * $qty;
                     $attribute_price += $values['price'];
                 }
             }
             // $this->total hat netto * Stück in der 1. Runde
             // Artikel Rabatt berücksichtigt
             // Gesamt Rabatt auf Bestellung nicht
             // Nur weiterrechnen, falls Product nicht ohne Steuer
             // $this->total + $this->tax wird berechnet
             if ($product['products_tax_class_id'] != 0) {
                 if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                     // Rabatt für die Steuerberechnung
                     // der eigentliche Rabatt wird im order-details_cart abgezogen
                     $products_price_tax = $products_price - $products_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
                     $attribute_price_tax = $attribute_price - $attribute_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
                 }
                 $products_tax = $xtPrice->TAX[$product['products_tax_class_id']];
                 $products_tax_description = xtc_get_tax_description($product['products_tax_class_id']);
                 // price incl tax
                 if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '1') {
                     if (!isset($this->tax[$product['products_tax_class_id']])) {
                         $this->tax[$product['products_tax_class_id']]['value'] = 0;
                     }
                     //DokuMan - 2010-03-26 - set undefined variable
                     if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price_tax + $attribute_price_tax) / (100 + $products_tax) * $products_tax * $qty;
                     } else {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price + $attribute_price) / (100 + $products_tax) * $products_tax * $qty;
                     }
                     $this->tax[$product['products_tax_class_id']]['desc'] = TAX_ADD_TAX . $products_tax_description;
                 }
                 // excl tax + tax at checkout
                 if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                     if (!isset($this->tax[$product['products_tax_class_id']])) {
                         $this->tax[$product['products_tax_class_id']]['value'] = 0;
                     }
                     //Web28 - 2012-05-08 - set undefined variable
                     if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price_tax + $attribute_price_tax) / 100 * $products_tax * $qty;
                         //$this->total+=(($products_price_tax+$attribute_price_tax) / 100) * ($products_tax)*$qty;  // Tomcraft - 2011-02-01 - Paypal Express Modul fuer Einzelrundung
                         if (!isset($this->tax_discount[$product['products_tax_class_id']])) {
                             $this->tax_discount[$product['products_tax_class_id']] = 0;
                         }
                         $this->tax_discount[$product['products_tax_class_id']] += ($products_price_tax + $attribute_price_tax) / 100 * $products_tax * $qty;
                         // Tomcraft - 2011-02-01 - Paypal Express Modul fuer Einzelrundung
                     } else {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price + $attribute_price) / 100 * $products_tax * $qty;
                         $this->total += ($products_price + $attribute_price) / 100 * $products_tax * $qty;
                     }
                     $this->tax[$product['products_tax_class_id']]['desc'] = TAX_NO_TAX . $products_tax_description;
                 }
             }
         }
     }
     // BOF - Tomcraft - 2011-02-01 - Paypal Express Modul // Aufaddieren und Runden der Gesamtsumme je Steuersatz
     foreach ($this->tax_discount as $value) {
         //$this->total+=round($value, $xtPrice->get_decimal_places($order->info['currency']));
         $this->total += round($value, $xtPrice->get_decimal_places(''));
         //web28: parameter in get_decimal_places isn't used
     }
     // EOF - Tomcraft - 2011-02-01 - Paypal Express Modul  // Aufaddieren und Runden der Gesamtsumme je Steuersatz
     //echo 'TT'.$this->total;
 }