Example #1
0
 function calculate_deductions($order_total)
 {
     global $db, $order, $messageStack;
     $od_amount = array();
     $deduction = $this->calculate_credit($this->get_order_total());
     $od_amount['total'] = $deduction;
     switch ($this->calculate_tax) {
         case 'None':
             $remainder = $order->info['total'] - $od_amount['total'];
             $tax_deduct = $order->info['tax'] - $remainder;
             // division by 0
             if ($order->info['tax'] <= 0) {
                 $ratio_tax = 0;
             } else {
                 $ratio_tax = $tax_deduct / $order->info['tax'];
             }
             $tax_deduct = 0;
             /*
                     if ($this->include_tax) {
                       reset($order->info['tax_groups']);
                       foreach ($order->info['tax_groups'] as $key=>$value) {
                         $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio_tax;
                         $tax_deduct += $od_amount['tax_groups'][$key];
                       }
                     }
             */
             $od_amount['tax'] = $tax_deduct;
             break;
         case 'Standard':
             if ($od_amount['total'] >= $order_total) {
                 $ratio = 1;
             } else {
                 $ratio = $od_amount['total'] / ($order_total - $order->info['tax']);
             }
             reset($order->info['tax_groups']);
             $tax_deduct = 0;
             foreach ($order->info['tax_groups'] as $key => $value) {
                 $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
                 $tax_deduct += $od_amount['tax_groups'][$key];
             }
             $od_amount['tax'] = $tax_deduct;
             break;
         case 'Credit Note':
             $od_amount['total'] = $deduction;
             $tax_rate = zen_get_tax_rate($this->tax_class);
             $od_amount['tax'] = zen_calculate_tax($deduction, $tax_rate);
             $tax_description = zen_get_tax_description($this->tax_class);
             $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
             break;
         default:
     }
     return $od_amount;
 }
Example #2
0
 function ot_shipping()
 {
     global $order, $currencies;
     $this->code = 'ot_shipping';
     $this->title = MODULE_ORDER_TOTAL_SHIPPING_TITLE;
     $this->description = MODULE_ORDER_TOTAL_SHIPPING_DESCRIPTION;
     $this->sort_order = MODULE_ORDER_TOTAL_SHIPPING_SORT_ORDER;
     unset($_SESSION['shipping_tax_description']);
     $this->output = array();
     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;
                 }
                 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_SHIPPING_FREE_SHIPPING_OVER) {
             $order->info['shipping_method'] = $this->title;
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     $module = isset($_SESSION['shipping']) && isset($_SESSION['shipping']['id']) ? substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_')) : '';
     if (is_object($order) && zen_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             if (!isset($GLOBALS[$module]->tax_basis)) {
                 $shipping_tax_basis = STORE_SHIPPING_TAX_BASIS;
             } else {
                 $shipping_tax_basis = $GLOBALS[$module]->tax_basis;
             }
             if ($shipping_tax_basis == 'Billing') {
                 $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
                 $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
             } elseif ($shipping_tax_basis == 'Shipping') {
                 $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                 $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             } else {
                 if (STORE_ZONE == $order->billing['zone_id']) {
                     $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
                     $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
                 } elseif (STORE_ZONE == $order->delivery['zone_id']) {
                     $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                     $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                 } else {
                     $shipping_tax = 0;
                 }
             }
             $shipping_tax_amount = zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['shipping_tax'] += $shipping_tax_amount;
             $order->info['tax'] += $shipping_tax_amount;
             $order->info['tax_groups']["{$shipping_tax_description}"] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $_SESSION['shipping_tax_description'] = $shipping_tax_description;
             $_SESSION['shipping_tax_amount'] = $shipping_tax_amount;
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         if ($_SESSION['shipping']['id'] == 'free_free') {
             $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
             $order->info['shipping_cost'] = 0;
         }
     }
 }
Example #3
0
 function calculate_deductions($order_total)
 {
     global $db, $order;
     $od_amount = array();
     if ($order_total == 0) {
         return $od_amount;
     }
     $orderTotal = $this->get_order_total();
     $orderTotalTax = $orderTotal['tax'];
     $taxGroups = $orderTotal['taxGroups'];
     $group_query = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . (int) $_SESSION['customer_id'] . "'");
     if ($group_query->fields['customers_group_pricing'] != '0') {
         $group_discount = $db->Execute("select group_name, group_percentage from " . TABLE_GROUP_PRICING . "\n                                      where group_id = '" . (int) $group_query->fields['customers_group_pricing'] . "'");
         $gift_vouchers = $_SESSION['cart']->gv_only();
         $discount = ($orderTotal['total'] - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
         //      echo "discout = $discount<br>";
         $od_amount['total'] = round($discount, 2);
         $ratio = $od_amount['total'] / $order_total;
         /**
          * when calculating the ratio add some insignificant values to stop divide by zero errors
          */
         switch ($this->calculate_tax) {
             case 'None':
                 if ($this->include_tax) {
                     reset($order->info['tax_groups']);
                     foreach ($order->info['tax_groups'] as $key => $value) {
                         $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
                     }
                 }
                 break;
             case 'Standard':
                 if ($od_amount['total'] >= $order_total) {
                     $ratio = 1;
                 }
                 $adjustedTax = $orderTotalTax * $ratio;
                 if ($order->info['tax'] == 0) {
                     return $od_amount;
                 }
                 $ratioTax = $orderTotalTax != 0 ? $adjustedTax / $orderTotalTax : 0;
                 reset($order->info['tax_groups']);
                 $tax_deduct = 0;
                 foreach ($taxGroups as $key => $value) {
                     $od_amount['tax_groups'][$key] = $value * $ratioTax;
                     $tax_deduct += $od_amount['tax_groups'][$key];
                 }
                 $od_amount['tax'] = $tax_deduct;
                 break;
             case 'Credit Note':
                 $tax_rate = zen_get_tax_rate($this->tax_class);
                 $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
                 $tax_description = zen_get_tax_description($this->tax_class);
                 $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
                 break;
         }
     }
     return $od_amount;
 }
Example #4
0
 function process()
 {
     global $order, $currencies;
     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) ) {
         if ($pass == true && $order->info['subtotal'] < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) {
             $charge_it = 'true';
             $cart_content_type = $_SESSION['cart']->get_content_type();
             $gv_content_only = $_SESSION['cart']->gv_only();
             if ($cart_content_type == 'physical' or $cart_content_type == 'mixed') {
                 $charge_it = 'true';
             } else {
                 // check to see if everything is virtual, if so - skip the low order fee.
                 if ($cart_content_type == 'virtual' and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'true') {
                     $charge_it = 'false';
                     if ($gv_content_only > 0 and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'false') {
                         $charge_it = 'true';
                     }
                 }
                 if ($gv_content_only > 0 and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'true') {
                     // check to see if everything is gift voucher, if so - skip the low order fee.
                     $charge_it = 'false';
                     if ($cart_content_type == 'virtual' and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'false') {
                         $charge_it = 'true';
                     }
                 }
             }
             if ($charge_it == 'true') {
                 $tax_address = zen_get_tax_locations();
                 $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $tax_address['country_id'], $tax_address['zone_id']);
                 $tax_description = zen_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $tax_address['country_id'], $tax_address['zone_id']);
                 // calculate from flat fee or percentage
                 if (substr(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, -1) == '%') {
                     $low_order_fee = $order->info['subtotal'] * (MODULE_ORDER_TOTAL_LOWORDERFEE_FEE / 100);
                 } else {
                     $low_order_fee = MODULE_ORDER_TOTAL_LOWORDERFEE_FEE;
                 }
                 $order->info['tax'] += zen_calculate_tax($low_order_fee, $tax);
                 $order->info['tax_groups']["{$tax_description}"] += zen_calculate_tax($low_order_fee, $tax);
                 $order->info['total'] += $low_order_fee + zen_calculate_tax($low_order_fee, $tax);
                 if (DISPLAY_PRICE_WITH_TAX == 'true') {
                     $low_order_fee += zen_calculate_tax($low_order_fee, $tax);
                 }
                 $this->output[] = array('title' => $this->title . ':', 'text' => $currencies->format($low_order_fee, true, $order->info['currency'], $order->info['currency_value']), 'value' => $low_order_fee);
             }
         }
     }
 }
 function process()
 {
     global $order, $currencies;
     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;
                 }
                 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_SHIPPING_FREE_SHIPPING_OVER) {
             $order->info['shipping_method'] = $this->title;
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     $module = substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_'));
     if (zen_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             if (!defined($GLOBALS[$module]->tax_basis)) {
                 $shipping_tax_basis = STORE_SHIPPING_TAX_BASIS;
             } else {
                 $shipping_tax_basis = $GLOBALS[$module]->tax_basis;
             }
             if ($shipping_tax_basis == 'Billing') {
                 $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
                 $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
             } elseif ($shipping_tax_basis == 'Shipping') {
                 $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                 $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             } else {
                 if (STORE_ZONE == $order->billing['zone_id']) {
                     $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
                     $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
                 } elseif (STORE_ZONE == $order->delivery['zone_id']) {
                     $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                     $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                 } else {
                     $shipping_tax = 0;
                 }
             }
             $order->info['tax'] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         if ($_SESSION['shipping'] == 'free_free') {
             $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
         }
         $this->output[] = array('title' => $order->info['shipping_method'] . ':', 'text' => $currencies->format($order->info['shipping_cost'], true, $order->info['currency'], $order->info['currency_value']), 'value' => $order->info['shipping_cost']);
     }
 }
Example #6
0
 function process()
 {
     global $order, $currencies, $cod_cost, $cod_country, $shipping;
     if ($this->enabled == 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
             if (substr_count($_SESSION['shipping']['id'], 'flat') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FLAT);
             }
             if (substr_count($_SESSION['shipping']['id'], 'free') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREE);
             }
             if (substr_count($_SESSION['shipping']['id'], 'freeshipper') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREESHIPPER);
             }
             if (substr_count($_SESSION['shipping']['id'], 'freeoptions') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREEOPTIONS);
             }
             if (substr_count($_SESSION['shipping']['id'], 'item') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ITEM);
             }
             if (substr_count($_SESSION['shipping']['id'], 'perweightunit') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_PERWEIGHTUNIT);
             }
             if (substr_count($_SESSION['shipping']['id'], 'table') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_TABLE);
             }
             if (substr_count($_SESSION['shipping']['id'], 'ups') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPS);
             }
             if (substr_count($_SESSION['shipping']['id'], 'usps') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_USPS);
             }
             if (substr_count($_SESSION['shipping']['id'], 'fedex') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FEDEX);
             }
             if (substr_count($_SESSION['shipping']['id'], 'zones') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ZONES);
             }
             if (substr_count($_SESSION['shipping']['id'], 'ap') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_AP);
             }
             if (substr_count($_SESSION['shipping']['id'], 'dp') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DP);
             }
             //satt inn av Pompel
             if (substr_count($_SESSION['shipping']['id'], 'servicepakke') != 0) {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_SERVICEPAKKE);
             }
             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;
                     //print('match' . $i . ': ' . $cod_cost);
                     break;
                 } elseif ($cod_zones[$i] == '00') {
                     $cod_cost = $cod_zones[$i + 1];
                     $cod_country = true;
                     //print('match' . $i . ': ' . $cod_cost);
                     break;
                 } else {
                     //print('no match');
                 }
                 $i++;
             }
         } else {
             //COD selected, but no shipping module which offers COD
         }
         if ($cod_country) {
             $cod_tax_address = zen_get_tax_locations();
             $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_COD_TAX_CLASS, $cod_tax_address['country_id'], $cod_tax_address['zone_id']);
             $order->info['total'] += $cod_cost;
             if ($tax > 0) {
                 $tax_description = zen_get_tax_description(MODULE_ORDER_TOTAL_COD_TAX_CLASS, $cod_tax_address['country_id'], $cod_tax_address['zone_id']);
                 $order->info['tax'] += zen_calculate_tax($cod_cost, $tax);
                 $order->info['tax_groups'][$tax_description] += zen_calculate_tax($cod_cost, $tax);
                 $order->info['total'] += zen_calculate_tax($cod_cost, $tax);
                 if (DISPLAY_PRICE_WITH_TAX == 'true') {
                     $cod_cost += zen_calculate_tax($cod_cost, $tax);
                 }
             }
             $this->output[] = array('title' => $this->title . ':', 'text' => $currencies->format($cod_cost, true, $order->info['currency'], $order->info['currency_value']), 'value' => $cod_cost);
         } 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' => '');
         }
     }
 }
Example #7
0
 /**
  * Enter description here...
  *
  * @param unknown_type $order_total
  * @return unknown
  */
 function calculate_deductions($order_total)
 {
     global $db, $order, $messageStack, $currencies;
     $tax_address = zen_get_tax_locations();
     $od_amount = array();
     $orderTotalDetails = $this->get_order_total();
     $orderTotalTax = $orderTotalDetails['tax'];
     $orderTotal = $orderTotalDetails['total'];
     if ($_SESSION['cc_id']) {
         $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int) $_SESSION['cc_id'] . "'");
         $this->coupon_code = $coupon->fields['coupon_code'];
         if ($coupon->RecordCount() > 0 && $orderTotal != 0 || $coupon->RecordCount() > 0 && $coupon->fields['coupon_type'] == 'S') {
             // left for total order amount vs qualified order amount just switch the commented lines
             //        if ($orderTotalDetails['totalFull'] >= $coupon->fields['coupon_minimum_order']) {
             if (strval($orderTotalDetails['total']) >= $coupon->fields['coupon_minimum_order']) {
                 if ($coupon->fields['coupon_type'] == 'S') {
                     $od_amount['total'] = $_SESSION['shipping']['cost'];
                     $od_amount['type'] = 'S';
                     $od_amount['tax'] = $this->calculate_tax == 'Standard' ? $_SESSION['shipping_tax_amount'] : 0;
                     if (DISPLAY_PRICE_WITH_TAX == 'true') {
                         $od_amount['total'] += $od_amount['tax'];
                     }
                     if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
                         $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
                     }
                     return $od_amount;
                 }
                 if ($coupon->fields['coupon_type'] == 'P') {
                     $od_amount['total'] = round($orderTotal * ($coupon->fields['coupon_amount'] / 100), 2);
                     $od_amount['type'] = 'P';
                     $ratio = $od_amount['total'] / $orderTotal;
                 } elseif ($coupon->fields['coupon_type'] == 'F') {
                     $od_amount['total'] = round($coupon->fields['coupon_amount'] * ($orderTotal > 0), 2);
                     $od_amount['type'] = 'F';
                     $ratio = $od_amount['total'] / $orderTotal;
                 }
                 if ($od_amount['total'] > $orderTotal) {
                     $od_amount['total'] = $orderTotal;
                 }
                 switch ($this->calculate_tax) {
                     case 'None':
                         if ($this->include_tax == 'true') {
                             reset($order->info['tax_groups']);
                             foreach ($order->info['tax_groups'] as $key => $value) {
                                 $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
                             }
                         }
                         break;
                     case 'Standard':
                         if ($od_amount['total'] >= $orderTotal) {
                             $ratio = 1;
                         }
                         $adjustedTax = $orderTotalTax * $ratio;
                         //            echo "order total tax = $orderTotalTax";
                         $ratioTax = isset($order->info['tax']) && $order->info['tax'] != 0 ? $adjustedTax / $order->info['tax'] : 0;
                         reset($order->info['tax_groups']);
                         $tax_deduct = 0;
                         foreach ($order->info['tax_groups'] as $key => $value) {
                             $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratioTax;
                             $tax_deduct += $od_amount['tax_groups'][$key];
                         }
                         $od_amount['tax'] = $tax_deduct;
                         break;
                     case 'Credit Note':
                         $tax_rate = zen_get_tax_rate($this->tax_class);
                         $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
                         $tax_description = zen_get_tax_description($this->tax_class);
                         $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
                         break;
                     default:
                 }
             } else {
                 $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_REDEEM_COUPON_MINIMUM, $currencies->format($coupon->fields['coupon_minimum_order'])), 'caution');
                 $this->clear_posts();
                 zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
             }
         }
     }
     return $od_amount;
 }
Example #8
0
 function calculate_deductions($order_total)
 {
     global $gBitDb, $gBitCustomer, $order;
     $tax_address = zen_get_tax_locations();
     $od_amount['total'] = 0;
     $od_amount['tax'] = 0;
     if ($_SESSION['cc_id']) {
         $coupon = new CommerceVoucher($_SESSION['cc_id']);
         if ($coupon->load() && $coupon->isRedeemable()) {
             if ($coupon->getField('coupon_minimum_order') <= $order_total) {
                 if ($coupon->getField('coupon_type') == 'S') {
                     if ($coupon->getField('restrict_to_shipping')) {
                         $shippingMethods = explode(',', $coupon->getField('restrict_to_shipping'));
                         if (in_array($order->info['shipping_method_code'], $shippingMethods)) {
                             $od_amount['total'] = $order->info['shipping_cost'];
                         }
                     } else {
                         $od_amount['total'] = $order->info['shipping_cost'];
                     }
                     $od_amount['type'] = 'S';
                 } else {
                     if ($coupon->getField('coupon_type') == 'P') {
                         // Max discount is a sum of percentages of valid products
                         $totalDiscount = 0;
                     } else {
                         $totalDiscount = $coupon->getField('coupon_amount') * ($order_total > 0);
                     }
                     $runningDiscount = 0;
                     $runningDiscountQuantity = 0;
                     foreach (array_keys($gBitCustomer->mCart->contents) as $productKey) {
                         $productHash = $gBitCustomer->mCart->getProductHash($productKey);
                         if ($coupon->getField('quantity_max')) {
                             if ($discountQuantity = $coupon->getField('quantity_max') - $runningDiscountQuantity) {
                                 if ($discountQuantity > $productHash['products_quantity']) {
                                     $discountQuantity = $productHash['products_quantity'];
                                 }
                             }
                         } else {
                             $discountQuantity = $productHash['products_quantity'];
                         }
                         if ($productHash && $discountQuantity && $this->is_product_valid($productHash, $_SESSION['cc_id'])) {
                             // _P_ercentage discount
                             if ($coupon->getField('coupon_type') == 'P') {
                                 $runningDiscountQuantity += $discountQuantity;
                                 $itemDiscount = round($productHash['final_price'] * $discountQuantity * ($coupon->getField('coupon_amount') / 100), 2);
                                 $totalDiscount += $itemDiscount;
                                 if ($runningDiscount < $totalDiscount) {
                                     $runningDiscount += $itemDiscount;
                                 }
                                 if ($runningDiscount > $totalDiscount) {
                                     $runningDiscount = $totalDiscount;
                                     $itemDiscount = 0;
                                 }
                                 switch ($this->calculate_tax) {
                                     case 'Credit Note':
                                         $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $od_amount[$tax_desc] = $runningDiscount / 100 * $tax_rate;
                                         $od_amount['tax'] += $od_amount[$tax_desc];
                                         break;
                                     case 'Standard':
                                         $ratio = $runningDiscount / $this->get_order_total();
                                         $tax_rate = zen_get_tax_rate($productHash['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                         $tax_desc = zen_get_tax_description($productHash['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                         if ($tax_rate > 0) {
                                             if (empty($od_amount[$tax_desc])) {
                                                 $od_amount[$tax_desc] = 0;
                                             }
                                             $od_amount[$tax_desc] += $productHash['final_price'] * $discountQuantity * $tax_rate / 100 * $ratio;
                                             $od_amount['tax'] += $od_amount[$tax_desc];
                                         }
                                         break;
                                 }
                                 // _F_ixed discount
                             } elseif ($coupon->getField('coupon_type') == 'F') {
                                 switch ($this->calculate_tax) {
                                     case 'Credit Note':
                                         $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $od_amount[$tax_desc] = $runningDiscount / 100 * $tax_rate;
                                         $od_amount['tax'] += $od_amount[$tax_desc];
                                         break;
                                     case 'Standard':
                                         $ratio = $runningDiscount / $this->get_order_total();
                                         $t_prid = zen_get_prid($productKey);
                                         $cc_result = $gBitDb->query("select `products_tax_class_id` from " . TABLE_PRODUCTS . " where `products_id` = ?", array($t_prid));
                                         if ($this->is_product_valid($productHash, $_SESSION['cc_id'])) {
                                             if ($runningDiscount < $totalDiscount) {
                                                 $runningDiscount += $productHash['final_price'] * $discountQuantity;
                                             }
                                             if ($runningDiscount > $totalDiscount) {
                                                 $runningDiscount = $totalDiscount;
                                             }
                                             $tax_rate = zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                             $tax_desc = zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                             if ($tax_rate > 0) {
                                                 if (empty($od_amount[$tax_desc])) {
                                                     $od_amount[$tax_desc] = 0;
                                                 }
                                                 $od_amount[$tax_desc] += $productHash['final_price'] * $discountQuantity * $tax_rate / 100 * $ratio;
                                                 $od_amount['tax'] += $od_amount[$tax_desc];
                                             }
                                         }
                                         break;
                                 }
                             }
                         }
                     }
                     $od_amount['total'] = $runningDiscount;
                     if ($od_amount['total'] > $order_total) {
                         $od_amount['total'] = $order_total;
                     }
                 }
             }
         }
     }
     return $od_amount;
 }
Example #9
0
 function cart()
 {
     global $db, $currencies;
     $this->content_type = $_SESSION['cart']->get_content_type();
     $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone,\r\n                                        c.customers_email_address, ab.entry_company, ab.entry_street_address,\r\n                                        ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,\r\n                                        z.zone_name, co.countries_id, co.countries_name,\r\n                                        co.countries_iso_code_2, co.countries_iso_code_3,\r\n                                        co.address_format_id, ab.entry_state\r\n                                 from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab\r\n                                 left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                 left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id)\r\n                                 where c.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                 and ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                 and c.customers_default_address_id = ab.address_book_id";
     $customer_address = $db->Execute($customer_address_query);
     $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\r\n                                        ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\r\n                                        ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\r\n                                        c.countries_id, c.countries_name, c.countries_iso_code_2,\r\n                                        c.countries_iso_code_3, c.address_format_id, ab.entry_state\r\n                                 from " . TABLE_ADDRESS_BOOK . " ab\r\n                                 left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                 left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\r\n                                 where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                 and ab.address_book_id = '" . (int) $_SESSION['sendto'] . "'";
     $shipping_address = $db->Execute($shipping_address_query);
     $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\r\n                                       ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\r\n                                       ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\r\n                                       c.countries_id, c.countries_name, c.countries_iso_code_2,\r\n                                       c.countries_iso_code_3, c.address_format_id, ab.entry_state\r\n                                from " . TABLE_ADDRESS_BOOK . " ab\r\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\r\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
     $billing_address = $db->Execute($billing_address_query);
     //STORE_PRODUCT_TAX_BASIS
     switch (STORE_PRODUCT_TAX_BASIS) {
         case 'Shipping':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                from " . TABLE_ADDRESS_BOOK . " ab\r\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Billing':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                from " . TABLE_ADDRESS_BOOK . " ab\r\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Store':
             if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                  from " . TABLE_ADDRESS_BOOK . " ab\r\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             } else {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                  from " . TABLE_ADDRESS_BOOK . " ab\r\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                  and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             }
             $tax_address = $db->Execute($tax_address_query);
     }
     $class =& $_SESSION['payment'];
     if (isset($_SESSION['cc_id'])) {
         $coupon_code_query = "select coupon_code\r\n                              from " . TABLE_COUPONS . "\r\n                              where coupon_id = '" . (int) $_SESSION['cc_id'] . "'";
         $coupon_code = $db->Execute($coupon_code_query);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'payment_module_code' => $GLOBALS[$class]->code, 'coupon_code' => $coupon_code->fields['coupon_code'], 'shipping_method' => $_SESSION['shipping']['title'], 'shipping_module_code' => $_SESSION['shipping']['id'], 'shipping_cost' => $_SESSION['shipping']['cost'], 'subtotal' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SERVER['REMOTE_ADDR']);
     //print_r($GLOBALS[$class]);
     //echo $class;
     //print_r($GLOBALS);
     //echo $_SESSION['payment'];
     /*
     // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder
           if (isset($$_SESSION['payment']) && is_object($$_SESSION['payment'])) {
             $this->info['payment_method'] = $$_SESSION['payment']->title;
           }
     */
     if ($this->info['total'] == 0) {
         if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
         } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
         }
     }
     if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
         if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
         }
     }
     $this->customer = array('firstname' => $customer_address->fields['customers_firstname'], 'lastname' => $customer_address->fields['customers_lastname'], 'company' => $customer_address->fields['entry_company'], 'street_address' => $customer_address->fields['entry_street_address'], 'suburb' => $customer_address->fields['entry_suburb'], 'city' => $customer_address->fields['entry_city'], 'postcode' => $customer_address->fields['entry_postcode'], 'state' => zen_not_null($customer_address->fields['entry_state']) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name'], 'zone_id' => $customer_address->fields['entry_zone_id'], 'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']), 'format_id' => $customer_address->fields['address_format_id'], 'telephone' => $customer_address->fields['customers_telephone'], 'email_address' => $customer_address->fields['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'], 'lastname' => $shipping_address->fields['entry_lastname'], 'company' => $shipping_address->fields['entry_company'], 'street_address' => $shipping_address->fields['entry_street_address'], 'suburb' => $shipping_address->fields['entry_suburb'], 'city' => $shipping_address->fields['entry_city'], 'postcode' => $shipping_address->fields['entry_postcode'], 'state' => zen_not_null($shipping_address->fields['entry_state']) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name'], 'zone_id' => $shipping_address->fields['entry_zone_id'], 'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']), 'country_id' => $shipping_address->fields['entry_country_id'], 'format_id' => $shipping_address->fields['address_format_id']);
     $this->billing = array('firstname' => $billing_address->fields['entry_firstname'], 'lastname' => $billing_address->fields['entry_lastname'], 'company' => $billing_address->fields['entry_company'], 'street_address' => $billing_address->fields['entry_street_address'], 'suburb' => $billing_address->fields['entry_suburb'], 'city' => $billing_address->fields['entry_city'], 'postcode' => $billing_address->fields['entry_postcode'], 'state' => zen_not_null($billing_address->fields['entry_state']) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name'], 'zone_id' => $billing_address->fields['entry_zone_id'], 'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']), 'country_id' => $billing_address->fields['entry_country_id'], 'format_id' => $billing_address->fields['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax' => zen_get_tax_rate($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), 'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']), 'weight' => $products[$i]['weight'], 'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'], 'product_is_free' => $products[$i]['product_is_free'], 'products_discount_type' => $products[$i]['products_discount_type'], 'products_discount_type_from' => $products[$i]['products_discount_type_from'], 'id' => $products[$i]['id']);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 /*
                 	//clr 030714 Determine if attribute is a text attribute and change products array if it is.
                             if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){
                               $attr_value = $products[$i]['attributes_values'][$option];
                             } else {
                               $attr_value = $attributes->fields['products_options_values_name'];
                             }
                 */
                 $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\r\n                                        pa.options_values_price, pa.price_prefix\r\n                                 from " . TABLE_PRODUCTS_OPTIONS . " popt,\r\n                                      " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,\r\n                                      " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n                                 where pa.products_id = '" . (int) $products[$i]['id'] . "'\r\n                                 and pa.options_id = '" . (int) $option . "'\r\n                                 and pa.options_id = popt.products_options_id\r\n                                 and pa.options_values_id = '" . (int) $value . "'\r\n                                 and pa.options_values_id = poval.products_options_values_id\r\n                                 and popt.language_id = '" . (int) $_SESSION['languages_id'] . "'\r\n                                 and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'";
                 $attributes = $db->Execute($attributes_query);
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                     $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                     $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes->fields['price_prefix'], 'price' => $attributes->fields['options_values_price']);
                 $subindex++;
             }
         }
         // add onetime charges here
         //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])
         $shown_price = zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'] + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
         $this->info['subtotal'] += $shown_price;
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $this->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             }
         } else {
             $this->info['tax'] += $products_tax / 100 * $shown_price;
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $products_tax / 100 * $shown_price;
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $products_tax / 100 * $shown_price;
             }
         }
         $this->info['tax'] = zen_round($this->info['tax'], 2);
         $index++;
     }
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
     } else {
         $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
     }
 }
Example #10
0
 function cart()
 {
     global $db, $currencies;
     $this->content_type = $_SESSION['cart']->get_content_type();
     $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone,\n\n                                    c.customers_email_address, ab.entry_company, ab.entry_street_address,\n\n                                    ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,\n\n                                    z.zone_name, co.countries_id, co.countries_name,\n\n                                    co.countries_iso_code_2, co.countries_iso_code_3,\n\n                                    co.address_format_id, ab.entry_state\n\n                                   from (" . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab )\n\n                                   left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                   left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id)\n\n                                   where c.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                   and ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                   and c.customers_default_address_id = ab.address_book_id";
     $customer_address = $db->Execute($customer_address_query);
     $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n\n                                    ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n\n                                    ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n\n                                    c.countries_id, c.countries_name, c.countries_iso_code_2,\n\n                                    c.countries_iso_code_3, c.address_format_id, ab.entry_state\n\n                                   from " . TABLE_ADDRESS_BOOK . " ab\n\n                                   left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                   left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n\n                                   where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                   and ab.address_book_id = '" . (int) $_SESSION['sendto'] . "'";
     $shipping_address = $db->Execute($shipping_address_query);
     $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n\n                                   ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n\n                                   ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n\n                                   c.countries_id, c.countries_name, c.countries_iso_code_2,\n\n                                   c.countries_iso_code_3, c.address_format_id, ab.entry_state\n\n                                  from " . TABLE_ADDRESS_BOOK . " ab\n\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                  left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
     $billing_address = $db->Execute($billing_address_query);
     //STORE_PRODUCT_TAX_BASIS
     switch (STORE_PRODUCT_TAX_BASIS) {
         case 'Shipping':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                              from " . TABLE_ADDRESS_BOOK . " ab\n\n                              left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                              where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                              and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Billing':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                              from " . TABLE_ADDRESS_BOOK . " ab\n\n                              left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                              where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                              and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Store':
             if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                                from " . TABLE_ADDRESS_BOOK . " ab\n\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             } else {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                                from " . TABLE_ADDRESS_BOOK . " ab\n\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             }
             $tax_address = $db->Execute($tax_address_query);
     }
     $class =& $_SESSION['payment'];
     if (isset($_SESSION['cc_id'])) {
         $coupon_code_query = "select coupon_code\n\n                              from " . TABLE_COUPONS . "\n\n                              where coupon_id = '" . (int) $_SESSION['cc_id'] . "'";
         $coupon_code = $db->Execute($coupon_code_query);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'payment_module_code' => $GLOBALS[$class]->code, 'coupon_code' => $coupon_code->fields['coupon_code'], 'shipping_method' => $_SESSION['shipping']['title'], 'shipping_module_code' => $_SESSION['shipping']['id'], 'shipping_cost' => $_SESSION['shipping']['cost'], 'subtotal' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);
     //echo  "<br>".__FILE__.' line:'.__LINE__.'============'."<pre>";print_r($_SESSION['shipping']);echo '--';print_r($_SESSION['shipping']['cost']);exit;
     //print_r($GLOBALS[$class]);
     //echo $class;
     //print_r($GLOBALS);
     //echo $_SESSION['payment'];
     /*
     // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder
     if (isset($$_SESSION['payment']) && is_object($$_SESSION['payment'])) {
     $this->info['payment_method'] = $$_SESSION['payment']->title;
     }
     */
     /*
     // bof: move below calculations
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
         if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
           if ( isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && ($GLOBALS[$class]->order_status > 0) ) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
           }
         }
     // eof: move below calculations
     */
     $this->customer = array('firstname' => $customer_address->fields['customers_firstname'], 'lastname' => $customer_address->fields['customers_lastname'], 'company' => $customer_address->fields['entry_company'], 'street_address' => $customer_address->fields['entry_street_address'], 'suburb' => $customer_address->fields['entry_suburb'], 'city' => $customer_address->fields['entry_city'], 'postcode' => $customer_address->fields['entry_postcode'], 'state' => zen_not_null($customer_address->fields['entry_state']) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name'], 'zone_id' => $customer_address->fields['entry_zone_id'], 'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']), 'format_id' => (int) $customer_address->fields['address_format_id'], 'telephone' => $customer_address->fields['customers_telephone'], 'email_address' => $customer_address->fields['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'], 'lastname' => $shipping_address->fields['entry_lastname'], 'company' => $shipping_address->fields['entry_company'], 'street_address' => $shipping_address->fields['entry_street_address'], 'suburb' => $shipping_address->fields['entry_suburb'], 'city' => $shipping_address->fields['entry_city'], 'postcode' => $shipping_address->fields['entry_postcode'], 'state' => zen_not_null($shipping_address->fields['entry_state']) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name'], 'zone_id' => $shipping_address->fields['entry_zone_id'], 'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']), 'country_id' => $shipping_address->fields['entry_country_id'], 'format_id' => (int) $shipping_address->fields['address_format_id']);
     $this->billing = array('firstname' => $billing_address->fields['entry_firstname'], 'lastname' => $billing_address->fields['entry_lastname'], 'company' => $billing_address->fields['entry_company'], 'street_address' => $billing_address->fields['entry_street_address'], 'suburb' => $billing_address->fields['entry_suburb'], 'city' => $billing_address->fields['entry_city'], 'postcode' => $billing_address->fields['entry_postcode'], 'state' => zen_not_null($billing_address->fields['entry_state']) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name'], 'zone_id' => $billing_address->fields['entry_zone_id'], 'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']), 'country_id' => $billing_address->fields['entry_country_id'], 'format_id' => (int) $billing_address->fields['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products(true);
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         if ($i / 2 == floor($i / 2)) {
             $rowClass = "rowEven";
         } else {
             $rowClass = "rowOdd";
         }
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax' => zen_get_tax_rate($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price(zen_get_uprid($products[$i]['id'], $products[$i]['attributes'])), 'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']), 'weight' => $products[$i]['weight'], 'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'], 'product_is_free' => $products[$i]['product_is_free'], 'products_discount_type' => $products[$i]['products_discount_type'], 'products_discount_type_from' => $products[$i]['products_discount_type_from'], 'id' => $products[$i]['id'], 'rowClass' => $rowClass);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 /*
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){
                 $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                 $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 */
                 $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n\n                                          pa.options_values_price, pa.price_prefix\n\n                                   from " . TABLE_PRODUCTS_OPTIONS . " popt,\n\n                                        " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,\n\n                                        " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\n                                   where pa.products_id = '" . (int) $products[$i]['id'] . "'\n\n                                   and pa.options_id = '" . (int) $option . "'\n\n                                   and pa.options_id = popt.products_options_id\n\n                                   and pa.options_values_id = '" . (int) $value . "'\n\n                                   and pa.options_values_id = poval.products_options_values_id\n\n                                   and popt.language_id = '" . (int) $_SESSION['languages_id'] . "'\n\n                                   and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'";
                 $attributes = $db->Execute($attributes_query);
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                     $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                     $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes->fields['price_prefix'], 'price' => $attributes->fields['options_values_price']);
                 $subindex++;
             }
         }
         // add onetime charges here
         //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])
         /*********************************************
          * Calculate taxes for this product
          *********************************************/
         $shown_price = zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'] + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
         $this->info['subtotal'] += $shown_price;
         // find product's tax rate and description
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             // calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled)
             $tax_add = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
         } else {
             // calculate the amount of tax for this product (assuming tax is NOT included in the price)
             $tax_add = zen_round($products_tax / 100 * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']);
         }
         $this->info['tax'] += $tax_add;
         if (isset($this->info['tax_groups'][$products_tax_description])) {
             $this->info['tax_groups'][$products_tax_description] += $tax_add;
         } else {
             $this->info['tax_groups'][$products_tax_description] = $tax_add;
         }
         /*********************************************
          * END: Calculate taxes for this product
          *********************************************/
         $index++;
     }
     // Update the final total to include tax if not already tax-inc
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         if ($_SESSION['insurance'] != "") {
             //判断保险是否选中 2011-3-29 du
             if ($_SESSION['insurance'] == 1) {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'] + $this->info['subtotal'] * 0.031;
             } else {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
             }
         } else {
             $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
         }
     } else {
         if ($_SESSION['insurance'] != "") {
             //判断保险是否选中 2011-3-29 du
             if ($_SESSION['insurance'] == 1) {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'] + $this->info['subtotal'] * 0.031;
             } else {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
             }
         } else {
             $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
         }
     }
     /*
     // moved to function create
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
     */
     if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
         if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
         }
     }
 }
Example #11
0
 /**
  * Enter description here...
  *
  * @param unknown_type $order_total
  * @return unknown
  */
 function calculate_deductions($order_total)
 {
     global $db, $order, $messageStack;
     $tax_address = zen_get_tax_locations();
     $od_amount = array();
     $orderTotal = $this->get_order_total();
     $orderTotalTax = $orderTotal['tax'];
     if ($_SESSION['cc_id']) {
         $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int) $_SESSION['cc_id'] . "'");
         $this->coupon_code = $coupon->fields['coupon_code'];
         if ($coupon->RecordCount() > 0 && $order_total != 0 || $coupon->RecordCount() > 0 && $coupon->fields['coupon_type'] == 'S') {
             if ($coupon->fields['coupon_minimum_order'] <= $orderTotal['totalFull']) {
                 if ($coupon->fields['coupon_type'] == 'S') {
                     $od_amount['total'] = $_SESSION['shipping']['cost'];
                     $od_amount['type'] = 'S';
                     $od_amount['tax'] = $_SESSION['shipping_tax_amount'];
                     if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
                         $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
                     }
                     return $od_amount;
                 }
                 if ($coupon->fields['coupon_type'] == 'P') {
                     $od_amount['total'] = round($order_total * ($coupon->fields['coupon_amount'] / 100), 2);
                     $od_amount['type'] = 'P';
                     $ratio = $od_amount['total'] / $order_total;
                 } elseif ($coupon->fields['coupon_type'] == 'F') {
                     $od_amount['total'] = $coupon->fields['coupon_amount'] * ($order_total > 0);
                     $od_amount['type'] = 'F';
                     $ratio = $od_amount['total'] / $order_total;
                 }
                 if ($od_amount['total'] > $order_total) {
                     $od_amount['total'] = $order_total;
                 }
                 switch ($this->calculate_tax) {
                     case 'None':
                         if ($this->include_tax) {
                             reset($order->info['tax_groups']);
                             foreach ($order->info['tax_groups'] as $key => $value) {
                                 $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
                             }
                         }
                         break;
                     case 'Standard':
                         if ($od_amount['total'] >= $order_total) {
                             $ratio = 1;
                         }
                         $adjustedTax = $orderTotalTax * $ratio;
                         $ratioTax = $adjustedTax / $order->info['tax'];
                         reset($order->info['tax_groups']);
                         $tax_deduct = 0;
                         foreach ($order->info['tax_groups'] as $key => $value) {
                             $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratioTax;
                             $tax_deduct += $od_amount['tax_groups'][$key];
                         }
                         $od_amount['tax'] = $tax_deduct;
                         break;
                     case 'Credit Note':
                         $tax_rate = zen_get_tax_rate($this->tax_class);
                         $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
                         $tax_description = zen_get_tax_description($this->tax_class);
                         $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
                         break;
                     default:
                 }
             }
         }
     }
     return $od_amount;
 }
 function calculate_deductions($order_total)
 {
     global $db, $order, $messageStack;
     $tax_address = zen_get_tax_locations();
     $od_amount = array();
     if ($_SESSION['cc_id']) {
         $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . $_SESSION['cc_id'] . "'");
         if ($coupon->RecordCount() > 0 && $order_total != 0 || $coupon->RecordCount() > 0 && $coupon->fields['coupon_type'] == 'S') {
             if ($coupon->fields['coupon_minimum_order'] <= $order_total) {
                 if ($coupon->fields['coupon_type'] == 'S') {
                     $od_amount['total'] = $order->info['shipping_cost'];
                     $od_amount['type'] = 'S';
                 } else {
                     if ($coupon->fields['coupon_type'] == 'P') {
                         $od_amount['total'] = zen_round($order_total * ($coupon->fields['coupon_amount'] / 100), 2);
                     } else {
                         $od_amount['total'] = $coupon->fields['coupon_amount'] * ($order_total > 0);
                     }
                     if ($od_amount['total'] > $order_total) {
                         $od_amount['total'] = $order_total;
                     }
                     $products = $_SESSION['cart']->get_products();
                     for ($i = 0; $i < sizeof($products); $i++) {
                         // speed up process and store value
                         $is_valid_results = is_product_valid($products[$i]['id'], $_SESSION['cc_id']);
                         if ($is_valid_results) {
                             if ($coupon->fields['coupon_type'] == 'P') {
                                 switch ($this->calculate_tax) {
                                     case 'Credit Note':
                                         $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $od_amount[$tax_desc] = $od_amount['total'] / 100 * $tax_rate;
                                         $od_amount['tax'] += $od_amount[$tax_desc];
                                         break;
                                     case 'Standard':
                                         $ratio = $od_amount['total'] / $this->get_order_total();
                                         $products = $_SESSION['cart']->get_products();
                                         for ($j = 0; $j < sizeof($products); $j++) {
                                             $t_prid = zen_get_prid($products[$j]['id']);
                                             $cc_result = $db->Execute("select products_tax_class_id\n                                                   from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
                                             if ($is_valid_results) {
                                                 $tax_rate = zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                                 $tax_desc = zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                                 if ($tax_rate > 0) {
                                                     //                            $od_amount[$tax_desc] += (($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate)/100 * $ratio;
                                                     $od_amount[$tax_desc] += round(($products[$j]['final_price'] * $products[$j]['quantity'] * $tax_rate + 0.5) / 100 * $ratio, 2);
                                                     $od_amount['tax'] += $od_amount[$tax_desc];
                                                 }
                                             }
                                         }
                                         break;
                                     default:
                                 }
                             }
                             if ($coupon->fields['coupon_type'] == 'F') {
                                 switch ($this->calculate_tax) {
                                     case 'Credit Note':
                                         $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                                         $od_amount[$tax_desc] = $od_amount['total'] / 100 * $tax_rate;
                                         $od_amount['tax'] += $od_amount[$tax_desc];
                                         break;
                                     case 'Standard':
                                         $ratio = $od_amount['total'] / $this->get_order_total();
                                         $products = $_SESSION['cart']->get_products();
                                         for ($j = 0; $j < sizeof($products); $j++) {
                                             $t_prid = zen_get_prid($products[$j]['id']);
                                             $cc_result = $db->Execute("select products_tax_class_id\n                                                   from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
                                             if ($is_valid_results) {
                                                 $tax_rate = zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                                 $tax_desc = zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                                                 if ($tax_rate > 0) {
                                                     //                            $od_amount[$tax_desc] += (($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate)/100 * $ratio;
                                                     $od_amount[$tax_desc] += round(($products[$j]['final_price'] * $products[$j]['quantity'] * $tax_rate + 0.5) / 100 * $ratio, 2);
                                                     $od_amount['tax'] += $od_amount[$tax_desc];
                                                 }
                                             }
                                         }
                                         break;
                                     default:
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $od_amount;
 }
function eo_get_product_taxes($product, $shown_price = -1, $add = true)
{
    global $db, $currencies, $order;
    if (DISPLAY_PRICE_WITH_TAX == 'true') {
        $shown_price = (zen_round($product['final_price'], $currencies->get_decimal_places($_SESSION['currency'])) + zen_calculate_tax($product['final_price'], $product['tax'])) * $product['qty'];
        $shown_price += zen_round($product['onetime_charges'], $currencies->get_decimal_places($_SESSION['currency'])) + zen_calculate_tax($product['onetime_charges'], $product['tax']);
    } else {
        $shown_price = $product['final_price'] * $product['qty'];
        $shown_price += $product['onetime_charges'];
    }
    // Not standard Zen Cart - but clears up some math issues later
    $shown_price = zen_round($shown_price, $currencies->get_decimal_places($_SESSION['currency']));
    if (array_key_exists('tax_description', $product)) {
        $products_tax_description = $product['tax_description'];
    } else {
        $query = $db->Execute('SELECT `products_tax_class_id` ' . 'FROM `' . TABLE_PRODUCTS . '` WHERE `products_id`=\'' . (int) $product['id'] . '\' ');
        if (!$query->EOF) {
            $products_tax_description = zen_get_tax_description($query->fields['products_tax_class_id']);
        } else {
            if (array_key_exists('tax', $product)) {
                $products_tax_description = TEXT_UNKNOWN_TAX_RATE . ' (' . zen_display_tax_value($product['tax']) . '%)';
            }
        }
    }
    $totalTaxAdd = 0;
    if (zen_not_null($products_tax_description)) {
        $taxAdd = 0;
        // Done this way to ensure we calculate
        if (DISPLAY_PRICE_WITH_TAX == 'true') {
            $taxAdd = $shown_price - $shown_price / ($product['tax'] < 10 ? "1.0" . str_replace('.', '', $product['tax']) : "1." . str_replace('.', '', $product['tax']));
        } else {
            $taxAdd = zen_calculate_tax($shown_price, $product['tax']);
        }
        if (isset($order->info['tax_groups'][$products_tax_description])) {
            if ($add) {
                $order->info['tax_groups'][$products_tax_description] += $taxAdd;
            } else {
                $order->info['tax_groups'][$products_tax_description] -= $taxAdd;
            }
        } else {
            if ($add) {
                $order->info['tax_groups'][$products_tax_description] = $taxAdd;
            }
        }
        $totalTaxAdd += $taxAdd;
        unset($taxAdd);
    }
    return $totalTaxAdd;
}
Example #14
0
 function calculate_tax_deduction($amount, $od_amount, $method, $finalise = false)
 {
     global $order;
     $tax_address = zen_get_tax_locations();
     switch ($method) {
         case 'Standard':
             $ratio1 = zen_round($od_amount / $amount, 2);
             $tod_amount = 0;
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = zen_get_tax_rate_from_desc($key, $tax_address['country_id'], $tax_address['zone_id']);
                 $total_net += $tax_rate * $value;
             }
             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 = zen_get_tax_rate_from_desc($key, $tax_address['country_id'], $tax_address['zone_id']);
                 $net = $tax_rate * $value;
                 if ($net > 0) {
                     $god_amount = $value * $ratio1;
                     $tod_amount += $god_amount;
                     if ($finalise) {
                         $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                     }
                 }
             }
             if ($finalise) {
                 $order->info['tax'] -= $tod_amount;
             }
             if ($finalise) {
                 $order->info['total'] -= $tod_amount;
             }
             break;
         case 'Credit Note':
             $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
             $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
             $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate;
             if ($finalise) {
                 $order->info['tax_groups'][$tax_desc] -= $tod_amount;
             }
             if ($finalise) {
                 $order->info['tax'] -= $tod_amount;
             }
             if ($finalise) {
                 $order->info['total'] -= $tod_amount;
             }
             break;
         default:
     }
     return $tod_amount;
 }
Example #15
0
 function get_order_total($couponCode)
 {
     global $order;
     $orderTaxGroups = $order->info['tax_groups'];
     $orderTotalTax = $order->info['tax'];
     $orderTotal = $order->info['total'];
     // left for total order amount vs qualified order amount just switch the commented lines
     $orderTotalFull = $orderTotal;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0; $i < sizeof($products); $i++) {
         if (!is_product_valid($products[$i]['id'], $couponCode)) {
             $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']);
             $productsTaxAmount = zen_calculate_tax($products[$i]['final_price'], $products_tax) * $products[$i]['quantity'];
             $orderTotal -= $products[$i]['final_price'] * $products[$i]['quantity'];
             if ($this->include_tax == 'true') {
                 $orderTotal -= $productsTaxAmount;
             }
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $orderTotal -= $productsTaxAmount;
             }
             $orderTaxGroups[zen_get_tax_description($products[$i]['tax_class_id'])] -= $productsTaxAmount;
             $orderTotalTax -= zen_calculate_tax($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id'])) * $products[$i]['quantity'];
         }
     }
     if ($this->include_shipping != 'true') {
         $orderTotal -= $order->info['shipping_cost'];
         if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
             $orderTaxGroups[$_SESSION['shipping_tax_description']] -= $order->info['shipping_tax'];
             $orderTotalTax -= $order->info['shipping_tax'];
         }
     }
     if (DISPLAY_PRICE_WITH_TAX != 'true') {
         $orderTotal -= $order->info['tax'];
     }
     // left for total order amount vs qualified order amount - $orderTotalFull
     return array('totalFull' => $orderTotalFull, 'orderTotal' => $orderTotal, 'orderTaxGroups' => $orderTaxGroups, 'orderTax' => $orderTotalTax, 'shipping' => $order->info['shipping_cost'], 'shippingTax' => $order->info['shipping_tax']);
 }
Example #16
0
 function cart()
 {
     global $db, $currencies;
     $decimals = $currencies->get_decimal_places($_SESSION['currency']);
     $this->content_type = $_SESSION['cart']->get_content_type();
     /* Dual Pricing start */
     $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_whole,\n/* Dual Pricing end */\n                                    c.customers_email_address, ab.entry_company, ab.entry_street_address,\n                                    ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,\n                                    z.zone_name, co.countries_id, co.countries_name,\n                                    co.countries_iso_code_2, co.countries_iso_code_3,\n                                    co.address_format_id, ab.entry_state\n                                   from (" . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab )\n                                   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                                   where c.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                   and ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                   and c.customers_default_address_id = ab.address_book_id";
     $customer_address = $db->Execute($customer_address_query);
     $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n                                    ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n                                    ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n                                    c.countries_id, c.countries_name, c.countries_iso_code_2,\n                                    c.countries_iso_code_3, c.address_format_id, ab.entry_state\n                                   from " . TABLE_ADDRESS_BOOK . " ab\n                                   left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                   left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n                                   where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                   and ab.address_book_id = '" . (int) $_SESSION['sendto'] . "'";
     $shipping_address = $db->Execute($shipping_address_query);
     $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n                                   ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n                                   ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n                                   c.countries_id, c.countries_name, c.countries_iso_code_2,\n                                   c.countries_iso_code_3, c.address_format_id, ab.entry_state\n                                  from " . TABLE_ADDRESS_BOOK . " ab\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                  left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
     $billing_address = $db->Execute($billing_address_query);
     // set default tax calculation for not-logged-in visitors
     $taxCountryId = $taxZoneId = 0;
     // get tax zone info for logged-in visitors
     if (isset($_SESSION['customer_id']) && (int) $_SESSION['customer_id'] > 0) {
         $taxCountryId = $taxZoneId = -1;
         $tax_address_query = '';
         switch (STORE_PRODUCT_TAX_BASIS) {
             case 'Shipping':
                 $tax_address_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 = '" . (int) $_SESSION['customer_id'] . "'\n                                and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
                 break;
             case 'Billing':
                 $tax_address_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 = '" . (int) $_SESSION['customer_id'] . "'\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
                 break;
             case 'Store':
                 if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) {
                     $tax_address_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 = '" . (int) $_SESSION['customer_id'] . "'\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
                 } else {
                     $tax_address_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 = '" . (int) $_SESSION['customer_id'] . "'\n                                  and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
                 }
         }
         if ($tax_address_query != '') {
             $tax_address = $db->Execute($tax_address_query);
             if ($tax_address->recordCount() > 0) {
                 $taxCountryId = $tax_address->fields['entry_country_id'];
                 $taxZoneId = $tax_address->fields['entry_zone_id'];
             }
         }
     }
     $class =& $_SESSION['payment'];
     if (isset($_SESSION['cc_id'])) {
         $coupon_code_query = "select coupon_code\n                              from " . TABLE_COUPONS . "\n                              where coupon_id = '" . (int) $_SESSION['cc_id'] . "'";
         $coupon_code = $db->Execute($coupon_code_query);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'payment_module_code' => $GLOBALS[$class]->code, 'coupon_code' => $coupon_code->fields['coupon_code'], 'shipping_method' => isset($_SESSION['shipping']['title']) ? $_SESSION['shipping']['title'] : '', 'shipping_module_code' => isset($_SESSION['shipping']['id']) && strpos($_SESSION['shipping']['id'], '_') > 0 ? $_SESSION['shipping']['id'] : $_SESSION['shipping'], 'shipping_cost' => isset($_SESSION['shipping']['cost']) ? $_SESSION['shipping']['cost'] : 0, 'subtotal' => 0, 'shipping_tax' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);
     //print_r($GLOBALS[$class]);
     //echo $class;
     //print_r($GLOBALS);
     //echo $_SESSION['payment'];
     /*
     // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder
     if (isset(${$_SESSION['payment']}) && is_object(${$_SESSION['payment']})) {
     $this->info['payment_method'] = ${$_SESSION['payment']}->title;
     }
     */
     /*
     // bof: move below calculations
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
         if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
           if ( isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && ($GLOBALS[$class]->order_status > 0) ) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
           }
         }
     // eof: move below calculations
     */
     $this->customer = array('firstname' => $customer_address->fields['customers_firstname'], 'lastname' => $customer_address->fields['customers_lastname'], 'company' => $customer_address->fields['entry_company'], 'street_address' => $customer_address->fields['entry_street_address'], 'suburb' => $customer_address->fields['entry_suburb'], 'city' => $customer_address->fields['entry_city'], 'postcode' => $customer_address->fields['entry_postcode'], 'state' => zen_not_null($customer_address->fields['entry_state']) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name'], 'zone_id' => $customer_address->fields['entry_zone_id'], 'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']), 'format_id' => (int) $customer_address->fields['address_format_id'], 'telephone' => $customer_address->fields['customers_telephone'], 'email_address' => $customer_address->fields['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'], 'lastname' => $shipping_address->fields['entry_lastname'], 'company' => $shipping_address->fields['entry_company'], 'street_address' => $shipping_address->fields['entry_street_address'], 'suburb' => $shipping_address->fields['entry_suburb'], 'city' => $shipping_address->fields['entry_city'], 'postcode' => $shipping_address->fields['entry_postcode'], 'state' => zen_not_null($shipping_address->fields['entry_state']) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name'], 'zone_id' => $shipping_address->fields['entry_zone_id'], 'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']), 'country_id' => $shipping_address->fields['entry_country_id'], 'format_id' => (int) $shipping_address->fields['address_format_id']);
     $this->billing = array('firstname' => $billing_address->fields['entry_firstname'], 'lastname' => $billing_address->fields['entry_lastname'], 'company' => $billing_address->fields['entry_company'], 'street_address' => $billing_address->fields['entry_street_address'], 'suburb' => $billing_address->fields['entry_suburb'], 'city' => $billing_address->fields['entry_city'], 'postcode' => $billing_address->fields['entry_postcode'], 'state' => zen_not_null($billing_address->fields['entry_state']) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name'], 'zone_id' => $billing_address->fields['entry_zone_id'], 'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']), 'country_id' => $billing_address->fields['entry_country_id'], 'format_id' => (int) $billing_address->fields['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         if ($i / 2 == floor($i / 2)) {
             $rowClass = "rowEven";
         } else {
             $rowClass = "rowOdd";
         }
         $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId);
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax_groups' => $taxRates, 'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId), 'price' => $products[$i]['price'], 'final_price' => zen_round($products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), $decimals), 'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']), 'weight' => $products[$i]['weight'], 'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'], 'product_is_free' => $products[$i]['product_is_free'], 'products_discount_type' => $products[$i]['products_discount_type'], 'products_discount_type_from' => $products[$i]['products_discount_type_from'], 'id' => $products[$i]['id'], 'rowClass' => $rowClass);
         if (STORE_PRODUCT_TAX_BASIS == 'Shipping' && isset($_SESSION['shipping']['id']) && stristr($_SESSION['shipping']['id'], 'storepickup') == TRUE) {
             $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], STORE_COUNTRY, STORE_ZONE);
             $this->products[$index]['tax'] = zen_get_tax_rate($products[$i]['tax_class_id'], STORE_COUNTRY, STORE_ZONE);
         } else {
             $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId);
             $this->products[$index]['tax'] = zen_get_tax_rate($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId);
         }
         $this->notify('NOTIFY_ORDER_CART_ADD_PRODUCT_LIST', array('index' => $index, 'products' => $products[$i]));
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 /*
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){
                 $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                 $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 */
                 $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n                                          pa.options_values_price, pa.price_prefix\n                                   from " . TABLE_PRODUCTS_OPTIONS . " popt,\n                                        " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,\n                                        " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n                                   where pa.products_id = '" . (int) $products[$i]['id'] . "'\n                                   and pa.options_id = '" . (int) $option . "'\n                                   and pa.options_id = popt.products_options_id\n                                   and pa.options_values_id = '" . (int) $value . "'\n                                   and pa.options_values_id = poval.products_options_values_id\n                                   and popt.language_id = '" . (int) $_SESSION['languages_id'] . "'\n                                   and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'";
                 $attributes = $db->Execute($attributes_query);
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                     $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                     $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes->fields['price_prefix'], 'price' => $attributes->fields['options_values_price']);
                 $this->notify('NOTIFY_ORDER_CART_ADD_ATTRIBUTE_LIST', array('index' => $index, 'subindex' => $subindex, 'products' => $products[$i], 'attributes' => $attributes));
                 $subindex++;
             }
         }
         // add onetime charges here
         //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])
         /**************************************
          * Check for external tax handling code
          **************************************/
         $this->use_external_tax_handler_only = FALSE;
         $this->notify('NOTIFY_ORDER_CART_EXTERNAL_TAX_HANDLING', array(), $index, $taxCountryId, $taxZoneId);
         if ($this->use_external_tax_handler_only == FALSE) {
             /*********************************************
              * Calculate taxes for this product
              *********************************************/
             $shown_price = zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']) + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
             $this->info['subtotal'] += $shown_price;
             $this->notify('NOTIFIY_ORDER_CART_SUBTOTAL_CALCULATE', array('shown_price' => $shown_price));
             // find product's tax rate and description
             $products_tax = $this->products[$index]['tax'];
             $products_tax_description = $this->products[$index]['tax_description'];
             // Dual Pricing start - no taxes for wholesale customers
             if ($customer_address->fields['customers_whole'] > 0) {
                 $products_tax = 0;
                 $this->products[$index]['tax'] = 0;
                 $tax_add = 0;
                 $this->products[$index]['tax_description'] = '';
             }
             if ($customer_address->fields['customers_whole'] == 0) {
                 // Dual pricing end -  no taxes for wholesale customers
                 if (DISPLAY_PRICE_WITH_TAX == 'true') {
                     // calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled)
                     $tax_add = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                 } else {
                     // calculate the amount of tax for this product (assuming tax is NOT included in the price)
                     //        $tax_add = zen_round(($products_tax / 100) * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']);
                     $tax_add = $products_tax / 100 * $shown_price;
                 }
                 $this->info['tax'] += $tax_add;
                 foreach ($taxRates as $taxDescription => $taxRate) {
                     $taxAdd = zen_calculate_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $taxRate) + zen_calculate_tax($this->products[$index]['onetime_charges'], $taxRate);
                     if (isset($this->info['tax_groups'][$taxDescription])) {
                         $this->info['tax_groups'][$taxDescription] += $taxAdd;
                     } else {
                         $this->info['tax_groups'][$taxDescription] = $taxAdd;
                     }
                 }
                 //Dual Pricing start -  no taxes for wholesale customers
             }
             // Dual pricing end -  no taxes for wholesale customers
             /*********************************************
              * END: Calculate taxes for this product
              *********************************************/
         }
         $index++;
     }
     // Update the final total to include tax if not already tax-inc
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
     } else {
         $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
     }
     /*
     // moved to function create
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
     */
     if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
         if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
         }
     }
     $this->notify('NOTIFY_ORDER_CART_FINISHED');
 }
Example #17
0
 function cart()
 {
     global $gBitDb, $currencies, $gBitUser, $gBitCustomer;
     $this->content_type = $gBitCustomer->mCart->get_content_type();
     if ($gBitUser->isRegistered()) {
         $customer_address_query = "SELECT ab.`entry_firstname`, ab.`entry_lastname`, ab.`entry_telephone`, c.`customers_id`, 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`, ab.`address_book_id`\n\t\t\t\t\t\t\t\t\t FROM " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . TABLE_ZONES . " z on (ab.`entry_zone_id` = z.`zone_id`)\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . TABLE_COUNTRIES . " co on (ab.`entry_country_id` = co.`countries_id`)\n\t\t\t\t\t\t\t\t\t WHERE c.`customers_id` = ? AND ab.`customers_id` = ?  AND c.`customers_default_address_id` = ab.`address_book_id`";
         $defaultAddress = $gBitDb->getRow($customer_address_query, array($gBitUser->mUserId, $gBitUser->mUserId));
         // default to primary address in case we have ended up here without anything previously selected
         $sendToAddressId = !empty($_SESSION['sendto']) ? (int) $_SESSION['sendto'] : (!empty($defaultAddress['address_book_id']) ? $defaultAddress['address_book_id'] : NULL);
         if ($sendToAddressId) {
             $query = "SELECT ab.*, 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`\n\t\t\t\t\t\t FROM " . TABLE_ADDRESS_BOOK . " ab\n\t\t\t\t\t\t\t LEFT JOIN " . TABLE_ZONES . " z on (ab.`entry_zone_id` = z.`zone_id`)\n\t\t\t\t\t\t\t LEFT JOIN " . TABLE_COUNTRIES . " c on (ab.`entry_country_id` = c.`countries_id`)\n\t\t\t\t\t\t WHERE ab.`customers_id`=? AND ab.`address_book_id`=?";
             $shippingAddress = $gBitDb->getRow($query, array($gBitUser->mUserId, $sendToAddressId));
             if (!$shippingAddress) {
                 $shippingAddress = $defaultAddress;
             }
         }
         // default to primary address in case we have ended up here without anything previously selected
         $billToAddressId = !empty($_SESSION['billto']) ? (int) $_SESSION['billto'] : (!empty($defaultAddress['address_book_id']) ? $defaultAddress['address_book_id'] : NULL);
         if ($billToAddressId) {
             $query = "SELECT ab.*, 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`\n\t\t\t\t\t\t\tFROM " . TABLE_ADDRESS_BOOK . " ab\n\t\t\t\t\t\t\tLEFT JOIN " . TABLE_ZONES . " z on (ab.`entry_zone_id` = z.`zone_id`)\n\t\t\t\t\t\t\tLEFT JOIN " . TABLE_COUNTRIES . " c on (ab.`entry_country_id` = c.`countries_id`)\n\t\t\t\t\t\t\tWHERE ab.`customers_id` = ?\tand ab.`address_book_id` = ?";
             $billingAddress = $gBitDb->getRow($query, array($gBitUser->mUserId, $billToAddressId));
         }
         switch (STORE_PRODUCT_TAX_BASIS) {
             case 'Shipping':
                 $taxAddressId = $this->content_type == 'virtual' ? $billToAddressId : $sendToAddressId;
                 break;
             case 'Billing':
                 $taxAddressId = $billToAddressId;
                 break;
             case 'Store':
                 if ($billingAddress['entry_zone_id'] == STORE_ZONE) {
                     $taxAddressId = (int) $billToAddressId;
                 } else {
                     $taxAddressId = (int) ($this->content_type == 'virtual' ? $billToAddressId : $sendToAddressId);
                 }
                 break;
         }
         //STORE_PRODUCT_TAX_BASIS
         if (!empty($taxAddressId)) {
             $tax_address_query = "SELECT ab.entry_country_id, ab.entry_zone_id, ab.`entry_state`\n\t\t\t\t\t\t\t\t\t  FROM " . TABLE_ADDRESS_BOOK . " ab\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . TABLE_ZONES . " z on (ab.`entry_zone_id` = z.`zone_id`)\n\t\t\t\t\t\t\t\t\t  WHERE ab.`customers_id` = ?  and ab.`address_book_id` = ?";
             $tax_address = $gBitDb->getAssoc($tax_address_query, array($gBitUser->mUserId, $taxAddressId));
         }
         if (!empty($taxAddress['entry_country_id']) && empty($taxAddress['entry_zone_id'])) {
             if ($gBitCustomer->getZoneCount($taxAddress['entry_country_id']) && ($zoneId = $gBitCustomer->getZoneId($taxAddress['entry_state'], $taxAddress['entry_country_id']))) {
                 $taxAddress['entry_zone_id'] = $zoneId;
             }
             // maybe we have some newly updated zones and outdated address_book entries
         } else {
             $taxAddress = $defaultAddress;
         }
     }
     $class =& $_SESSION['payment'];
     $coupon_code = NULL;
     if (!empty($_SESSION['cc_id'])) {
         $coupon_code_query = "SELECT `coupon_code` FROM " . TABLE_COUPONS . " WHERE `coupon_id` = ?";
         $coupon_code = $gBitDb->GetOne($coupon_code_query, array((int) $_SESSION['cc_id']));
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => !empty($_SESSION['currency']) ? $_SESSION['currency'] : NULL, 'currency_value' => !empty($_SESSION['currency']) ? $currencies->currencies[$_SESSION['currency']]['currency_value'] : NULL, 'payment_method' => !empty($GLOBALS[$class]) ? $GLOBALS[$class]->title : '', 'payment_module_code' => !empty($GLOBALS[$class]) ? $GLOBALS[$class]->code : '', 'coupon_code' => $coupon_code, 'shipping_method' => !empty($_SESSION['shipping']['title']) ? $_SESSION['shipping']['title'] : '', 'shipping_method_code' => !empty($_SESSION['shipping']['code']) ? $_SESSION['shipping']['code'] : '', 'shipping_module_code' => !empty($_SESSION['shipping']['id']) ? $_SESSION['shipping']['id'] : '', 'shipping_cost' => !empty($_SESSION['shipping']['cost']) ? $_SESSION['shipping']['cost'] : '', 'subtotal' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SERVER['REMOTE_ADDR']);
     if ($this->info['total'] == 0) {
         if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
         } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
         }
     }
     if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
         if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
         }
     }
     if (!empty($defaultAddress)) {
         $this->customer = array('firstname' => $defaultAddress['entry_firstname'], 'lastname' => $defaultAddress['entry_lastname'], 'customers_id' => $defaultAddress['customers_id'], 'user_id' => $defaultAddress['customers_id'], 'company' => $defaultAddress['entry_company'], 'street_address' => $defaultAddress['entry_street_address'], 'suburb' => $defaultAddress['entry_suburb'], 'city' => $defaultAddress['entry_city'], 'postcode' => $defaultAddress['entry_postcode'], 'state' => zen_not_null($defaultAddress['entry_state']) ? $defaultAddress['entry_state'] : $defaultAddress['zone_name'], 'zone_id' => $defaultAddress['entry_zone_id'], 'country' => array('countries_name' => $defaultAddress['countries_name'], 'countries_id' => $defaultAddress['countries_id'], 'countries_iso_code_2' => $defaultAddress['countries_iso_code_2'], 'countries_iso_code_3' => $defaultAddress['countries_iso_code_3']), 'format_id' => $defaultAddress['address_format_id'], 'telephone' => $defaultAddress['entry_telephone'], 'email_address' => $defaultAddress['customers_email_address']);
     }
     if (!empty($shippingAddress)) {
         $this->delivery = array('firstname' => $shippingAddress['entry_firstname'], 'lastname' => $shippingAddress['entry_lastname'], 'company' => $shippingAddress['entry_company'], 'street_address' => $shippingAddress['entry_street_address'], 'suburb' => $shippingAddress['entry_suburb'], 'city' => $shippingAddress['entry_city'], 'postcode' => $shippingAddress['entry_postcode'], 'state' => zen_not_null($shippingAddress['entry_state']) ? $shippingAddress['entry_state'] : $shippingAddress['zone_name'], 'zone_id' => $shippingAddress['entry_zone_id'], 'country' => array('countries_id' => $shippingAddress['countries_id'], 'countries_name' => $shippingAddress['countries_name'], 'countries_iso_code_2' => $shippingAddress['countries_iso_code_2'], 'countries_iso_code_3' => $shippingAddress['countries_iso_code_3']), 'country_id' => $shippingAddress['entry_country_id'], 'telephone' => $shippingAddress['entry_telephone'], 'format_id' => $shippingAddress['address_format_id']);
     }
     if (!empty($billingAddress)) {
         $this->billing = array('firstname' => $billingAddress['entry_firstname'], 'lastname' => $billingAddress['entry_lastname'], 'company' => $billingAddress['entry_company'], 'street_address' => $billingAddress['entry_street_address'], 'suburb' => $billingAddress['entry_suburb'], 'city' => $billingAddress['entry_city'], 'postcode' => $billingAddress['entry_postcode'], 'state' => zen_not_null($billingAddress['entry_state']) ? $billingAddress['entry_state'] : $billingAddress['zone_name'], 'zone_id' => $billingAddress['entry_zone_id'], 'country' => array('countries_id' => $billingAddress['countries_id'], 'countries_name' => $billingAddress['countries_name'], 'countries_iso_code_2' => $billingAddress['countries_iso_code_2'], 'countries_iso_code_3' => $billingAddress['countries_iso_code_3']), 'country_id' => $billingAddress['entry_country_id'], 'telephone' => $billingAddress['entry_telephone'], 'format_id' => $billingAddress['address_format_id']);
     }
     foreach (array_keys($gBitCustomer->mCart->contents) as $productsKey) {
         $this->contents[$productsKey] = $gBitCustomer->mCart->getProductHash($productsKey);
         if (!empty($taxAddress)) {
             $this->contents[$productsKey]['tax'] = zen_get_tax_rate($this->contents[$productsKey]['tax_class_id'], $taxAddress['countries_id'], $taxAddress['entry_zone_id']);
             $this->contents[$productsKey]['tax_description'] = zen_get_tax_description($this->contents[$productsKey]['tax_class_id'], $taxAddress['countries_id'], $taxAddress['entry_zone_id']);
         }
         if (!empty($this->contents[$productsKey]['attributes'])) {
             $attributes = $this->contents[$productsKey]['attributes'];
             $this->contents[$productsKey]['attributes'] = array();
             $subindex = 0;
             foreach ($attributes as $option => $value) {
                 $optionValues = zen_get_option_value(zen_get_options_id($option), (int) $value);
                 // Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                     $attr_value = $this->contents[$productsKey]['attributes_values'][$option];
                 } else {
                     $attr_value = $optionValues['products_options_values_name'];
                 }
                 $this->contents[$productsKey]['attributes'][$subindex] = array('option' => $optionValues['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $optionValues['price_prefix'], 'price' => $optionValues['options_values_price']);
                 $subindex++;
             }
         }
         $shown_price = zen_add_tax($this->contents[$productsKey]['final_price'], $this->contents[$productsKey]['tax']) * $this->contents[$productsKey]['products_quantity'] + zen_add_tax($this->contents[$productsKey]['onetime_charges'], $this->contents[$productsKey]['tax']);
         $this->subtotal += $shown_price;
         $products_tax = $this->contents[$productsKey]['tax'];
         $products_tax_description = $this->contents[$productsKey]['tax_description'];
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $this->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             }
         } else {
             $this->info['tax'] += $products_tax / 100 * $shown_price;
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $products_tax / 100 * $shown_price;
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $products_tax / 100 * $shown_price;
             }
         }
         $this->info['tax'] = zen_round($this->info['tax'], 2);
     }
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         $this->info['total'] = $this->subtotal + $this->info['shipping_cost'];
     } else {
         $this->info['total'] = $this->subtotal + $this->info['tax'] + $this->info['shipping_cost'];
     }
 }