Example #1
0
 function query($order_id)
 {
     $order_query = tep_db_query("select * from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'");
     $order = tep_db_fetch_array($order_query);
     $totals_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int) $order_id . "' order by sort_order");
     while ($totals = tep_db_fetch_array($totals_query)) {
         $this->totals[] = array('title' => $totals['title'], 'text' => $totals['text'], 'class' => $totals['class'], 'value' => $totals['value'], 'sort_order' => $totals['sort_order'], 'orders_total_id' => $totals['orders_total_id']);
     }
     $this->info = array('currency' => $order['currency'], 'currency_value' => $order['currency_value'], 'payment_method' => $order['payment_method'], 'cc_type' => $order['cc_type'], 'cc_owner' => $order['cc_owner'], 'cc_number' => $order['cc_number'], 'cc_expires' => $order['cc_expires'], 'shipping_tax' => $order['shipping_tax'], 'date_purchased' => $order['date_purchased'], 'orders_status' => $order['orders_status'], 'last_modified' => $order['last_modified']);
     $this->customer = array('name' => $order['customers_name'], 'company' => $order['customers_company'], 'street_address' => $order['customers_street_address'], 'suburb' => $order['customers_suburb'], 'city' => $order['customers_city'], 'postcode' => $order['customers_postcode'], 'state' => $order['customers_state'], 'country' => $order['customers_country'], 'format_id' => $order['customers_address_format_id'], 'telephone' => $order['customers_telephone'], 'email_address' => $order['customers_email_address']);
     $this->delivery = array('name' => $order['delivery_name'], 'company' => $order['delivery_company'], 'street_address' => $order['delivery_street_address'], 'suburb' => $order['delivery_suburb'], 'city' => $order['delivery_city'], 'postcode' => $order['delivery_postcode'], 'state' => $order['delivery_state'], 'country' => $order['delivery_country'], 'format_id' => $order['delivery_address_format_id']);
     $this->billing = array('name' => $order['billing_name'], 'company' => $order['billing_company'], 'street_address' => $order['billing_street_address'], 'suburb' => $order['billing_suburb'], 'city' => $order['billing_city'], 'postcode' => $order['billing_postcode'], 'state' => $order['billing_state'], 'country' => $order['billing_country'], 'format_id' => $order['billing_address_format_id']);
     $countryid = tep_get_country_id($this->delivery["country"]);
     $zoneid = tep_get_zone_id($countryid, $this->delivery["state"]);
     $index = 0;
     $orders_products_query = tep_db_query("\n     SELECT \n\t op.orders_products_id, \n\t op.products_name, \n\t op.products_model, \n\t op.products_price,\n\t op.products_tax, \n\t op.products_quantity, \n\t op.final_price, \n\t p.products_tax_class_id,\n\t p.products_weight\n  FROM " . TABLE_ORDERS_PRODUCTS . " op\n  LEFT JOIN " . TABLE_PRODUCTS . " p\n    ON op.products_id = p.products_id\n WHERE orders_id = '" . (int) $order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
         $this->products[$index] = array('qty' => $orders_products['products_quantity'], 'name' => $orders_products['products_name'], 'model' => $orders_products['products_model'], 'tax' => $orders_products['products_tax'], 'tax_description' => tep_get_tax_description($orders_products['products_tax_class_id'], $countryid, $zoneid), 'price' => $orders_products['products_price'], 'final_price' => $orders_products['final_price'], 'weight' => $orders_products['products_weight'], 'orders_products_id' => $orders_products['orders_products_id']);
         $subindex = 0;
         $attributes_query = tep_db_query("select * from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int) $order_id . "' and orders_products_id = '" . (int) $orders_products['orders_products_id'] . "'");
         if (tep_db_num_rows($attributes_query)) {
             while ($attributes = tep_db_fetch_array($attributes_query)) {
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price'], 'orders_products_attributes_id' => $attributes['orders_products_attributes_id']);
                 $subindex++;
             }
         }
         $index++;
     }
 }
 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) {
             $tax = tep_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_description = tep_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             $order->info['tax_groups']["{$tax_description}"] += tep_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             $order->info['total'] += MODULE_ORDER_TOTAL_LOWORDERFEE_FEE + tep_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             $this->output[] = array('title' => $this->title . ':', 'text' => $currencies->format(tep_add_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax), true, $order->info['currency'], $order->info['currency_value']), 'value' => tep_add_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax));
         }
     }
 }
Example #3
0
 function process()
 {
     global $order, $currencies;
     if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         $pass = false;
         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'] = OSCOM::getDef('free_shipping_title');
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     if (strpos($_SESSION['shipping']['id'], '\\') !== false) {
         list($vendor, $app, $module) = explode('\\', $_SESSION['shipping']['id']);
         list($module, $method) = explode('_', $module);
         $module = $vendor . '\\' . $app . '\\' . $module;
         $code = 'Shipping_' . str_replace('\\', '_', $module);
         if (Registry::exists($code)) {
             $OSCOM_SM = Registry::get($code);
         }
     } else {
         list($module, $method) = explode('_', $_SESSION['shipping']['id']);
         if (is_object($GLOBALS[$module])) {
             $OSCOM_SM = $GLOBALS[$module];
         }
     }
     if (tep_not_null($order->info['shipping_method'])) {
         if ($OSCOM_SM->tax_class > 0) {
             $shipping_tax = tep_get_tax_rate($OSCOM_SM->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = tep_get_tax_description($OSCOM_SM->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $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 #4
0
 function query($order_id)
 {
     global $shipping;
     $order_query = tep_db_query("select * from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'");
     $order = tep_db_fetch_array($order_query);
     $totals_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int) $order_id . "' order by sort_order");
     while ($totals = tep_db_fetch_array($totals_query)) {
         $this->totals[] = array('title' => $totals['title'], 'text' => $totals['text'], 'class' => $totals['class'], 'value' => $totals['value'], 'sort_order' => $totals['sort_order'], 'orders_total_id' => $totals['orders_total_id']);
     }
     $this->info = array('currency' => $order['currency'], 'currency_value' => $order['currency_value'], 'payment_method' => $order['payment_method'], 'cc_type' => $order['cc_type'], 'cc_owner' => $order['cc_owner'], 'cc_number' => $order['cc_number'], 'cc_expires' => $order['cc_expires'], 'date_purchased' => $order['date_purchased'], 'orders_status' => $order['orders_status'], 'last_modified' => $order['last_modified'], 'shipping_method' => $shipping['title'], 'shipping_cost' => $shipping['cost'], 'shipping_id' => $order['shipping_module'], 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array());
     $this->customer = array('id' => $order['customers_id'], 'name' => $order['customers_name'], 'company' => $order['customers_company'], 'street_address' => $order['customers_street_address'], 'suburb' => $order['customers_suburb'], 'city' => $order['customers_city'], 'postcode' => $order['customers_postcode'], 'state' => $order['customers_state'], 'country' => $order['customers_country'], 'country_id' => oe_get_country_id($order['customers_country']), 'zone_id' => oe_get_zone_id(oe_get_country_id($order['customers_country']), $order['customers_state']), 'format_id' => $order['customers_address_format_id'], 'telephone' => $order['customers_telephone'], 'email_address' => $order['customers_email_address']);
     $this->delivery = array('name' => $order['delivery_name'], 'company' => $order['delivery_company'], 'street_address' => $order['delivery_street_address'], 'suburb' => $order['delivery_suburb'], 'city' => $order['delivery_city'], 'postcode' => $order['delivery_postcode'], 'state' => $order['delivery_state'], 'country' => $order['delivery_country'], 'country_id' => oe_get_country_id($order['delivery_country']), 'zone_id' => oe_get_zone_id(oe_get_country_id($order['delivery_country']), $order['delivery_state']), 'format_id' => $order['delivery_address_format_id']);
     $this->billing = array('name' => $order['billing_name'], 'company' => $order['billing_company'], 'street_address' => $order['billing_street_address'], 'suburb' => $order['billing_suburb'], 'city' => $order['billing_city'], 'postcode' => $order['billing_postcode'], 'state' => $order['billing_state'], 'country' => $order['billing_country'], 'country_id' => oe_get_country_id($order['billing_country']), 'zone_id' => oe_get_zone_id(oe_get_country_id($order['billing_country']), $order['billing_state']), 'format_id' => $order['billing_address_format_id']);
     $index = 0;
     $orders_products_query = tep_db_query("select op.orders_products_id, op.products_id, op.products_name, op.products_model, op.products_code, op.products_price, op.products_tax, op.products_quantity, op.final_price, p.products_tax_class_id, p.products_weight, p.products_id from " . TABLE_ORDERS_PRODUCTS . " op INNER JOIN " . TABLE_PRODUCTS . " p on op.products_id = p.products_id where orders_id = '" . (int) $order_id . "' order by op.orders_products_id");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
         $orders_products_tax_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = " . $orders_products['products_id'] . "");
         $orders_products_tax = tep_db_fetch_array($orders_products_tax_query);
         $this->products[$index] = array('qty' => $orders_products['products_quantity'], 'name' => $orders_products['products_name'], 'model' => $orders_products['products_model'], 'code' => $orders_products['products_code'], 'tax' => $orders_products['products_tax'], 'tax_description' => tep_get_tax_description($orders_products_tax['products_tax_class_id'], $this->delivery["country_id"], $this->delivery["zone_id"]), 'price' => $orders_products['products_price'], 'final_price' => $orders_products['final_price'], 'weight' => $orders_products['products_weight'], 'products_id' => $orders_products['products_id'], 'orders_products_id' => $orders_products['orders_products_id']);
         $subindex = 0;
         $attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix, orders_products_attributes_id from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int) $order_id . "' and orders_products_id = '" . (int) $orders_products['orders_products_id'] . "'");
         if (tep_db_num_rows($attributes_query)) {
             while ($attributes = tep_db_fetch_array($attributes_query)) {
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price'], 'orders_products_attributes_id' => $attributes['orders_products_attributes_id']);
                 $subindex++;
             }
         }
         $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];
         $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;
             }
         }
         $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 #5
0
 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;
         }
         /* One Page Checkout - BEGIN */
         /*        if ( ($pass == true) && ( ($order->info['subtotal'] - $order->info['shipping_cost']) >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
                   $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
                   $order->info['total'] -= $order->info['shipping_cost'];
                   $order->info['shipping_cost'] = 0;
                 }
         */
         if (ONEPAGE_CHECKOUT_ENABLED != 'True') {
             if ($pass == true && $order->info['subtotal'] - $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
                 $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
                 $order->info['total'] -= $order->info['shipping_cost'];
                 $order->info['shipping_cost'] = 0;
             }
         }
         /* One Page Checkout - END */
     }
     $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
     if (tep_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = tep_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $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;
     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'] = FREE_SHIPPING_TITLE;
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
     if (tep_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = tep_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $search = array(' regimark', ' tradmrk');
         $replace = array('<sup>&reg;</sup>', '<sup>&trade;</sup>');
         $this->output[] = array('title' => str_replace($search, $replace, $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 #7
0
 function process()
 {
     global $order, $currencies, $customer_group;
     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($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
     if (tep_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = tep_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if ($customer_group->gettax() == '1') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $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 #8
0
 function cart()
 {
     global $customer_id, $sendto, $billto, $currencies, $shipping, $payment, $comments, $customer_default_address_id;
     $this->content_type = $_SESSION['cart']->get_content_type();
     if ($this->content_type != 'virtual' && $sendto == false) {
         $sendto = $customer_default_address_id;
     }
     $customer_address_query = tep_db_query("select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id) where c.customers_id = '" . (int) $customer_id . "' and ab.customers_id = '" . (int) $customer_id . "' and c.customers_default_address_id = ab.address_book_id");
     $customer_address = tep_db_fetch_array($customer_address_query);
     if (is_array($sendto) && !empty($sendto)) {
         $shipping_address = array('entry_firstname' => $sendto['firstname'], 'entry_lastname' => $sendto['lastname'], 'entry_company' => $sendto['company'], 'entry_street_address' => $sendto['street_address'], 'entry_suburb' => $sendto['suburb'], 'entry_postcode' => $sendto['postcode'], 'entry_city' => $sendto['city'], 'entry_zone_id' => $sendto['zone_id'], 'zone_name' => $sendto['zone_name'], 'entry_country_id' => $sendto['country_id'], 'countries_id' => $sendto['country_id'], 'countries_name' => $sendto['country_name'], 'countries_iso_code_2' => $sendto['country_iso_code_2'], 'countries_iso_code_3' => $sendto['country_iso_code_3'], 'address_format_id' => $sendto['address_format_id'], 'entry_state' => $sendto['zone_name']);
     } elseif (is_numeric($sendto)) {
         $shipping_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int) $customer_id . "' and ab.address_book_id = '" . (int) $sendto . "'");
         $shipping_address = tep_db_fetch_array($shipping_address_query);
     } else {
         $shipping_address = array('entry_firstname' => null, 'entry_lastname' => null, 'entry_company' => null, 'entry_street_address' => null, 'entry_suburb' => null, 'entry_postcode' => null, 'entry_city' => null, 'entry_zone_id' => null, 'zone_name' => null, 'entry_country_id' => null, 'countries_id' => null, 'countries_name' => null, 'countries_iso_code_2' => null, 'countries_iso_code_3' => null, 'address_format_id' => 0, 'entry_state' => null);
     }
     if (is_array($billto) && !empty($billto)) {
         $billing_address = array('entry_firstname' => $billto['firstname'], 'entry_lastname' => $billto['lastname'], 'entry_company' => $billto['company'], 'entry_street_address' => $billto['street_address'], 'entry_suburb' => $billto['suburb'], 'entry_postcode' => $billto['postcode'], 'entry_city' => $billto['city'], 'entry_zone_id' => $billto['zone_id'], 'zone_name' => $billto['zone_name'], 'entry_country_id' => $billto['country_id'], 'countries_id' => $billto['country_id'], 'countries_name' => $billto['country_name'], 'countries_iso_code_2' => $billto['country_iso_code_2'], 'countries_iso_code_3' => $billto['country_iso_code_3'], 'address_format_id' => $billto['address_format_id'], 'entry_state' => $billto['zone_name']);
     } else {
         $billing_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int) $customer_id . "' and ab.address_book_id = '" . (int) $billto . "'");
         $billing_address = tep_db_fetch_array($billing_address_query);
     }
     if ($this->content_type == 'virtual') {
         $tax_address = array('entry_country_id' => $billing_address['entry_country_id'], 'entry_zone_id' => $billing_address['entry_zone_id']);
     } else {
         $tax_address = array('entry_country_id' => $shipping_address['entry_country_id'], 'entry_zone_id' => $shipping_address['entry_zone_id']);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $payment, 'cc_type' => '', 'cc_owner' => '', 'cc_number' => '', 'cc_expires' => '', 'shipping_method' => $shipping['title'], 'shipping_cost' => $shipping['cost'], 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) && !empty($comments) ? $comments : '');
     if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {
         if (isset($GLOBALS[$payment]->public_title)) {
             $this->info['payment_method'] = $GLOBALS[$payment]->public_title;
         } else {
             $this->info['payment_method'] = $GLOBALS[$payment]->title;
         }
         if (isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && $GLOBALS[$payment]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$payment]->order_status;
         }
     }
     $this->customer = array('firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'company' => $customer_address['entry_company'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => tep_not_null($customer_address['entry_state']) ? $customer_address['entry_state'] : $customer_address['zone_name'], 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['customers_telephone'], 'email_address' => $customer_address['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'company' => $shipping_address['entry_company'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => tep_not_null($shipping_address['entry_state']) ? $shipping_address['entry_state'] : $shipping_address['zone_name'], 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'format_id' => $shipping_address['address_format_id']);
     $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'company' => $billing_address['entry_company'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => tep_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'zone_id' => $billing_address['entry_zone_id'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']), 'country_id' => $billing_address['entry_country_id'], 'format_id' => $billing_address['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), 'weight' => $products[$i]['weight'], 'id' => $products[$i]['id']);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             foreach ($products[$i]['attributes'] as $option => $value) {
                 $attributes_query = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int) $products[$i]['id'] . "' and pa.options_id = '" . (int) $option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int) $value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . (int) $_SESSION['languages_id'] . "' and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'");
                 $attributes = tep_db_fetch_array($attributes_query);
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'], 'value' => $attributes['products_options_values_name'], 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']);
                 $subindex++;
             }
         }
         $shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']);
         $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;
             }
         }
         $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 #9
0
                 }
             }
         }
     }
 }
 $ShipTxt .= '</table></form>';
 $info_box_contents = array();
 $info_box_contents[] = array('text' => $ShipTxt);
 new infoBox($info_box_contents);
 if (CARTSHIP_SHOWOT == 'true') {
     // BOF get taxes if not logged in
     if (!tep_session_is_registered('customer_id')) {
         $products = $cart->get_products();
         for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
             $products_tax = tep_get_tax_rate($products[$i]['tax_class_id'], $order->delivery['country_id'], $order->delivery['zone_id']);
             $products_tax_description = tep_get_tax_description($products[$i]['tax_class_id'], $order->delivery['country_id'], $order->delivery['zone_id']);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 //Modified by Strider 42 to correct the tax calculation when a customer is not logged in
                 // $tax_val = ($products[$i]['final_price']-(($products[$i]['final_price']*100)/(100+$products_tax)))*$products[$i]['quantity'];
                 $tax_val = $products[$i]['final_price'] / 100 * $products_tax * $products[$i]['quantity'];
             } else {
                 $tax_val = $products[$i]['final_price'] * $products_tax / 100 * $products[$i]['quantity'];
             }
             $order->info['tax'] += $tax_val;
             $order->info['tax_groups']["{$products_tax_description}"] += $tax_val;
             // Modified by Strider 42 to correct the order total figure when shop displays prices with tax
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['total'];
             } else {
                 $order->info['total'] += $tax_val;
             }
Example #10
0
    ?>
</td>
	  <td class="dataTableHeadingContent"width="1"><?php 
    echo tep_draw_separator('pixel_trans.gif', '1', '1');
    ?>
</td>
	  </tr>
	  <tr>
	  <td class="smallText" align="right"><b><?php 
    echo TABLE_HEADING_SHIPPING_TAX;
    ?>
</b></td>
	  <td class="smallText" align="right"><input name="update_shipping_tax" size="10" onKeyUp="getTotals('shipping', '<?php 
    $countryid = tep_get_country_id($order->delivery["country"]);
    $zoneid = tep_get_zone_id($countryid, $order->delivery["state"]);
    $default_tax_name = tep_get_tax_description($default_tax_class, $countryid, $zoneid);
    //default tax class is set at the top of the file
    echo $default_tax_name;
    ?>
')" value="<?php 
    echo tep_display_tax_value($order->info['shipping_tax']);
    ?>
" id="shipping_tax_rate" /></td>
	  <td></td>
	   </tr>
		<tr class="dataTableHeadingRow">
	  <td class="dataTableHeadingContent"></td>
	  <td class="dataTableHeadingContent"><?php 
    echo TABLE_HEADING_TOTAL_AMOUNT;
    ?>
</td>
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $order;
     switch ($method) {
         case 'Standard':
             $ratio1 = tep_round($od_amount / $amount, 2);
             $tod_amount = 0;
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = tep_get_tax_rate_from_desc($key);
                 $total_net += $tax_rate * $order->info['tax_groups'][$key];
             }
             if ($od_amount > $total_net) {
                 $od_amount = $total_net;
             }
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = tep_get_tax_rate_from_desc($key);
                 $net = $tax_rate * $order->info['tax_groups'][$key];
                 if ($net > 0) {
                     $god_amount = $order->info['tax_groups'][$key] * $ratio1;
                     $tod_amount += $god_amount;
                     $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                 }
             }
             $order->info['tax'] -= $tod_amount;
             $order->info['total'] -= $tod_amount;
             break;
         case 'Credit Note':
             $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate;
             $order->info['tax_groups'][$tax_desc] -= $tod_amount;
             //          $order->info['total'] -= $tod_amount;   //// ????? Strider
             break;
         default:
     }
     return $tod_amount;
 }
 if (!empty($quotes_array) && MODULE_PAYMENT_PAYPAL_EXPRESS_INSTANT_UPDATE == 'True' && (MODULE_PAYMENT_PAYPAL_EXPRESS_TRANSACTION_SERVER != 'Live' || MODULE_PAYMENT_PAYPAL_EXPRESS_TRANSACTION_SERVER == 'Live' && ENABLE_SSL == true)) {
     // Live server requires SSL to be enabled
     $item_params['CALLBACK'] = tep_href_link('ext/modules/payment/paypal/express.php', 'osC_Action=callbackSet', 'SSL', false, false);
     $item_params['CALLBACKTIMEOUT'] = '6';
     $item_params['CALLBACKVERSION'] = $paypal_express->api_version;
 }
 include DIR_WS_CLASSES . 'order_total.php';
 $order_total_modules = new order_total();
 $order_totals = $order_total_modules->process();
 // Remove shipping tax from total that was added again in ot_shipping
 if (DISPLAY_PRICE_WITH_TAX == 'true') {
     $order->info['shipping_cost'] = $order->info['shipping_cost'] / (1.0 + $quotes_array[$default_shipping]['tax'] / 100);
 }
 $module = substr($shipping['id'], 0, strpos($shipping['id'], '_'));
 $order->info['tax'] -= tep_calculate_tax($order->info['shipping_cost'], $quotes_array[$default_shipping]['tax']);
 $order->info['tax_groups'][tep_get_tax_description($module->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id'])] -= tep_calculate_tax($order->info['shipping_cost'], $quotes_array[$default_shipping]['tax']);
 $order->info['total'] -= tep_calculate_tax($order->info['shipping_cost'], $quotes_array[$default_shipping]['tax']);
 $items_total = $paypal_express->format_raw($order->info['subtotal']);
 foreach ($order_totals as $ot) {
     if (!in_array($ot['code'], array('ot_subtotal', 'ot_shipping', 'ot_tax', 'ot_total'))) {
         $item_params['L_PAYMENTREQUEST_0_NAME' . $line_item_no] = $ot['title'];
         $item_params['L_PAYMENTREQUEST_0_AMT' . $line_item_no] = $paypal_express->format_raw($ot['value']);
         $items_total += $paypal_express->format_raw($ot['value']);
         $line_item_no++;
     }
 }
 $params['PAYMENTREQUEST_0_AMT'] = $paypal_express->format_raw($order->info['total']);
 $item_params['MAXAMT'] = $paypal_express->format_raw($params['PAYMENTREQUEST_0_AMT'] + $expensive_rate + 100, '', 1);
 // safely pad higher for dynamic shipping rates (eg, USPS express)
 $item_params['PAYMENTREQUEST_0_ITEMAMT'] = $items_total;
 $item_params['PAYMENTREQUEST_0_SHIPPINGAMT'] = $paypal_express->format_raw($order->info['shipping_cost']);
Example #13
0
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $order;
     switch ($method) {
         case 'Standard':
             // Amended line, was giving an error when a zero value was arriving here. v5.13 by Rigadin
             // v5.13 spelling error introduced an error, corrected
             //$ratio1 = tep_round($od_amount / $amount,2);
             $ratio1 = $amount == 0 ? 0 : tep_round($od_amount / $amount, 2);
             $tod_amount = 0;
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = tep_get_tax_rate_from_desc($key);
                 $total_net += $tax_rate * $order->info['tax_groups'][$key];
             }
             if ($od_amount > $total_net) {
                 $od_amount = $total_net;
             }
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = tep_get_tax_rate_from_desc($key);
                 $net = $tax_rate * $order->info['tax_groups'][$key];
                 if ($net > 0) {
                     $god_amount = $order->info['tax_groups'][$key] * $ratio1;
                     $tod_amount += $god_amount;
                     $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                 }
             }
             $order->info['tax'] -= $tod_amount;
             $order->info['total'] -= $tod_amount;
             break;
         case 'Credit Note':
             $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate;
             $order->info['tax_groups'][$tax_desc] -= $tod_amount;
             //          $order->info['total'] -= $tod_amount;   //// ????? Strider
             break;
         default:
     }
     return $tod_amount;
 }
Example #14
0
 function cart()
 {
     global $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, $payment;
     $this->content_type = $cart->get_content_type();
     $customer_address_query = tep_db_query("select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id) where c.customers_id = '" . (int) $customer_id . "' and ab.customers_id = '" . (int) $customer_id . "' and c.customers_default_address_id = ab.address_book_id");
     $customer_address = tep_db_fetch_array($customer_address_query);
     $shipping_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int) $customer_id . "' and ab.address_book_id = '" . (int) $sendto . "'");
     $shipping_address = tep_db_fetch_array($shipping_address_query);
     $billing_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int) $customer_id . "' and ab.address_book_id = '" . (int) $billto . "'");
     $billing_address = tep_db_fetch_array($billing_address_query);
     $tax_address_query = tep_db_query("select ab.entry_country_id, ab.entry_zone_id from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = '" . (int) $customer_id . "' and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $billto : $sendto) . "'");
     $tax_address = tep_db_fetch_array($tax_address_query);
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $currency, 'currency_value' => $currencies->currencies[$currency]['value'], 'payment_method' => $payment, 'cc_type' => isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : '', 'cc_owner' => isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : '', 'cc_number' => isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : '', 'cc_expires' => isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : '', 'shipping_method' => $shipping['title'], 'shipping_cost' => $shipping['cost'], 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array(), 'comments' => isset($GLOBALS['comments']) ? $GLOBALS['comments'] : '');
     if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {
         $this->info['payment_method'] = $GLOBALS[$payment]->title;
         if (isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && $GLOBALS[$payment]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$payment]->order_status;
         }
     }
     $this->customer = array('firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'company' => $customer_address['entry_company'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => tep_not_null($customer_address['entry_state']) ? $customer_address['entry_state'] : $customer_address['zone_name'], 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['customers_telephone'], 'email_address' => $customer_address['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'company' => $shipping_address['entry_company'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => tep_not_null($shipping_address['entry_state']) ? $shipping_address['entry_state'] : $shipping_address['zone_name'], 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'format_id' => $shipping_address['address_format_id']);
     $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'company' => $billing_address['entry_company'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => tep_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'zone_id' => $billing_address['entry_zone_id'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']), 'country_id' => $billing_address['entry_country_id'], 'format_id' => $billing_address['address_format_id']);
     $index = 0;
     $products = $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' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']), 'weight' => $products[$i]['weight'], 'id' => $products[$i]['id']);
         // BOF Separate Pricing Per Customer
         if (!tep_session_is_registered('sppc_customer_group_id')) {
             $customer_group_id = '0';
         } else {
             $customer_group_id = $sppc_customer_group_id;
         }
         if ($customer_group_id != '0') {
             $orders_customers_price = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where customers_group_id = '" . $customer_group_id . "' and products_id = '" . $products[$i]['id'] . "'");
             $orders_customers = tep_db_fetch_array($orders_customers_price);
             if ($orders_customers = tep_db_fetch_array($orders_customers_price)) {
                 $this->products[$index] = array('price' => $orders_customers['customers_group_price'], 'final_price' => $orders_customers['customers_group_price'] + $cart->attributes_price($products[$i]['id']));
             }
         }
         // EOF Separate Pricing Per Customer
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 //++++ QT Pro: Begin Changed code
                 $attributes_query = tep_db_query("select popt.products_options_name, popt.products_options_track_stock, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int) $products[$i]['id'] . "' and pa.options_id = '" . (int) $option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int) $value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . (int) $languages_id . "' and poval.language_id = '" . (int) $languages_id . "'");
                 //++++ QT Pro: End Changed Code
                 $attributes = tep_db_fetch_array($attributes_query);
                 //++++ QT Pro: Begin Changed code
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'], 'value' => $attributes['products_options_values_name'], 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price'], 'track_stock' => $attributes['products_options_track_stock']);
                 //++++ QT Pro: End Changed Code
                 $subindex++;
             }
         }
         $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];
         $this->info['subtotal'] += $shown_price;
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         // BOF Separate Pricing Per Customer, show_tax modification
         // next line was original code
         //      if (DISPLAY_PRICE_WITH_TAX == 'true') {
         global $sppc_customer_group_show_tax;
         if (!tep_session_is_registered('sppc_customer_group_show_tax')) {
             $customer_group_show_tax = '1';
         } else {
             $customer_group_show_tax = $sppc_customer_group_show_tax;
         }
         if (DISPLAY_PRICE_WITH_TAX == 'true' && $customer_group_show_tax == '1') {
             // EOF Separate Pricing Per Customer, show_tax modification
             $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;
             }
         }
         $index++;
     }
     // BOF Separate Pricing Per Customer, show_tax modification
     // next line was original code
     //      if (DISPLAY_PRICE_WITH_TAX == 'true') {
     global $sppc_customer_group_show_tax;
     if (!tep_session_is_registered('sppc_customer_group_show_tax')) {
         $customer_group_show_tax = '1';
     } else {
         $customer_group_show_tax = $sppc_customer_group_show_tax;
     }
     if (DISPLAY_PRICE_WITH_TAX == 'true' && $customer_group_show_tax == '1') {
         // EOF Separate Pricing Per Customer, show_tax modification
         $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 #15
0
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $customer_id, $order, $cc_id, $cart;
     //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
     $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");
     if (tep_db_num_rows($coupon_query) != 0) {
         $coupon_result = tep_db_fetch_array($coupon_query);
         $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '" . $coupon_result['coupon_code'] . "'");
         $get_result = tep_db_fetch_array($coupon_get);
         if ($get_result['coupon_type'] != 'S') {
             //RESTRICTION--------------------------------
             if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {
                 // What to do here.
                 // Loop through all products and build a list of all product_ids, price, tax class
                 // at the same time create total net amount.
                 // then
                 // for percentage discounts. simply reduce tax group per product by discount percentage
                 // or
                 // for fixed payment amount
                 // calculate ratio based on total net
                 // for each product reduce tax group per product by ratio amount.
                 $products = $cart->get_products();
                 $valid_product = false;
                 for ($i = 0; $i < sizeof($products); $i++) {
                     $valid_product = false;
                     $t_prid = tep_get_prid($products[$i]['id']);
                     $cc_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
                     $cc_result = tep_db_fetch_array($cc_query);
                     if ($get_result['restrict_to_products']) {
                         $pr_ids = split("[,]", $get_result['restrict_to_products']);
                         for ($p = 0; $p < sizeof($pr_ids); $p++) {
                             if ($pr_ids[$p] == $t_prid) {
                                 $valid_product = true;
                             }
                         }
                     }
                     if ($get_result['restrict_to_categories']) {
                         // Tanaka 2005-4-30:  Original Code
                         /*$cat_ids = split("[,]", $get_result['restrict_to_categories']);
                           for ($c = 0; $c < sizeof($cat_ids); $c++) {
                               // Tanaka 2005-4-30:  changed $products_id to $t_prid and changed $i to $c
                               $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $t_prid . "' and categories_id = '" . $cat_ids[$c] . "'");
                               if (tep_db_num_rows($cat_query) !=0 ) $valid_product = true;
                           }*/
                         // v5.13a Tanaka 2005-4-30:  New code, this correctly identifies valid products in subcategories
                         $cat_ids = split("[,]", $get_result['restrict_to_categories']);
                         $my_path = tep_get_product_path($t_prid);
                         $sub_cat_ids = split("[_]", $my_path);
                         for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {
                             for ($ii = 0; $ii < count($cat_ids); $ii++) {
                                 if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {
                                     $valid_product = true;
                                     continue 2;
                                 }
                             }
                         }
                     }
                     if ($valid_product) {
                         $price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity'];
                         //Fred - added
                         $price_incl_vat = $this->product_price($t_prid);
                         //Fred - added
                         $valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']);
                         //jason //Fred - changed from $products[$i]['final_price'] 'products_tax_class' => $cc_result['products_tax_class_id']);
                         //                                                $total_price += $price_incl_vat; //Fred - changed
                         $total_price += $price_excl_vat;
                         // changed
                     }
                 }
                 if (sizeof($valid_array) > 0) {
                     // if ($valid_product) {
                     if ($get_result['coupon_type'] == 'P') {
                         $ratio = $get_result['coupon_amount'] / 100;
                     } else {
                         $ratio = $od_amount / $total_price;
                     }
                     if ($get_result['coupon_type'] == 'S') {
                         $ratio = 1;
                     }
                     if ($method == 'Credit Note') {
                         $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         if ($get_result['coupon_type'] == 'P') {
                             $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate;
                         } else {
                             $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100;
                         }
                         $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                         $order->info['total'] -= $tod_amount;
                         //  need to modify total ...OLD
                         $order->info['tax'] -= $tod_amount;
                         //Fred - added
                     } else {
                         for ($p = 0; $p < sizeof($valid_array); $p++) {
                             $tax_rate = tep_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
                             $tax_desc = tep_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
                             if ($tax_rate > 0) {
                                 //Fred $tod_amount[$tax_desc] += ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; //OLD
                                 $tod_amount = $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio;
                                 // calc total tax Fred - added
                                 $order->info['tax_groups'][$tax_desc] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio;
                                 $order->info['total'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio;
                                 // adjust total
                                 $order->info['tax'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio;
                                 // adjust tax -- Fred - added
                             }
                         }
                     }
                 }
                 //NO RESTRICTION--------------------------------
             } else {
                 if ($get_result['coupon_type'] == 'F') {
                     $tod_amount = 0;
                     if ($method == 'Credit Note') {
                         $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate;
                         $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                     } else {
                         //                                                $ratio1 = $od_amount/$amount;   // this produces the wrong ratipo on fixed amounts
                         reset($order->info['tax_groups']);
                         while (list($key, $value) = each($order->info['tax_groups'])) {
                             $ratio1 = $od_amount / ($amount - $order->info['tax_groups'][$key]);
                             ////debug
                             $tax_rate = tep_get_tax_rate_from_desc($key);
                             $net = $tax_rate * $order->info['tax_groups'][$key];
                             if ($net > 0) {
                                 $god_amount = $order->info['tax_groups'][$key] * $ratio1;
                                 $tod_amount += $god_amount;
                                 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                             }
                         }
                     }
                     $order->info['total'] -= $tod_amount;
                     //OLD
                     $order->info['tax'] -= $tod_amount;
                     //Fred - added
                 }
                 if ($get_result['coupon_type'] == 'P') {
                     $tod_amount = 0;
                     if ($method == 'Credit Note') {
                         $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100;
                         $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                     } else {
                         reset($order->info['tax_groups']);
                         while (list($key, $value) = each($order->info['tax_groups'])) {
                             $god_amount = 0;
                             $tax_rate = tep_get_tax_rate_from_desc($key);
                             $net = $tax_rate * $order->info['tax_groups'][$key];
                             if ($net > 0) {
                                 $god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount'] / 100;
                                 $tod_amount += $god_amount;
                                 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                             }
                         }
                     }
                     $order->info['total'] -= $tod_amount;
                     // have to modify total also
                     $order->info['tax'] -= $tod_amount;
                 }
             }
         }
     }
     return $tod_amount;
 }
 function fixTaxes()
 {
     global $cart, $order, $currencies, $onepage, $customer_id, $customer_country_id, $customer_zone_id;
     if ($cart->get_content_type() == 'virtual' && is_numeric($onepage['billing']['country_id'])) {
         $taxCountryID = $onepage['billing']['country_id'];
         $taxZoneID = $onepage['billing']['zone_id'];
     } elseif (is_numeric($onepage['delivery']['country_id'])) {
         $taxCountryID = $onepage['delivery']['country_id'];
         $taxZoneID = $onepage['delivery']['zone_id'];
     } elseif (!tep_session_is_registered('customer_id')) {
         if (DISPLAY_PRICE_WITH_TAX == 'false') {
             $taxCountryID = 0;
             $taxZoneID = 0;
         } else {
             $taxCountryID = STORE_COUNTRY;
             $taxZoneID = STORE_ZONE;
         }
     } else {
         $taxCountryID = $customer_country_id;
         $taxZoneID = $customer_zone_id;
     }
     $products = $cart->get_products();
     if (sizeof($products) > 0) {
         $order->info['subtotal'] = 0;
         $order->info['tax_groups'] = array();
         $order->info['tax'] = 0;
         //BOF KGT
         if (MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true') {
             $valid_products_count = 0;
             $order->coupon->applied_discount = array();
         }
         //EOF KGT
         //echo '<pre>';
         for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
             $taxClassID = $products[$i]['tax_class_id'];
             $order->products[$i]['tax'] = tep_get_tax_rate($taxClassID, $taxCountryID, $taxZoneID);
             $order->products[$i]['tax_description'] = tep_get_tax_description($taxClassID, $taxCountryID, $taxZoneID);
             //BOF KGT
             if (MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true' && is_object($order->coupon) && !empty($order->coupon->coupon)) {
                 //kgt - discount coupons
                 $applied_discount = 0;
                 $discount = $order->coupon->calculate_discount($order->products[$i], $valid_products_count);
                 if ($discount['applied_discount'] > 0) {
                     $valid_products_count++;
                 }
                 $shown_price = $order->coupon->calculate_shown_price($discount, $order->products[$i]);
                 //var_dump($shown_price);
                 $shown_price = $shown_price['actual_shown_price'];
             } else {
                 $shown_price = tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'];
             }
             $order->info['subtotal'] += $shown_price;
             /**************
                  $shown_price = tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'];
                $order->info['subtotal'] += $shown_price;
                  **************/
             //end kgt - discount coupons
             //EOF KGT
             $products_tax = $order->products[$i]['tax'];
             $products_tax_description = $order->products[$i]['tax_description'];
             //echo "tax: $products_tax \n";
             //echo "tax desc: $products_tax_description \n";
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                 if (isset($order->info['tax_groups']["{$products_tax_description}"])) {
                     $order->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 {
                     $order->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 {
                 $order->info['tax'] += $products_tax / 100 * $shown_price;
                 if (isset($order->info['tax_groups']["{$products_tax_description}"])) {
                     $order->info['tax_groups']["{$products_tax_description}"] += $products_tax / 100 * $shown_price;
                 } else {
                     $order->info['tax_groups']["{$products_tax_description}"] = $products_tax / 100 * $shown_price;
                 }
             }
             //echo $shown_price."\n";
         }
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $order->info['total'] = $order->info['subtotal'] + $order->info['shipping_cost'];
         } else {
             $order->info['total'] = $order->info['subtotal'] + $order->info['tax'] + $order->info['shipping_cost'];
         }
         //kgt - discount coupon
         if (MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true' && is_object($order->coupon) && !empty($order->coupon->coupon)) {
             //$order->coupon->applied_discount = $applied_discount;
             $order->info['total'] = $order->coupon->finalize_discount($order->info);
             $onepage['coupon'] = $order->coupon;
         }
         //end kgt - discount coupon
     }
 }
Example #17
0
 function cart()
 {
     global $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, $payment;
     $this->content_type = $cart->get_content_type();
     $shop_countries = tep_get_shops_countries();
     $customer_address_query = tep_db_query("select c.customers_firstname, c.customers_lastname, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, ab.entry_country_id, ab.entry_telephone, ab.entry_state, c.customers_email_address, c.customers_telephone from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab where c.customers_id = '" . (int) $customer_id . "' and ab.customers_id = '" . (int) $customer_id . "' and c.customers_default_address_id = ab.address_book_id");
     $customer_address = tep_db_fetch_array($customer_address_query);
     if (!is_array($customer_address)) {
         $customer_address = array();
     }
     $country_info_query = tep_db_query("select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3, address_format_id from " . TABLE_COUNTRIES . " where countries_id = '" . (int) $customer_address['entry_country_id'] . "' and language_id = '" . (int) $languages_id . "'");
     $country_info = tep_db_fetch_array($country_info_query);
     if (!is_array($country_info)) {
         $country_info = array();
         reset($shop_countries);
         while (list(, $shop_country) = each($shop_countries)) {
             if ($shop_country['country_id'] == $customer_address['entry_country_id']) {
                 $country_info = array('countries_id' => $shop_country['country_id'], 'countries_name' => $shop_country['country_name'], 'countries_iso_code_2' => $shop_country['country_code'], 'countries_iso_code_3' => $shop_country['country_code_3'], 'address_format_id' => $shop_country['address_format_id']);
                 break;
             }
         }
     }
     $zone_info_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_id = '" . (int) $customer_address['entry_zone_id'] . "'");
     $zone_info = tep_db_fetch_array($zone_info_query);
     if (!is_array($zone_info)) {
         $zone_info = array();
     }
     $customer_address = array_merge($customer_address, $country_info, $zone_info);
     $company = array();
     $company_info_query = tep_db_query("select * from " . TABLE_COMPANIES . " where customers_id = '" . (int) $customer_id . "'");
     $company_info = tep_db_fetch_array($company_info_query);
     if (!is_array($company_info)) {
         $company_info = array();
     }
     reset($company_info);
     while (list($k, $v) = each($company_info)) {
         $k = str_replace('companies_', 'company_', $k);
         $k = str_replace('company_full_name', 'company_full', $k);
         $k = str_replace('company_name', 'company', $k);
         $company[$k] = $v;
     }
     $shipping_address_query = tep_db_query("select entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_zone_id, entry_country_id, entry_telephone, entry_state from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int) $customer_id . "' and address_book_id = '" . (int) $sendto . "'");
     $shipping_address = tep_db_fetch_array($shipping_address_query);
     if (!is_array($shipping_address)) {
         $shipping_address = array();
     }
     $country_info_query = tep_db_query("select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3, address_format_id from " . TABLE_COUNTRIES . " where countries_id = '" . (int) $shipping_address['entry_country_id'] . "' and language_id = '" . (int) $languages_id . "'");
     $country_info = tep_db_fetch_array($country_info_query);
     if (!is_array($country_info)) {
         $country_info = array();
         reset($shop_countries);
         while (list(, $shop_country) = each($shop_countries)) {
             if ($shop_country['country_id'] == $shipping_address['entry_country_id']) {
                 $country_info = array('countries_id' => $shop_country['country_id'], 'countries_name' => $shop_country['country_name'], 'countries_iso_code_2' => $shop_country['country_code'], 'countries_iso_code_3' => $shop_country['country_code_3'], 'address_format_id' => $shop_country['address_format_id']);
                 break;
             }
         }
     }
     $zone_info_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_id = '" . (int) $shipping_address['entry_zone_id'] . "'");
     $zone_info = tep_db_fetch_array($zone_info_query);
     if (!is_array($zone_info)) {
         $zone_info = array();
     }
     $shipping_address = array_merge($shipping_address, $country_info, $zone_info);
     $billing_address_query = tep_db_query("select entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_zone_id, entry_country_id, entry_telephone, entry_state from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int) $customer_id . "' and address_book_id = '" . (int) $billto . "'");
     $billing_address = tep_db_fetch_array($billing_address_query);
     if (!is_array($billing_address)) {
         $billing_address = array();
     }
     $country_info_query = tep_db_query("select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3, address_format_id from " . TABLE_COUNTRIES . " where countries_id = '" . (int) $billing_address['entry_country_id'] . "' and language_id = '" . (int) $languages_id . "'");
     $country_info = tep_db_fetch_array($country_info_query);
     if (!is_array($country_info)) {
         $country_info = array();
         reset($shop_countries);
         while (list(, $shop_country) = each($shop_countries)) {
             if ($shop_country['country_id'] == $billing_address['entry_country_id']) {
                 $country_info = array('countries_id' => $shop_country['country_id'], 'countries_name' => $shop_country['country_name'], 'countries_iso_code_2' => $shop_country['country_code'], 'countries_iso_code_3' => $shop_country['country_code_3'], 'address_format_id' => $shop_country['address_format_id']);
                 break;
             }
         }
     }
     $zone_info_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_id = '" . (int) $billing_address['entry_zone_id'] . "'");
     $zone_info = tep_db_fetch_array($zone_info_query);
     if (!is_array($zone_info)) {
         $zone_info = array();
     }
     $billing_address = array_merge($billing_address, $country_info, $zone_info);
     $tax_address_query = tep_db_query("select ab.entry_country_id, ab.entry_zone_id from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = '" . (int) $customer_id . "' and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $billto : $sendto) . "'");
     $tax_address = tep_db_fetch_array($tax_address_query);
     $this->info = array('code' => '', 'order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $currency, 'currency_value' => $currencies->currencies[$currency]['value'], 'is_paid' => '0', 'payment_method' => $payment, 'cc_type' => isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : '', 'cc_owner' => isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : '', 'cc_number' => isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : '', 'cc_expires' => isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : '', 'check_account_type' => isset($GLOBALS['check_account_type']) ? $GLOBALS['check_account_type'] : '', 'check_bank_name' => isset($GLOBALS['check_bank_name']) ? $GLOBALS['check_bank_name'] : '', 'check_routing_number' => isset($GLOBALS['check_routing_number']) ? $GLOBALS['check_routing_number'] : '', 'check_account_number' => isset($GLOBALS['check_account_number']) ? $GLOBALS['check_account_number'] : '', 'shipping_method' => $shipping['title'], 'shipping_cost' => $shipping['cost'], 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array(), 'comments' => isset($GLOBALS['comments']) ? $GLOBALS['comments'] : '', 'delivery_transfer' => $cart->info['delivery_transfer'], 'shops_id' => SHOP_ID);
     if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {
         $this->info['payment_method'] = $GLOBALS[$payment]->title;
         if (isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && $GLOBALS[$payment]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$payment]->order_status;
         }
     }
     $this->customer = array('id' => $customer_id, 'firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => tep_not_null($customer_address['entry_state']) ? $customer_address['entry_state'] : $customer_address['zone_name'], 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['entry_telephone'], 'email_address' => $customer_address['customers_email_address']);
     $this->customer = array_merge($this->customer, $company);
     $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => tep_not_null($shipping_address['entry_state']) ? $shipping_address['entry_state'] : $shipping_address['zone_name'], 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'telephone' => $shipping_address['entry_telephone'], 'format_id' => $shipping_address['address_format_id']);
     $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => tep_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'zone_id' => $billing_address['entry_zone_id'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']), 'country_id' => $billing_address['entry_country_id'], 'telephone' => $billing_address['entry_telephone'], 'format_id' => $billing_address['address_format_id']);
     $index = 0;
     $products = $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'], 'code' => $products[$i]['code'], 'manufacturer' => $products[$i]['manufacturer'], 'year' => $products[$i]['year'], 'type' => $products[$i]['type'], 'periodicity' => $products[$i]['periodicity'], 'periodicity_min' => $products[$i]['periodicity_min'], 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'], 'tax' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'weight' => $products[$i]['weight'], 'warranty' => $products[$i]['warranty'], 'id' => $products[$i]['id']);
         if (tep_not_null($products[$i]['filename'])) {
             $this->products[$index]['filename'] = $products[$i]['filename'];
             $this->products[$index]['download_maxdays'] = DOWNLOAD_MAX_DAYS;
             $this->products[$index]['download_count'] = DOWNLOAD_MAX_COUNT;
         }
         $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];
         $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;
             }
         }
         $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 #18
0
 function cart()
 {
     global $currencies;
     $OSCOM_Db = Registry::get('Db');
     $this->content_type = $_SESSION['cart']->get_content_type();
     if ($this->content_type != 'virtual' && $_SESSION['sendto'] == false) {
         $_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
     }
     $customer_address = ['customers_firstname' => null, 'customers_lastname' => null, 'customers_telephone' => null, 'customers_email_address' => null, 'entry_company' => null, 'entry_street_address' => null, 'entry_suburb' => null, 'entry_postcode' => null, 'entry_city' => null, 'entry_zone_id' => null, 'zone_name' => null, 'countries_id' => null, 'countries_name' => null, 'countries_iso_code_2' => null, 'countries_iso_code_3' => null, 'address_format_id' => 0, 'entry_state' => null];
     if (isset($_SESSION['customer_id'])) {
         $Qcustomer = $OSCOM_Db->prepare('select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from :table_customers c, :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries co on (ab.entry_country_id = co.countries_id) where c.customers_id = :customers_id and c.customers_id = ab.customers_id and c.customers_default_address_id = ab.address_book_id');
         $Qcustomer->bindInt(':customers_id', $_SESSION['customer_id']);
         $Qcustomer->execute();
         $customer_address = $Qcustomer->toArray();
     }
     $shipping_address = array('entry_firstname' => null, 'entry_lastname' => null, 'entry_company' => null, 'entry_street_address' => null, 'entry_suburb' => null, 'entry_postcode' => null, 'entry_city' => null, 'entry_zone_id' => null, 'zone_name' => null, 'entry_country_id' => null, 'countries_id' => null, 'countries_name' => null, 'countries_iso_code_2' => null, 'countries_iso_code_3' => null, 'address_format_id' => 0, 'entry_state' => null);
     if (isset($_SESSION['sendto'])) {
         if (is_array($_SESSION['sendto']) && !empty($_SESSION['sendto'])) {
             $shipping_address = array('entry_firstname' => $_SESSION['sendto']['firstname'], 'entry_lastname' => $_SESSION['sendto']['lastname'], 'entry_company' => $_SESSION['sendto']['company'], 'entry_street_address' => $_SESSION['sendto']['street_address'], 'entry_suburb' => $_SESSION['sendto']['suburb'], 'entry_postcode' => $_SESSION['sendto']['postcode'], 'entry_city' => $_SESSION['sendto']['city'], 'entry_zone_id' => $_SESSION['sendto']['zone_id'], 'zone_name' => $_SESSION['sendto']['zone_name'], 'entry_country_id' => $_SESSION['sendto']['country_id'], 'countries_id' => $_SESSION['sendto']['country_id'], 'countries_name' => $_SESSION['sendto']['country_name'], 'countries_iso_code_2' => $_SESSION['sendto']['country_iso_code_2'], 'countries_iso_code_3' => $_SESSION['sendto']['country_iso_code_3'], 'address_format_id' => $_SESSION['sendto']['address_format_id'], 'entry_state' => $_SESSION['sendto']['zone_name']);
         } elseif (is_numeric($_SESSION['sendto'])) {
             $Qaddress = $OSCOM_Db->prepare('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id');
             $Qaddress->bindInt(':customers_id', $_SESSION['customer_id']);
             $Qaddress->bindInt(':address_book_id', $_SESSION['sendto']);
             $Qaddress->execute();
             $shipping_address = $Qaddress->toArray();
         }
     }
     $billing_address = array('entry_firstname' => null, 'entry_lastname' => null, 'entry_company' => null, 'entry_street_address' => null, 'entry_suburb' => null, 'entry_postcode' => null, 'entry_city' => null, 'entry_zone_id' => null, 'zone_name' => null, 'entry_country_id' => null, 'countries_id' => null, 'countries_name' => null, 'countries_iso_code_2' => null, 'countries_iso_code_3' => null, 'address_format_id' => 0, 'entry_state' => null);
     if (isset($_SESSION['billto'])) {
         if (is_array($_SESSION['billto']) && !empty($_SESSION['billto'])) {
             $billing_address = array('entry_firstname' => $_SESSION['billto']['firstname'], 'entry_lastname' => $_SESSION['billto']['lastname'], 'entry_company' => $_SESSION['billto']['company'], 'entry_street_address' => $_SESSION['billto']['street_address'], 'entry_suburb' => $_SESSION['billto']['suburb'], 'entry_postcode' => $_SESSION['billto']['postcode'], 'entry_city' => $_SESSION['billto']['city'], 'entry_zone_id' => $_SESSION['billto']['zone_id'], 'zone_name' => $_SESSION['billto']['zone_name'], 'entry_country_id' => $_SESSION['billto']['country_id'], 'countries_id' => $_SESSION['billto']['country_id'], 'countries_name' => $_SESSION['billto']['country_name'], 'countries_iso_code_2' => $_SESSION['billto']['country_iso_code_2'], 'countries_iso_code_3' => $_SESSION['billto']['country_iso_code_3'], 'address_format_id' => $_SESSION['billto']['address_format_id'], 'entry_state' => $_SESSION['billto']['zone_name']);
         } elseif (is_numeric($_SESSION['billto'])) {
             $Qaddress = $OSCOM_Db->prepare('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id');
             $Qaddress->bindInt(':customers_id', $_SESSION['customer_id']);
             $Qaddress->bindInt(':address_book_id', $_SESSION['billto']);
             $Qaddress->execute();
             $billing_address = $Qaddress->toArray();
         }
     }
     if ($this->content_type == 'virtual') {
         $tax_address = array('entry_country_id' => $billing_address['entry_country_id'], 'entry_zone_id' => $billing_address['entry_zone_id']);
     } else {
         $tax_address = array('entry_country_id' => $shipping_address['entry_country_id'], 'entry_zone_id' => $shipping_address['entry_zone_id']);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => isset($_SESSION['payment']) ? $_SESSION['payment'] : '', 'cc_type' => '', 'cc_owner' => '', 'cc_number' => '', 'cc_expires' => '', 'shipping_method' => isset($_SESSION['shipping']) ? $_SESSION['shipping']['title'] : '', 'shipping_cost' => isset($_SESSION['shipping']) ? $_SESSION['shipping']['cost'] : 0, 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) && !empty($_SESSION['comments']) ? $_SESSION['comments'] : '');
     if (isset($_SESSION['payment'])) {
         if (strpos($_SESSION['payment'], '\\') !== false) {
             $code = 'Payment_' . str_replace('\\', '_', $_SESSION['payment']);
             if (Registry::exists($code)) {
                 $OSCOM_PM = Registry::get($code);
             }
         } elseif (is_object($GLOBALS[$_SESSION['payment']])) {
             $OSCOM_PM = $GLOBALS[$_SESSION['payment']];
         }
         if (isset($OSCOM_PM)) {
             if (isset($OSCOM_PM->public_title)) {
                 $this->info['payment_method'] = $OSCOM_PM->public_title;
             } else {
                 $this->info['payment_method'] = $OSCOM_PM->title;
             }
             if (isset($OSCOM_PM->order_status) && is_numeric($OSCOM_PM->order_status) && $OSCOM_PM->order_status > 0) {
                 $this->info['order_status'] = $OSCOM_PM->order_status;
             }
         }
     }
     $this->customer = array('firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'company' => $customer_address['entry_company'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => tep_not_null($customer_address['entry_state']) ? $customer_address['entry_state'] : $customer_address['zone_name'], 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['customers_telephone'], 'email_address' => $customer_address['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'company' => $shipping_address['entry_company'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => tep_not_null($shipping_address['entry_state']) ? $shipping_address['entry_state'] : $shipping_address['zone_name'], 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'format_id' => $shipping_address['address_format_id']);
     $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'company' => $billing_address['entry_company'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => tep_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'zone_id' => $billing_address['entry_zone_id'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']), 'country_id' => $billing_address['entry_country_id'], 'format_id' => $billing_address['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), 'weight' => $products[$i]['weight'], 'id' => $products[$i]['id']);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             foreach ($products[$i]['attributes'] as $option => $value) {
                 $Qattributes = $OSCOM_Db->prepare('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :language_id and popt.language_id = poval.language_id');
                 $Qattributes->bindInt(':products_id', $products[$i]['id']);
                 $Qattributes->bindInt(':options_id', $option);
                 $Qattributes->bindInt(':options_values_id', $value);
                 $Qattributes->bindInt(':language_id', $_SESSION['languages_id']);
                 $Qattributes->execute();
                 $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options_name'), 'value' => $Qattributes->value('products_options_values_name'), 'option_id' => $option, 'value_id' => $value, 'prefix' => $Qattributes->value('price_prefix'), 'price' => $Qattributes->value('options_values_price'));
                 $subindex++;
             }
         }
         $shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']);
         $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;
             }
         }
         $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'];
     }
 }
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $customer_id, $order, $cc_id, $cart;
     $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");
     if (tep_db_num_rows($coupon_query) != 0) {
         $coupon_result = tep_db_fetch_array($coupon_query);
         $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '" . $coupon_result['coupon_code'] . "'");
         $get_result = tep_db_fetch_array($coupon_get);
         if ($get_result['coupon_type'] != 'S') {
             //PRODUCT / CATEGORY RESTRICTION
             if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {
                 // What to do here.
                 // Loop through all products and build a list of all product_ids, price, tax class
                 // at the same time create total net amount.
                 // then for percentage discounts. simply reduce tax group per product by discount percentage
                 // or for fixed payment amount calculate ratio based on total net for each product reduce tax group
                 // per product by ratio amount.
                 $products = $cart->get_products();
                 $valid_product = false;
                 for ($i = 0; $i < sizeof($products); $i++) {
                     $valid_product = false;
                     $t_prid = tep_get_prid($products[$i]['id']);
                     $cc_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
                     $cc_result = tep_db_fetch_array($cc_query);
                     if ($get_result['restrict_to_products']) {
                         $pr_ids = preg_split("[,]", $get_result['restrict_to_products']);
                         for ($p = 0; $p < sizeof($pr_ids); $p++) {
                             if ($pr_ids[$p] == $t_prid) {
                                 $valid_product = true;
                             }
                         }
                     }
                     if ($get_result['restrict_to_categories']) {
                         $cat_ids = preg_split("[,]", $get_result['restrict_to_categories']);
                         for ($c = 0; $c < sizeof($cat_ids); $c++) {
                             $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'");
                             if (tep_db_num_rows($cat_query) != 0) {
                                 $valid_product = true;
                             }
                         }
                     }
                     if ($valid_product) {
                         $price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity'];
                         $price_incl_vat = $this->product_price($t_prid);
                         $valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']);
                         $total_price += $price_excl_vat;
                     }
                 }
                 if (sizeof($valid_array) > 0) {
                     if ($get_result['coupon_type'] == 'P') {
                         $ratio = $get_result['coupon_amount'] / 100;
                     } else {
                         $ratio = $od_amount / $total_price;
                     }
                     if ($get_result['coupon_type'] == 'S') {
                         $ratio = 1;
                     }
                     if ($method == 'Credit Note') {
                         $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         if ($get_result['coupon_type'] == 'P') {
                             $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate;
                         } else {
                             $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100;
                         }
                         $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                         $order->info['tax'] -= $tod_amount;
                     } else {
                         for ($p = 0; $p < sizeof($valid_array); $p++) {
                             $tax_rate = tep_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
                             $tax_desc = tep_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
                             if ($tax_rate > 0) {
                                 $tod_amount = $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio;
                                 $order->info['tax_groups'][$tax_desc] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio;
                                 $order->info['tax'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio;
                             }
                         }
                     }
                 }
                 //NO RESTRICTION--------------------------------
             } else {
                 if ($get_result['coupon_type'] == 'F') {
                     $tod_amount = 0;
                     if ($method == 'Credit Note') {
                         $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate;
                         $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                     } else {
                         reset($order->info['tax_groups']);
                         while (list($key, $value) = each($order->info['tax_groups'])) {
                             $ratio1 = $od_amount / ($amount - $order->info['tax_groups'][$key]);
                             $tax_rate = tep_get_tax_rate_from_desc($key);
                             $net = $tax_rate * $order->info['tax_groups'][$key];
                             if ($net > 0) {
                                 $god_amount = $order->info['tax_groups'][$key] * $ratio1;
                                 $tod_amount += $god_amount;
                                 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                             }
                         }
                     }
                     $order->info['tax'] -= $tod_amount;
                 }
                 if ($get_result['coupon_type'] == 'P') {
                     $tod_amount = 0;
                     if ($method == 'Credit Note') {
                         $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100;
                         $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                     } else {
                         reset($order->info['tax_groups']);
                         while (list($key, $value) = each($order->info['tax_groups'])) {
                             $god_amount = 0;
                             $tax_rate = tep_get_tax_rate_from_desc($key);
                             $net = $tax_rate * $order->info['tax_groups'][$key];
                             if ($net > 0) {
                                 $god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount'] / 100;
                                 $tod_amount += $god_amount;
                                 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                             }
                         }
                     }
                     $order->info['tax'] -= $tod_amount;
                 }
             }
         }
     }
     return $tod_amount;
 }