function quote($method = '') { global $order, $shipping_weight; $calc_weight = $shipping_weight; $error = false; $dest_country = $order->delivery['country']['iso_code_2']; if (defined('MODULE_SHIPPING_CHINAPOSTREGISTERED_BASIS_WEIGHT_FEE') && defined('MODULE_SHIPPING_CHINAPOSTREGISTERED_BASIS_WEIGHT') && defined('MODULE_SHIPPING_CHINAPOSTREGISTERED_REST_WEIGHT_UNIT_FEE') && MODULE_SHIPPING_CHINAPOSTREGISTERED_REST_WEIGHT_UNIT_FEE > 0) { if ($calc_weight <= MODULE_SHIPPING_CHINAPOSTREGISTERED_BASIS_WEIGHT) { $shipping_cost = MODULE_SHIPPING_CHINAPOSTREGISTERED_BASIS_WEIGHT_FEE + MODULE_SHIPPING_CHINAPOSTREGISTERED_REGISTER_FEE; } else { $calc_weight = $calc_weight - MODULE_SHIPPING_CHINAPOSTREGISTERED_BASIS_WEIGHT; $shipping_cost = ceil($calc_weight / MODULE_SHIPPING_CHINAPOSTREGISTERED_REST_WEIGHT_UNIT) * MODULE_SHIPPING_CHINAPOSTREGISTERED_REST_WEIGHT_UNIT_FEE; $shipping_cost = MODULE_SHIPPING_CHINAPOSTREGISTERED_BASIS_WEIGHT_FEE + $shipping_cost + MODULE_SHIPPING_CHINAPOSTREGISTERED_REGISTER_FEE; } $shipping_method = MODULE_SHIPPING_CHINAPOSTREGISTERED_TEXT_WAY . ' ' . $dest_country . ' (' . number_format($shipping_weight, 2) . MODULE_SHIPPING_CHINAPOSTREGISTERED_TEXT_UNITS . ') '; //modified by john 2010-06-30 //for better calculate with currency $shipping_cost = $shipping_cost / (defined('MODULE_SHIPPING_CHINAPOSTREGISTERED_EXCHANGE_RATE') ? MODULE_SHIPPING_CHINAPOSTREGISTERED_EXCHANGE_RATE : 1); } if ($shipping_weight > MODULE_SHIPPING_CHINAPOSTREGISTERED_BEYOND_WEIGHTLIMIT) { $error = true; } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_CHINAPOSTREGISTERED_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } if ($error == true) { $this->quotes['error'] = MODULE_SHIPPING_CHINAPOSTREGISTERED_BEYOND_WEIGHTLIMIT_TEXT; } return $this->quotes; }
/** * @param $order * @return string */ public static function getCartContents($order) { $countLines = 1; $shipping = number_format($order->info['shipping_cost'], 2, '.', ''); $shippingtax = number_format($order->info['shipping_tax'], 2, '.', ''); $totalshipping = number_format($shipping + $shippingtax, 2, '.', ''); $shippingStr = ":Shipping:---:" . $shipping . ":" . $shippingtax . ":" . $totalshipping . ":" . $totalshipping; $products = $_SESSION['cart']->get_products(); $productLines = ''; for ($i = 0, $n = sizeof($products); $i < $n; $i++) { $desc = str_replace(":", "", $order->products[$i]['name']); $qty = $order->products[$i]['qty']; $price = $order->products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']); $tax = $price / 100 * zen_get_tax_rate($products[$i]['tax_class_id']); $tax = number_format($tax, 2, '.', ''); $finalPrice = $price + $tax; $finalPrice = number_format($finalPrice, 2, '.', ''); $lineTotal = $qty * $finalPrice; $lineTotal = number_format($lineTotal, 2, '.', ''); $line = ":" . $desc . ":" . $qty . ":" . $price . ":" . $tax . ":" . $finalPrice . ":" . $lineTotal; $productLines .= $line; $countLines++; } return $countLines . $productLines . $shippingStr; }
function quote($method = '') { global $order, $shipping_weight; $error = false; $dest_country = $order->delivery['country']['iso_code_2']; if (defined('MODULE_SHIPPING_HKPOSTREGISTERED_COST_UNIT') && MODULE_SHIPPING_HKPOSTREGISTERED_COST_UNIT > 0) { //hkpost weight as gram g. $shipping_cost = MODULE_SHIPPING_HKPOSTREGISTERED_COST_UNIT * $shipping_weight; if (defined('MODULE_SHIPPING_HKPOSTREGISTERED_HANDLE_FEE') && MODULE_SHIPPING_HKPOSTREGISTERED_HANDLE_FEE > 0) { $shipping_cost += MODULE_SHIPPING_HKPOSTREGISTERED_HANDLE_FEE; } //$shipping_method = MODULE_SHIPPING_HKPOSTREGISTERED_TEXT_WAY . ' ' . $dest_country . ' ('.number_format($shipping_weight,2).MODULE_SHIPPING_HKPOSTREGISTERED_TEXT_UNITS.')'; $shipping_method = MODULE_SHIPPING_HKPOSTREGISTERED_TEXT_WAY; //############################for better calculate with currency######################### //modified by john 2010-06-30 2/3 $shipping_cost = $shipping_cost / (defined('MODULE_SHIPPING_HKPOSTREGISTERED_EXCHANGE_RATE') ? MODULE_SHIPPING_HKPOSTREGISTERED_EXCHANGE_RATE : 1); } if ($shipping_weight > MODULE_SHIPPING_HKPOSTREGISTERED_BEYOND_WEIGHTLIMIT) { $error = true; } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_HKPOSTREGISTERED_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } if ($error == true) { $this->quotes['error'] = MODULE_SHIPPING_HKPOSTREGISTERED_BEYOND_WEIGHTLIMIT_TEXT; } return $this->quotes; }
function quote($method = '') { global $order; if ($this->enabled) { $excluded_array = explode(',', MODULE_SHIPPING_PREFERRED_SHIPPING_EXCLUDED_PRODUCTS); $products_in_cart_array = explode(',', $_SESSION['cart']->get_product_id_list()); echo var_dump($products_in_cart_array); foreach ($products_in_cart_array as $product_in_cart) { $base_product_in_cart = substr($product_in_cart, 0, strpos($product_in_cart, ':')); if (in_array($base_product_in_cart, $excluded_array)) { $this->enabled = false; } } if ($_SESSION['cart']->show_total() < MODULE_SHIPPING_PREFERRED_SHIPPING_MIN_ORDER) { $this->enabled = false; } } if ($this->enabled) { $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_PREFERRED_SHIPPING_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_PREFERRED_SHIPPING_TEXT_WAY, 'cost' => '0.00'))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } } return $this->quotes; }
function quote($pShipHash = array()) { global $order, $currencies; $this->quotes['id'] = $this->code; $this->quotes['module'] = tra('SuperSaver Shipping'); $this->quotes['icon'] = $this->icon; $min = MODULE_SHIPPING_SUPERSAVER_MIN; $max = MODULE_SHIPPING_SUPERSAVER_MAX; if (!empty($min) && $order->subtotal < MODULE_SHIPPING_SUPERSAVER_MIN) { $this->quotes['error'] = tra('You must spend at least ' . $currencies->format(MODULE_SHIPPING_SUPERSAVER_MIN) . ' to get SuperSaver Shipping.') . ' <a href="' . zen_href_link(FILENAME_SHOPPING_CART) . '">' . tra('Update Cart') . '</a>'; } elseif (!empty($max) && $order->subtotal > MODULE_SHIPPING_SUPERSAVER_MAX) { // no quote for you! $this->quotes['error'] = tra('SuperSaver Shipping only applies to orders up to ' . $currencies->format(MODULE_SHIPPING_SUPERSAVER_MAX)) . ' <a href="' . zen_href_link(FILENAME_SHOPPING_CART) . '">' . tra('Update Cart') . '</a>'; } else { $this->quotes['note'] = tra(MODULE_SHIPPING_SUPERSAVER_DESC); if (SHIPPING_ORIGIN_COUNTRY == $order->delivery['country']['countries_id'] && MODULE_SHIPPING_SUPERSAVER_DOMESTIC == 'True') { $desc = tra(MODULE_SHIPPING_SUPERSAVER_DESC) . ' ' . tra(MODULE_SHIPPING_SUPERSAVER_DOMESTIC_DESC); $this->quotes['methods'] = array(array('id' => $this->code, 'title' => trim($desc), 'code' => 'supersaver', 'cost' => MODULE_SHIPPING_SUPERSAVER_DOMESTIC_COST + MODULE_SHIPPING_SUPERSAVER_HANDLING)); } elseif (MODULE_SHIPPING_SUPERSAVER_INTL == 'True') { $desc = tra(MODULE_SHIPPING_SUPERSAVER_DESC) . ' ' . tra(MODULE_SHIPPING_SUPERSAVER_INTL_DESC); $this->quotes['methods'] = array(array('id' => $this->code, 'title' => trim($desc), 'code' => 'supersaverintl', 'cost' => MODULE_SHIPPING_SUPERSAVER_INTL_COST + MODULE_SHIPPING_SUPERSAVER_HANDLING)); } if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['countries_id'], $order->delivery['zone_id']); } } return $this->quotes; }
function convert_product_attributes_result($attributes_values, $load_option_name = true, $can_operate = false) { if ($load_option_name) { $attributes_values->fields['products_options_name'] = zen_options_name($attributes_values->fields['options_id']); $attributes_values->fields['products_options_values_name'] = zen_values_name($attributes_values->fields['options_values_id']); } $attributes_values->fields['products_display_price'] = $attributes_values->fields['price_prefix'] . $attributes_values->fields['options_values_price']; $attributes_values->fields['products_attributes_display_weight'] = $attributes_values->fields['products_attributes_weight_prefix'] . $attributes_values->fields['products_attributes_weight']; require_once DIR_WS_CLASSES . 'currencies.php'; $currencies = new currencies(); $attributes_price_final = zen_get_attributes_price_final($attributes_values->fields["products_attributes_id"], 1, $attributes_values, 'false'); $attributes_price_final_value = $attributes_price_final; $attributes_price_final = $currencies->display_price($attributes_price_final, zen_get_tax_rate(1), 1); $attributes_price_final_onetime = zen_get_attributes_price_final_onetime($attributes_values->fields["products_attributes_id"], 1, $attributes_values); $attributes_price_final_onetime = $currencies->display_price($attributes_price_final_onetime, zen_get_tax_rate(1), 1); $new_attributes_price = ''; if ($attributes_values->fields["attributes_discounted"]) { $new_attributes_price = zen_get_attributes_price_final($attributes_values->fields["products_attributes_id"], 1, '', 'false'); $new_attributes_price = zen_get_discount_calc($attributes_values->fields['products_id'], true, $new_attributes_price); if ($new_attributes_price != $attributes_price_final_value) { $new_attributes_price = '|' . $currencies->display_price($new_attributes_price, zen_get_tax_rate(1), 1); } else { $new_attributes_price = ''; } } $attributes_values->fields['attributes_display_price_final'] = $attributes_price_final . $new_attributes_price . ' ' . $attributes_price_final_onetime; // status $attributes_values->fields['products_status'] = ""; foreach ($this->statuses as $type => $icon_info) { $attributes_values->fields['products_status'] .= self::make_status_link($attributes_values->fields, $type, $icon_info['color'], $icon_info['alt'], $can_operate); } return $attributes_values->fields; }
function quote($pShipHash = array()) { global $order; $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'code' => $this->code, 'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY, 'cost' => MODULE_SHIPPING_STOREPICKUP_COST))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['countries_id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = $this->icon; } return $this->quotes; }
function quote($method = '') { global $order; $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_FREESHIPPER_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_FREESHIPPER_TEXT_WAY, 'cost' => MODULE_SHIPPING_FREESHIPPER_COST + MODULE_SHIPPING_FREESHIPPER_HANDLING))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } return $this->quotes; }
function quote($method = '') { global $order, $total_count; // adjusted count for free shipping $item_total_count = $total_count - $_SESSION['cart']->free_shipping_items(); $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_ITEM_TEXT_WAY, 'cost' => MODULE_SHIPPING_ITEM_COST * $item_total_count + MODULE_SHIPPING_ITEM_HANDLING))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } return $this->quotes; }
function quote($pShipHash = array()) { global $order, $total_count; // adjusted count for free shipping // $total_count = $total_count - $gBitCustomer->mCart->in_cart_check('product_is_free','1'); // $total_count = $total_count - $gBitCustomer->mCart->in_cart_check('product_is_always_free_ship','1'); $total_count = $total_count - $gBitCustomer->mCart->free_shipping_items(); $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_ITEM_TEXT_WAY, 'cost' => MODULE_SHIPPING_ITEM_COST * $total_count + MODULE_SHIPPING_ITEM_HANDLING))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['countries_id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = $this->icon; } return $this->quotes; }
function quote($method = '') { global $order, $shipping_weight; $calc_weight = $shipping_weight; $error = false; $dest_country = $order->delivery['country']['iso_code_2']; if (defined('MODULE_SHIPPING_EMS_BASIS_WEIGHT_FEE') && defined('MODULE_SHIPPING_EMS_BASIS_WEIGHT') && defined('MODULE_SHIPPING_EMS_REST_WEIGHT_UNIT_FEE') && MODULE_SHIPPING_EMS_REST_WEIGHT_UNIT_FEE > 0) { if ($calc_weight <= MODULE_SHIPPING_EMS_BASIS_WEIGHT) { $shipping_cost = MODULE_SHIPPING_EMS_BASIS_WEIGHT_FEE + MODULE_SHIPPING_EMS_HANDLING_FEE; } else { $calc_weight = $calc_weight - MODULE_SHIPPING_EMS_BASIS_WEIGHT; $shipping_cost = ceil($calc_weight / MODULE_SHIPPING_EMS_REST_WEIGHT_UNIT) * MODULE_SHIPPING_EMS_REST_WEIGHT_UNIT_FEE; $shipping_cost = MODULE_SHIPPING_EMS_BASIS_WEIGHT_FEE + $shipping_cost + MODULE_SHIPPING_EMS_HANDLING_FEE; } /*$shipping_method = MODULE_SHIPPING_EMS_TEXT_WAY . ' ' . $dest_country . ' ('.number_format($shipping_weight,2).MODULE_SHIPPING_EMS_TEXT_UNITS.') ';*/ $shipping_method = MODULE_SHIPPING_EMS_TEXT_WAY; //############################for better calculate with currency######################### //modified by john 2010-06-30 1/3 $shipping_cost = $shipping_cost / (defined('MODULE_SHIPPING_EMS_EXCHANGE_RATE') ? MODULE_SHIPPING_EMS_EXCHANGE_RATE : 1); } if (defined('MODULE_SHIPPING_EMS_ENABLED_COUNTRIES')) { $enable_countries = split('[,]', MODULE_SHIPPING_EMS_ENABLED_COUNTRIES); if (is_array($enable_countries) && !in_array($dest_country, $enable_countries)) { $error = true; } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_EMS_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } if ($error == true) { $this->quotes['error'] = MODULE_SHIPPING_EMS_NOT_DISPATCH_TO_TEXT . ' ' . $dest_country; } return $this->quotes; }
function quote($method = '') { global $order, $shipping_weight, $shipping_num_boxes; $dest_country = $order->delivery['country']['iso_code_2']; $dest_zone = 0; $error = false; for ($i = 1; $i <= $this->num_zones; $i++) { $countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $i); $country_zones = split("[,]", $countries_table); if (in_array($dest_country, $country_zones)) { $dest_zone = $i; break; } } if ($dest_zone == 0) { $error = true; } else { $shipping = -1; $zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $dest_zone); $zones_table = split("[:,]", $zones_cost); $size = sizeof($zones_table); for ($i = 0; $i < $size; $i += 2) { if (MODULE_SHIPPING_ZONES_METHOD == 'Weight') { if ($shipping_weight <= $zones_table[$i]) { $shipping = $zones_table[$i + 1]; switch (SHIPPING_BOX_WEIGHT_DISPLAY) { case 0: $show_box_weight = ''; break; case 1: $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')'; break; case 2: $show_box_weight = ' (' . number_format($shipping_weight * $shipping_num_boxes, 2) . MODULE_SHIPPING_ZONES_TEXT_UNITS . ')'; break; default: $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight, 2) . MODULE_SHIPPING_ZONES_TEXT_UNITS . ')'; break; } // $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . (SHIPPING_BOX_WEIGHT_DISPLAY >= 2 ? ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS : ''); $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . $show_box_weight; break; } } else { // shipping adjustment if ($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices() <= $zones_table[$i]) { $shipping = $zones_table[$i + 1]; $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country; break; } } } if ($shipping == -1) { $shipping_cost = 0; $shipping_method = MODULE_SHIPPING_ZONES_UNDEFINED_RATE; } else { if (MODULE_SHIPPING_ZONES_METHOD == 'Weight') { $shipping_cost = $shipping * $shipping_num_boxes + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone); } else { // don't charge per box when done by Price $shipping_cost = $shipping + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone); } } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } if ($error == true) { $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE; } return $this->quotes; }
<td><?php echo $quantityDiscount['show_qty']; ?> </td> <?php if (!isset($_SESSION['customer_id']) && $key + 1 > SHOW_PRICE_QTY_MAX_GROUP) { ?> <td><a rel="nofollow" href="<?php echo zen_href_link(FILENAME_LOGIN, '', 'SSL'); ?> ">Login</a></td> <?php } else { ?> <td><?php echo $currencies->display_price($quantityDiscount['discounted_price'], zen_get_tax_rate($products_tax_class_id)); ?> </td> <?php } ?> </tr> <?php /*$disc_cnt++; if ($discount_col_cnt == $disc_cnt && !($key == sizeof($quantityDiscount))) { $disc_cnt=0; }*/ } /*if ($disc_cnt < $columnCount) { ?> <td align="center" colspan="<?php echo ($columnCount+1 - $disc_cnt)+1; ?>"> </td>
</td> <td class="smallText" align="center"><?php echo ($attributes_values->fields["attributes_required"] == '0' ? '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_required' . '&attributes_id=' . $attributes_values->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_red_off.gif', LEGEND_ATTRIBUTES_REQUIRED) . '</a>' : '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_required' . '&attributes_id=' . $attributes_values->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_red_on.gif', LEGEND_ATTRIBUTES_REQUIRED)) . '</a>'; ?> </td> </tr> </table> </td> <?php } $new_attributes_price = ''; if ($attributes_values->fields["attributes_discounted"]) { $new_attributes_price = zen_get_attributes_price_final($attributes_values->fields["products_attributes_id"], 1, '', 'false'); $new_attributes_price = zen_get_discount_calc($products_filter, true, $new_attributes_price); if ($new_attributes_price != $attributes_price_final_value) { $new_attributes_price = '|' . $currencies->display_price($new_attributes_price, zen_get_tax_rate($product_check->fields['products_tax_class_id']), 1); } else { $new_attributes_price = ''; } } ?> <td align="right" class="smallText"><?php echo $attributes_price_final . $new_attributes_price . ' ' . $attributes_price_final_onetime; ?> </td> <?php if ($action != '') { ?> <td width='120' align="center" class="smallText"> </td> <?php } else {
function _build_attributes_array($build_stocked, $build_nonstocked) { global $languages_id; global $currencies; global $cart; global $db; if (!($build_stocked | $build_nonstocked)) { return null; } if ($build_stocked && $build_nonstocked) { $stocked_where = ""; } elseif ($build_stocked) { $stocked_where = "and popt.products_options_track_stock = 1"; } elseif ($build_nonstocked) { $stocked_where = "and popt.products_options_track_stock = 0"; } $products_options_name_query = "select distinct popt.products_options_id, popt.products_options_name, popt.products_options_track_stock, popt.products_options_images_style, popt.products_options_type from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id = :products_id: and popt.products_options_id = patrib.options_id and popt.language_id = :languages_id: :stocked_where: order by popt.products_options_sort_order"; $products_options_name_query = $db->bindVars($products_options_name_query, ':products_id:', $this->products_id, 'integer'); $products_options_name_query = $db->bindVars($products_options_name_query, ':languages_id:', $_SESSION['languages_id'], 'integer'); $products_options_name_query = $db->bindVars($products_options_name_query, ':stocked_where:', $stocked_where, 'passthru'); $products_options_name = $db->Execute($products_options_name_query); $attributes = array(); while (!$products_options_name->EOF) { $products_options_array = array(); $products_options_query = "select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = :products_id: and pa.options_id = :products_options_id: and pa.options_values_id = pov.products_options_values_id and pov.language_id = :languages_id: order by pa.products_options_sort_order"; $products_options_query = $db->bindVars($products_options_query, ':products_id:', $this->products_id, 'integer'); $products_options_query = $db->bindVars($products_options_query, ':languages_id:', $_SESSION['languages_id'], 'integer'); $products_options_query = $db->bindVars($products_options_query, ':products_options_id:', $products_options_name->fields['products_options_id'], 'integer'); $products_options = $db->Execute($products_options_query); while (!$products_options->EOF) { /**** AGF - add logic to format colours ******/ $value_name = $products_options->fields['products_options_values_name']; //if ( $products_options_name['products_options_name'] = 'Color' ) { // $value_name="<span class=\"col" . $value_name . "\">" . $value_name . "</span>"; //} $products_options_array[] = array('id' => $products_options->fields['products_options_values_id'], 'text' => $value_name); /**** AGF - end of new logic ******/ // AGF commented out +/- amount to show actual price if ($products_options->fields['options_values_price'] != '0') { $products_options_array[sizeof($products_options_array) - 1]['text'] .= ' (' . $products_options->fields['price_prefix'] . $currencies->display_price($products_options->fields['options_values_price'], zen_get_tax_rate($this->products_tax_class_id)) . ')'; } /// Start of Changes- display actual prices instead of +/- Actual Price Pull Down v1.2.3a $new_price ? $original_price = $new_price : ($original_price = $this->products_original_price); //// check if set special price note $this variable $option_price = $products_options->fields['options_values_price']; if ($products_options->fields['price_prefix'] == "-") { $show_price = 0.0 + $original_price - $option_price; // force float (in case) using the 0.0; } else { $show_price = 0.0 + $original_price + $option_price; // force float (in case) using the 0.0; } $products_options_array[sizeof($products_options_array) - 1]['text'] .= ' '; // note $this variable //HW: THIS WAS BROKEN - tax class ID was being used as the tax rate.. so a fixed 8 percent in my case. // End Of MOD $products_options->MoveNext(); } if (isset($_GET['products_id']) && zen_not_null($_GET['products_id']) && isset($_SESSION['cart']->contents[$_GET['products_id']]['attributes'][$products_options_name->fields['products_options_id']])) { $selected = $_SESSION['cart']->contents[$_GET['products_id']]['attributes'][$products_options_name->fields['products_options_id']]; } else { $selected = 0; } $attributes[] = array('oid' => $products_options_name->fields['products_options_id'], 'oname' => $products_options_name->fields['products_options_name'], 'oimgstyle' => $products_options_name->fields['products_options_images_style'], 'ovals' => $products_options_array, 'otype' => $products_options_name->fields['products_options_type'], 'default' => $selected); $products_options_name->MoveNext(); } return $attributes; }
/** * Prepare subtotal and line-item detail content to send to PayPal */ function getLineItemDetails() { global $order, $currencies, $order_totals, $order_total_modules; $optionsST = array(); $optionsLI = array(); $onetimeSum = 0; $onetimeTax = 0; $creditsApplied = 0; $creditsTax_applied = 0; $sumOfLineItems = 0; $sumOfLineTax = 0; // prepare subtotals for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) { if ($order_totals[$i]['code'] == 'ot_subtotal') { $optionsST['ITEMAMT'] = round($order_totals[$i]['value'], 2); } if ($order_totals[$i]['code'] == 'ot_tax') { $optionsST['TAXAMT'] = round($order_totals[$i]['value'], 2); } if ($order_totals[$i]['code'] == 'ot_shipping') { $optionsST['SHIPPINGAMT'] = round($order_totals[$i]['value'], 2); } if ($order_totals[$i]['code'] == 'ot_total') { $optionsST['AMT'] = round($order_totals[$i]['value'], 2); } $optionsST['HANDLINGAMT'] = 0; global ${$order_totals[$i]['code']}; if (isset(${$order_totals[$i]['code']}->credit_class) && ${$order_totals[$i]['code']}->credit_class == true) { $creditsApplied += round($order_totals[$i]['value'], 2); } // treat all other OT's as if they're related to handling fees if (!in_array($order_totals[$i]['code'], array('ot_total', 'ot_subtotal', 'ot_tax', 'ot_shipping')) && !(isset(${$order_totals[$i]['code']}->credit_class) && ${$order_totals[$i]['code']}->credit_class == true)) { $optionsST['HANDLINGAMT'] += $order_totals[$i]['value']; } } // Move shipping tax amount from Tax subtotal into Shipping subtotal for submission to PayPal $module = substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_')); if (zen_not_null($order->info['shipping_method'])) { if ($GLOBALS[$module]->tax_class > 0) { $shipping_tax_basis = !isset($GLOBALS[$module]->tax_basis) ? STORE_SHIPPING_TAX_BASIS : $GLOBALS[$module]->tax_basis; $shippingOnBilling = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']); $shippingOnDelivery = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); if ($shipping_tax_basis == 'Billing') { $shipping_tax = $shippingOnBilling; } elseif ($shipping_tax_basis == 'Shipping') { $shipping_tax = $shippingOnDelivery; } else { if (STORE_ZONE == $order->billing['zone_id']) { $shipping_tax = $shippingOnBilling; } elseif (STORE_ZONE == $order->delivery['zone_id']) { $shipping_tax = $shippingOnDelivery; } else { $shipping_tax = 0; } } $taxAdjustmentForShipping = zen_calculate_tax($order->info['shipping_cost'], $shipping_tax); $optionsST['SHIPPINGAMT'] += $taxAdjustmentForShipping; $optionsST['TAXAMT'] -= $taxAdjustmentForShipping; } } // loop thru all products to display quantity and price. Appends *** if out-of-stock. for ($i = 0, $n = sizeof($order->products), $k = 0; $i < $n; $i++, $k++) { $optionsLI["L_NUMBER{$k}"] = $order->products[$i]['model']; $optionsLI["L_QTY{$k}"] = (int) $order->products[$i]['qty']; $optionsLI["L_NAME{$k}"] = $order->products[$i]['name']; $optionsLI["L_NAME{$k}"] .= zen_get_products_stock($order->products[$i]['id']) - $order->products[$i]['qty'] < 0 ? STOCK_MARK_PRODUCT_OUT_OF_STOCK : ''; // if there are attributes, loop thru them and add to description if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) { for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) { $optionsLI["L_NAME{$k}"] .= "\n " . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value']; } // end loop } // endif attribute-info $optionsLI["L_AMT{$k}"] = $order->products[$i]['final_price']; $optionsLI["L_TAXAMT{$k}"] = zen_calculate_tax($order->products[$i]['final_price'], $order->products[$i]['tax']); // track one-time charges if ($order->products[$i]['onetime_charges'] != 0) { $onetimeSum += $order->products[$i]['onetime_charges']; $onetimeTax += zen_calculate_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']); } // Replace & and = with * if found. $optionsLI["L_NAME{$k}"] = str_replace(array('&', '='), '*', $optionsLI["L_NAME{$k}"]); $optionsLI["L_NAME{$k}"] = zen_clean_html($optionsLI["L_NAME{$k}"], 'strong'); // reformat properly $optionsLI["L_NUMBER{$k}"] = substr($optionsLI["L_NUMBER{$k}"], 0, 127); $optionsLI["L_NAME{$k}"] = substr($optionsLI["L_NAME{$k}"], 0, 127); $optionsLI["L_AMT{$k}"] = $optionsLI["L_AMT{$k}"]; $optionsLI["L_TAXAMT{$k}"] = round($optionsLI["L_TAXAMT{$k}"], 2); } // end for loopthru all products if ($onetimeSum > 0) { $i++; $k++; $optionsLI["L_NUMBER{$k}"] = $k; $optionsLI["L_NAME{$k}"] = 'One-Time Charges'; $optionsLI["L_AMT{$k}"] = $onetimeSum; $optionsLI["L_TAXAMT{$k}"] = $onetimeTax; $optionsLI["L_QTY{$k}"] = 1; } // handle discounts such as gift certificates and coupons if ($creditsApplied > 0) { $optionsST['HANDLINGAMT'] -= $creditsApplied; } // add all one-time charges $optionsST['ITEMAMT'] += $onetimeSum; //ensure things are not negative $optionsST['HANDLINGAMT'] = abs(strval($optionsST['HANDLINGAMT'])); // ensure all numbers are non-negative if (is_array($optionsST)) { foreach ($optionsST as $key => $value) { $optionsST[$key] = abs(strval($value)); } } if (is_array($optionsLI)) { foreach ($optionsLI as $key => $value) { if (strstr($key, 'AMT')) { $optionsLI[$key] = abs(strval($value)); } } } // subtotals have to add up to AMT // Thus, if there is a discrepancy, make adjustment to HANDLINGAMT: $st = $optionsST['ITEMAMT'] + $optionsST['TAXAMT'] + $optionsST['SHIPPINGAMT'] + $optionsST['HANDLINGAMT']; if ($st != $optionsST['AMT']) { $optionsST['HANDLINGAMT'] += strval($optionsST['AMT'] - $st); } /* //PayPal API spec contradicts itself ... and apparently neither of these "requirements" are enforced. //Thus skipping this section for now: // according to API specs, these cannot be set if they contain zero values, so unset if they are zero: if ($optionsST['TAXAMT'] == 0) unset($optionsST['TAXAMT']); if ($optionsST['SHIPPINGAMT'] == 0) unset($optionsST['SHIPPINGAMT']); if ($optionsST['HANDLINGAMT'] == 0) unset($optionsST['HANDLINGAMT']); // set missing subtotals if they are zero values, since all must be submitted if (!isset($optionsST['TAXAMT'])) $optionsST['TAXAMT'] = 0; if (!isset($optionsST['SHIPPINGAMT'])) $optionsST['SHIPPINGAMT'] = 0; if (!isset($optionsST['HANDLINGAMT'])) $optionsST['HANDLINGAMT'] = 0; */ // Since the PayPal spec cannot handle mathematically mismatched values caused by one-time charges, // must drop line-item details if any one-time charges apply to this order: // if there are any discounts in this order, do NOT supply line-item details if ($onetimeSum > 0) { $optionsLI = array(); } // Do sanity check -- if any of the line-item subtotal math doesn't add up properly, skip line-item details, // so that the order can go through even though PayPal isn't being flexible to handle Zen Cart's diversity for ($j = 0; $j < $k; $j++) { $itemAMT = $optionsLI["L_AMT{$j}"]; $itemTAX = $optionsLI["L_TAXAMT{$j}"]; $itemQTY = $optionsLI["L_QTY{$j}"]; $sumOfLineItems += $itemQTY * $itemAMT; $sumOfLineTax += round($itemQTY * $itemTAX, 2); } if ((double) $optionsST['ITEMAMT'] != (double) strval($sumOfLineItems)) { $optionsLI = array(); $this->zcLog('getLineItemDetails 1', 'Order Subtotal does not match sum of line-item prices. Line-item-details skipped.' . "\n" . (double) $optionsST['ITEMAMT'] . ' ' . (double) $sumOfLineItems); //die('ITEMAMT != $sumOfLineItems ' . $optionsST['ITEMAMT'] . ' ' . $sumOfLineItems); } if ((double) $optionsST['TAXAMT'] != (double) strval($sumOfLineTax)) { $optionsLI = array(); $this->zcLog('getLineItemDetails 2', 'Tax Subtotal does not match sum of taxes for line-items. Line-item-details skipped.' . "\n" . $optionsST['TAXAMT'] . ' ' . $sumOfLineTax); //die('TAXAMT != $sumofLineTax ' . $optionsST['TAXAMT'] . ' ' . $sumOfLineTax); } $this->zcLog('getLineItemDetails 3', 'LineItemDetails: ' . "\n" . ($creditsApplied ? 'Credits apply to this order, so all line-item details are NOT being submitted. Thus, the following data is REDUNDANT' . "\n" : '') . 'Details:' . print_r(array_merge($optionsST, $optionsLI), true) . "\n\n" . 'DEFAULT_CURRENCY = ' . DEFAULT_CURRENCY . "\nSESSION['currency'] = " . $_SESSION['currency'] . "\n" . "order->info['currency'] = " . $order->info['currency'] . "\n\$currencies->currencies[\$_SESSION['currency']]['value'] = " . $currencies->currencies[$_SESSION['currency']]['value'] . "\n" . print_r($currencies, true)); // if not default currency, do not send subtotals or line-item details if (DEFAULT_CURRENCY != $order->info['currency']) { $this->zcLog('getLineItemDetails 4', 'Not using default currency. Thus, no line-item details can be submitted.'); return array(); } if ($currencies->currencies[$_SESSION['currency']]['value'] != 1) { $this->zcLog('getLineItemDetails 5', 'currency val not equal to 1.0000 - cannot proceed without coping with currency conversions. Aborting line-item details.'); return array(); } // if there are any discounts in this order, do not supply subtotals or line-item details if (strval($creditsApplied) > 0) { return array(); } //$this->zcLog('getLineItemDetails 6', 'no credits - okay'); // if subtotals are not adding up correctly, then skip sending any line-item or subtotal details to PayPal $st = round(strval($optionsST['ITEMAMT'] + $optionsST['TAXAMT'] + $optionsST['SHIPPINGAMT'] + $optionsST['HANDLINGAMT']), 2); $stDiff = strval($optionsST['AMT'] - $st); $stDiffRounded = strval(abs($st) - abs(round($optionsST['AMT'], 2))); // tidy up all values so that they comply with proper format (number_format(xxxx,2) for PayPal US use ) if (!defined('PAYPALWPP_SKIP_LINE_ITEM_DETAIL_FORMATTING') || PAYPALWPP_SKIP_LINE_ITEM_DETAIL_FORMATTING != 'true') { if (is_array($optionsST)) { foreach ($optionsST as $key => $value) { $optionsST[$key] = number_format(abs($value), 2); } } if (is_array($optionsLI)) { foreach ($optionsLI as $key => $value) { if (strstr($key, 'AMT')) { $optionsLI[$key] = number_format(abs($value), 2); } } } } $this->zcLog('getLineItemDetails 7', 'checking subtotals... ' . "\nitemamt: " . $optionsST['ITEMAMT'] . "\ntaxamt: " . $optionsST['TAXAMT'] . "\nshippingamt: " . $optionsST['SHIPPINGAMT'] . "\nhandlingamt: " . $optionsST['HANDLINGAMT'] . "\n-------------------\nsubtotal: " . number_format($st, 2) . "\nAMT: " . $optionsST['AMT'] . "\n-------------------\ndifference: " . $stDiff . ' (abs+rounded: ' . $stDiffRounded . ')'); if ($stDiffRounded != 0) { return array(); } //die('bad subtotals'); //return array(); $this->zcLog('getLineItemDetails 8', 'subtotals balance - okay'); if (abs($optionsST['HANDLINGAMT']) == 0) { unset($optionsST['HANDLINGAMT']); } // Send Subtotal and LineItem results back to be submitted to PayPal return array_merge($optionsST, $optionsLI); }
/** * Prepare subtotal and line-item detail content to send to PayPal */ function getLineItemDetails($restrictedCurrency) { global $order, $currencies, $order_totals, $order_total_modules; // if not default currency, do not send subtotals or line-item details if (DEFAULT_CURRENCY != $order->info['currency'] || $restrictedCurrency != DEFAULT_CURRENCY) { $this->zcLog('getLineItemDetails 1', 'Not using default currency. Thus, no line-item details can be submitted.'); return array(); } if ($currencies->currencies[$_SESSION['currency']]['value'] != 1 || $currencies->currencies[$order->info['currency']]['value'] != 1) { $this->zcLog('getLineItemDetails 2', 'currency val not equal to 1.0000 - cannot proceed without coping with currency conversions. Aborting line-item details.'); return array(); } $optionsST = array(); $optionsLI = array(); $optionsNB = array(); $numberOfLineItemsProcessed = 0; $creditsApplied = 0; $surcharges = 0; $sumOfLineItems = 0; $sumOfLineTax = 0; $optionsST['AMT'] = 0; $optionsST['ITEMAMT'] = 0; $optionsST['TAXAMT'] = 0; $optionsST['SHIPPINGAMT'] = 0; $optionsST['SHIPDISCAMT'] = 0; $optionsST['HANDLINGAMT'] = 0; $optionsST['INSURANCEAMT'] = 0; $flagSubtotalsUnknownYet = true; $subTotalLI = 0; $subTotalTax = 0; $subTotalShipping = 0; $subtotalPRE = array('no data'); $discountProblemsFlag = FALSE; $flag_treat_as_partial = FALSE; if (sizeof($order_totals)) { // prepare subtotals for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) { if ($order_totals[$i]['code'] == '') { continue; } if (in_array($order_totals[$i]['code'], array('ot_total', 'ot_subtotal', 'ot_tax', 'ot_shipping')) || strstr($order_totals[$i]['code'], 'insurance')) { if ($order_totals[$i]['code'] == 'ot_shipping') { $optionsST['SHIPPINGAMT'] = round($order_totals[$i]['value'], 2); } if ($order_totals[$i]['code'] == 'ot_total') { $optionsST['AMT'] = round($order_totals[$i]['value'], 2); } if ($order_totals[$i]['code'] == 'ot_tax') { $optionsST['TAXAMT'] = round($order_totals[$i]['value'], 2); } if ($order_totals[$i]['code'] == 'ot_subtotal') { $optionsST['ITEMAMT'] = round($order_totals[$i]['value'], 2); } if (strstr($order_totals[$i]['code'], 'insurance')) { $optionsST['INSURANCEAMT'] += round($order_totals[$i]['value'], 2); } //$optionsST['SHIPDISCAMT'] = ''; // Not applicable } else { // handle other order totals: global ${$order_totals[$i]['code']}; if (substr($order_totals[$i]['text'], 0, 1) == '-' || isset(${$order_totals[$i]['code']}->credit_class) && ${$order_totals[$i]['code']}->credit_class == true) { // handle credits $creditsApplied += round($order_totals[$i]['value'], 2); } else { // treat all other OT's as if they're related to handling fees or other extra charges to be added/included $surcharges += $order_totals[$i]['value']; } } } if ($creditsApplied > 0) { $optionsST['ITEMAMT'] -= $creditsApplied; } if ($surcharges > 0) { $optionsST['ITEMAMT'] += $surcharges; } // Handle tax-included scenario if (DISPLAY_PRICE_WITH_TAX == 'true') { $optionsST['TAXAMT'] = 0; } $subtotalPRE = $optionsST; // Move shipping tax amount from Tax subtotal into Shipping subtotal for submission to PayPal, since PayPal applies tax to each line-item individually $module = substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_')); if (zen_not_null($order->info['shipping_method']) && DISPLAY_PRICE_WITH_TAX != 'true') { if ($GLOBALS[$module]->tax_class > 0) { $shipping_tax_basis = !isset($GLOBALS[$module]->tax_basis) ? STORE_SHIPPING_TAX_BASIS : $GLOBALS[$module]->tax_basis; $shippingOnBilling = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']); $shippingOnDelivery = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); if ($shipping_tax_basis == 'Billing') { $shipping_tax = $shippingOnBilling; } elseif ($shipping_tax_basis == 'Shipping') { $shipping_tax = $shippingOnDelivery; } else { if (STORE_ZONE == $order->billing['zone_id']) { $shipping_tax = $shippingOnBilling; } elseif (STORE_ZONE == $order->delivery['zone_id']) { $shipping_tax = $shippingOnDelivery; } else { $shipping_tax = 0; } } $taxAdjustmentForShipping = zen_round(zen_calculate_tax($order->info['shipping_cost'], $shipping_tax), $currencies->currencies[$_SESSION['currency']]['decimal_places']); $optionsST['SHIPPINGAMT'] += $taxAdjustmentForShipping; $optionsST['TAXAMT'] -= $taxAdjustmentForShipping; } } $flagSubtotalsUnknownYet = $optionsST['SHIPPINGAMT'] + $optionsST['SHIPDISCAMT'] + $optionsST['AMT'] + $optionsST['TAXAMT'] + $optionsST['ITEMAMT'] + $optionsST['INSURANCEAMT'] == 0; } else { // if we get here, we don't have any order-total information yet because the customer has clicked Express before starting normal checkout flow // thus, we must make a note to manually calculate subtotals, rather than relying on the more robust order-total infrastructure $flagSubtotalsUnknownYet = TRUE; } // loop thru all products to prepare details of quantity and price. for ($i = 0, $n = sizeof($order->products), $k = 0; $i < $n; $i++, $k++) { // PayPal won't accept zero-value line-items, so skip this entry if price is zero if ($order->products[$i]['final_price'] == 0) { continue; } $optionsLI["L_NUMBER{$k}"] = $order->products[$i]['model']; $optionsLI["L_NAME{$k}"] = $order->products[$i]['name']; // Append *** if out-of-stock. $optionsLI["L_NAME{$k}"] .= zen_get_products_stock($order->products[$i]['id']) - $order->products[$i]['qty'] < 0 ? STOCK_MARK_PRODUCT_OUT_OF_STOCK : ''; // if there are attributes, loop thru them and add to description if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) { $optionsLI["L_DESC{$k}"] = ''; for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) { $optionsLI["L_DESC{$k}"] .= "\n " . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value']; } // end loop } // endif attribute-info // check for rounding problems with taxes $m1 = zen_round($order->products[$i]['qty'] * $order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']); $m2 = $order->products[$i]['qty'] * zen_round($order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']); $n1 = $order->products[$i]['qty'] * zen_calculate_tax($order->products[$i]['final_price'], $order->products[$i]['tax']); $n2 = zen_calculate_tax($order->products[$i]['qty'] * $order->products[$i]['final_price'], $order->products[$i]['tax']); if ($m1 != $m2 || zen_round($n1, $currencies->currencies[$_SESSION['currency']]['decimal_places']) != zen_round($n2, $currencies->currencies[$_SESSION['currency']]['decimal_places'])) { $flag_treat_as_partial = true; } // PayPal can't handle partial-quantity values, so fudge it here if ($flag_treat_as_partial || $order->products[$i]['qty'] != (int) $order->products[$i]['qty']) { $optionsLI["L_NAME{$k}"] = '(' . $order->products[$i]['qty'] . ' x ) ' . $optionsLI["L_NAME{$k}"]; $optionsLI["L_AMT{$k}"] = zen_round($order->products[$i]['qty'] * $order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']); $optionsLI["L_TAXAMT{$k}"] = zen_calculate_tax(zen_round($order->products[$i]['qty'] * $order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']), $order->products[$i]['tax']); $optionsLI["L_QTY{$k}"] = 1; } else { $optionsLI["L_AMT{$k}"] = $order->products[$i]['final_price']; $optionsLI["L_QTY{$k}"] = $order->products[$i]['qty']; $optionsLI["L_TAXAMT{$k}"] = zen_calculate_tax(1 * $order->products[$i]['final_price'], $order->products[$i]['tax']); } // For tax-included pricing, combine tax with price instead of treating separately: if (DISPLAY_PRICE_WITH_TAX == 'true') { $optionsLI["L_AMT{$k}"] += $optionsLI["L_TAXAMT{$k}"]; $optionsLI["L_TAXAMT{$k}"] = 0; } $subTotalLI += $optionsLI["L_QTY{$k}"] * $optionsLI["L_AMT{$k}"]; $subTotalTax += $optionsLI["L_QTY{$k}"] * $optionsLI["L_TAXAMT{$k}"]; // add line-item for one-time charges on this product if ($order->products[$i]['onetime_charges'] != 0) { $k++; $optionsLI["L_NAME{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_ONETIME_CHARGES_PREFIX . substr(htmlentities($order->products[$i]['name'], ENT_QUOTES, 'UTF-8'), 0, 120); $optionsLI["L_AMT{$k}"] = $order->products[$i]['onetime_charges']; $optionsLI["L_QTY{$k}"] = 1; $optionsLI["L_TAXAMT{$k}"] = zen_calculate_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']); $subTotalLI += $order->products[$i]['onetime_charges']; $subTotalTax += $optionsLI["L_TAXAMT{$k}"]; } $numberOfLineItemsProcessed = $k; } // end for loopthru all products // add line items for any surcharges added by order-total modules if ($surcharges > 0) { $numberOfLineItemsProcessed++; $k = $numberOfLineItemsProcessed; $optionsLI["L_NAME{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_SURCHARGES_SHORT; $optionsLI["L_DESC{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_SURCHARGES_LONG; $optionsLI["L_AMT{$k}"] = $surcharges; $optionsLI["L_QTY{$k}"] = 1; $subTotalLI += $surcharges; } // add line items for discounts such as gift certificates and coupons if ($creditsApplied > 0) { $numberOfLineItemsProcessed++; $k = $numberOfLineItemsProcessed; $optionsLI["L_NAME{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_DISCOUNTS_SHORT; $optionsLI["L_DESC{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_DISCOUNTS_LONG; $optionsLI["L_AMT{$k}"] = -1 * $creditsApplied; $optionsLI["L_QTY{$k}"] = 1; $subTotalLI -= $creditsApplied; } // Reformat properly for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) { // Replace & and = and % with * if found. $optionsLI["L_NAME{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_NAME{$k}"]); if (isset($optionsLI["L_DESC{$k}"])) { $optionsLI["L_DESC{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_DESC{$k}"]); } if (isset($optionsLI["L_NUMBER{$k}"])) { $optionsLI["L_NUMBER{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_NUMBER{$k}"]); } // Remove HTML markup if found $optionsLI["L_NAME{$k}"] = zen_clean_html($optionsLI["L_NAME{$k}"], 'strong'); if (isset($optionsLI["L_DESC{$k}"])) { $optionsLI["L_DESC{$k}"] = zen_clean_html($optionsLI["L_DESC{$k}"], 'strong'); } // reformat properly according to API specs $optionsLI["L_NAME{$k}"] = substr($optionsLI["L_NAME{$k}"], 0, 127); if (isset($optionsLI["L_NUMBER{$k}"])) { $optionsLI["L_NUMBER{$k}"] = substr($optionsLI["L_NUMBER{$k}"], 0, 127); } if (isset($optionsLI["L_DESC{$k}"]) && $optionsLI["L_DESC{$k}"] == '') { unset($optionsLI["L_DESC{$k}"]); } if (isset($optionsLI["L_DESC{$k}"])) { $optionsLI["L_DESC{$k}"] = substr($optionsLI["L_DESC{$k}"], 0, 127); } if (isset($optionsLI["L_TAXAMT{$k}"]) && ($optionsLI["L_TAXAMT{$k}"] != '' || $optionsLI["L_TAXAMT{$k}"] > 0)) { $optionsLI["L_TAXAMT{$k}"] = round($optionsLI["L_TAXAMT{$k}"], 2); } } /** * PayPal says their math works like this: * a) ITEMAMT = L_AMTn * L_QTYn * b) TAXAMT = L_QTYn * L_TAXAMTn * c) AMT = ITEMAMT + SHIPPINGAMT + HANDLINGAMT + TAXAMT */ // Sanity Check of line-item subtotals for ($j = 0; $j < $k; $j++) { $itemAMT = $optionsLI["L_AMT{$j}"]; $itemQTY = $optionsLI["L_QTY{$j}"]; $itemTAX = isset($optionsLI["L_TAXAMT{$j}"]) ? $optionsLI["L_TAXAMT{$j}"] : 0; $sumOfLineItems += $itemQTY * $itemAMT; $sumOfLineTax += $itemQTY * $itemTAX; } $sumOfLineItems = round($sumOfLineItems, 2); $sumOfLineTax = round($sumOfLineTax, 2); if ($sumOfLineItems == 0) { $sumOfLineTax = 0; $optionsLI = array(); $discountProblemsFlag = TRUE; if ($optionsST['SHIPPINGAMT'] == $optionsST['AMT']) { $optionsST['SHIPPINGAMT'] = 0; } } // Sanity check -- if tax-included pricing is causing problems, remove the numbers and put them in a comment instead: $stDiffTaxOnly = strval($sumOfLineItems - $sumOfLineTax - round($optionsST['AMT'], 2)) + 0; if (DISPLAY_PRICE_WITH_TAX == 'true' && $stDiffTaxOnly == 0) { $optionsNB['DESC'] = 'Tax included in prices: ' . $sumOfLineTax . ' (' . $optionsST['TAXAMT'] . ') '; $optionsST['TAXAMT'] = 0; for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) { if (isset($optionsLI["L_TAXAMT{$k}"])) { unset($optionsLI["L_TAXAMT{$k}"]); } } } // Do sanity check -- if any of the line-item subtotal math doesn't add up properly, skip line-item details, // so that the order can go through even though PayPal isn't being flexible to handle Zen Cart's diversity if (strval($subTotalTax) - strval($sumOfLineTax) > 0.02) { $this->zcLog('getLineItemDetails 3', 'Tax Subtotal does not match sum of taxes for line-items. Tax details are being removed from line-item submission data.' . "\n" . $sumOfLineTax . ' ' . $subTotalTax . print_r(array_merge($optionsST, $optionsLI), true)); for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) { if (isset($optionsLI["L_TAXAMT{$k}"])) { unset($optionsLI["L_TAXAMT{$k}"]); } } $subTotalTax = 0; $sumOfLineTax = 0; } // If coupons exist and there's a calculation problem, then it's likely that taxes are incorrect, so reset L_TAXAMTn values if ($creditsApplied > 0 && strval($optionsST['TAXAMT']) != strval($sumOfLineTax)) { $pre = $optionsLI; for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) { if (isset($optionsLI["L_TAXAMT{$k}"])) { unset($optionsLI["L_TAXAMT{$k}"]); } } $this->zcLog('getLineItemDetails 4', 'Coupons/Discounts have affected tax calculations, so tax details are being removed from line-item submission data.' . "\n" . $sumOfLineTax . ' ' . $optionsST['TAXAMT'] . "\n" . print_r(array_merge($optionsST, $pre, $optionsNB), true) . "\nAFTER:" . print_r(array_merge($optionsST, $optionsLI, $optionsNB), TRUE)); $subTotalTax = 0; $sumOfLineTax = 0; } if (TRUE) { // disable line-item tax details, leaving only TAXAMT subtotal as tax indicator for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) { if (isset($optionsLI["L_TAXAMT{$k}"])) { unset($optionsLI["L_TAXAMT{$k}"]); } } } // check subtotals if (strval($optionsST['ITEMAMT']) > 0 && strval($subTotalLI) > 0 && strval($subTotalLI) != strval($optionsST['ITEMAMT']) || strval($subTotalLI) - strval($sumOfLineItems) != 0) { $this->zcLog('getLineItemDetails 5', 'Line-item subtotals do not add up properly. Line-item-details skipped.' . "\n" . (double) $sumOfLineItems . ' ' . (double) $subTotalTax . print_r(array_merge($optionsST, $optionsLI), true)); $optionsLI = array(); } // check whether discounts are causing a problem if (strval($optionsST['ITEMAMT']) < 0) { $pre = array_merge($optionsST, $optionsLI); $optionsLI = array(); $optionsST['ITEMAMT'] = $optionsST['AMT']; if ($optionsST['AMT'] < $optionsST['TAXAMT']) { $optionsST['TAXAMT'] = 0; } if ($optionsST['AMT'] < $optionsST['SHIPPINGAMT']) { $optionsST['SHIPPINGAMT'] = 0; } $discountProblemsFlag = TRUE; $this->zcLog('getLineItemDetails 6', 'Discounts have caused the subtotal to calculate incorrectly. Line-item-details cannot be submitted.' . "\nBefore:" . print_r($pre, TRUE) . "\nAfter:" . print_r(array_merge($optionsST, $optionsLI), true)); } // if AMT or ITEMAMT values are 0 (ie: certain OT modules disabled) or we've started express checkout without going through normal checkout flow, we have to get subtotals manually if ((!isset($optionsST['AMT']) || $optionsST['AMT'] == 0 || $flagSubtotalsUnknownYet == TRUE || $optionsST['ITEMAMT'] == 0) && $discountProblemsFlag != TRUE) { $optionsST['ITEMAMT'] = $sumOfLineItems; $optionsST['TAXAMT'] = $sumOfLineTax; if ($subTotalShipping > 0) { $optionsST['SHIPPINGAMT'] = $subTotalShipping; } $optionsST['AMT'] = $sumOfLineItems + $optionsST['TAXAMT'] + $optionsST['SHIPPINGAMT']; } $this->zcLog('getLineItemDetails 7 - subtotal comparisons', 'BEFORE line-item calcs: ' . print_r($subtotalPRE, true) . ($flagSubtotalsUnknownYet == TRUE ? 'Subtotals Unknown Yet' : '') . ' - AFTER doing line-item calcs: ' . print_r(array_merge($optionsST, $optionsLI, $optionsNB), true)); // if subtotals are not adding up correctly, then skip sending any line-item or subtotal details to PayPal $stAll = round(strval($optionsST['ITEMAMT'] + $optionsST['TAXAMT'] + $optionsST['SHIPPINGAMT'] + $optionsST['SHIPDISCAMT'] + $optionsST['HANDLINGAMT'] + $optionsST['INSURANCEAMT']), 2); $stDiff = strval($optionsST['AMT'] - $stAll); $stDiffRounded = strval($stAll - round($optionsST['AMT'], 2)) + 0; // unset any subtotal values that are zero if (isset($optionsST['ITEMAMT']) && $optionsST['ITEMAMT'] == 0) { unset($optionsST['ITEMAMT']); } if (isset($optionsST['TAXAMT']) && $optionsST['TAXAMT'] == 0) { unset($optionsST['TAXAMT']); } if (isset($optionsST['SHIPPINGAMT']) && $optionsST['SHIPPINGAMT'] == 0) { unset($optionsST['SHIPPINGAMT']); } if (isset($optionsST['SHIPDISCAMT']) && $optionsST['SHIPDISCAMT'] == 0) { unset($optionsST['SHIPDISCAMT']); } if (isset($optionsST['HANDLINGAMT']) && $optionsST['HANDLINGAMT'] == 0) { unset($optionsST['HANDLINGAMT']); } if (isset($optionsST['INSURANCEAMT']) && $optionsST['INSURANCEAMT'] == 0) { unset($optionsST['INSURANCEAMT']); } // tidy up all values so that they comply with proper format (number_format(xxxx,2) for PayPal US use ) if (!defined('PAYPALWPP_SKIP_LINE_ITEM_DETAIL_FORMATTING') || PAYPALWPP_SKIP_LINE_ITEM_DETAIL_FORMATTING != 'true' || in_array($order->info['currency'], array('JPY', 'NOK'))) { if (is_array($optionsST)) { foreach ($optionsST as $key => $value) { $optionsST[$key] = number_format($value, $order->info['currency'] == 'JPY' ? 0 : 2); } } if (is_array($optionsLI)) { foreach ($optionsLI as $key => $value) { if (substr($key, 0, 8) == 'L_TAXAMT' && ($optionsLI[$key] == '' || $optionsLI[$key] == 0)) { unset($optionsLI[$key]); } else { if (strstr($key, 'AMT')) { $optionsLI[$key] = number_format($value, $order->info['currency'] == 'JPY' ? 0 : 2); } } } } } $this->zcLog('getLineItemDetails 8', 'checking subtotals... ' . "\n" . print_r(array_merge(array('calculated total' => number_format($stAll, $order->info['currency'] == 'JPY' ? 0 : 2)), $optionsST), true) . "\n-------------------\ndifference: " . ($stDiff + 0) . ' (abs+rounded: ' . ($stDiffRounded + 0) . ')'); if ($stDiffRounded != 0) { $this->zcLog('getLineItemDetails 9', 'Subtotals Bad. Skipping line-item/subtotal details'); return array(); } $this->zcLog('getLineItemDetails 10', 'subtotals balance - okay'); // Send Subtotal and LineItem results back to be submitted to PayPal return array_merge($optionsST, $optionsLI, $optionsNB); }
$attrArray[$option]['options_values_price'] = $attributes_values->fields['options_values_price']; $attrArray[$option]['price_prefix'] = $attributes_values->fields['price_prefix']; } } //end foreach [attributes] if (STOCK_CHECK == 'true') { $flagStockCheck = zen_check_stock($products[$i]['id'], $products[$i]['quantity']); if ($flagStockCheck == true) { $flagAnyOutOfStock = true; } } $linkProductsImage = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']); $linkProductsName = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']); $productsImage = IMAGE_SHOPPING_CART_STATUS == 1 ? zen_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT) : ''; $show_products_quantity_max = zen_get_products_quantity_order_max($products[$i]['id']); $showFixedQuantity = ($show_products_quantity_max == 1 or zen_get_products_qty_box_status($products[$i]['id']) == 0) ? true : false; // $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('products_id[]', $products[$i]['id']) . zen_draw_hidden_field('cart_quantity[]', 1); // $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', 1); $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', $products[$i]['quantity']); $showMinUnits = zen_get_products_quantity_min_units_display($products[$i]['id']); $quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], ' size="4" onfocus="set_update_count(this);" onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\\d]/g,\'\'));update_count(this);" onkeyup="value=value.replace(/[^\\d]/g,\'\');update_count(this);" class="check_input_num" id="cart_quantity[]"'); $buttonUpdate = ((SHOW_SHOPPING_CART_UPDATE == 1 or SHOW_SHOPPING_CART_UPDATE == 3) ? zen_image_submit(ICON_IMAGE_UPDATE, ICON_UPDATE_ALT) : '') . zen_draw_hidden_field('products_id[]', $products[$i]['id']); $productsPrice = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : ''); $productsPriceEach = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : ''); $productArray[$i] = array('attributeHiddenField' => $attributeHiddenField, 'flagStockCheck' => $flagStockCheck, 'flagShowFixedQuantity' => $showFixedQuantity, 'linkProductsImage' => $linkProductsImage, 'linkProductsName' => $linkProductsName, 'productsImage' => $productsImage, 'productsName' => $productsName, 'showFixedQuantity' => $showFixedQuantity, 'showFixedQuantityAmount' => $showFixedQuantityAmount, 'showMinUnits' => $showMinUnits, 'quantityField' => $quantityField, 'buttonUpdate' => $buttonUpdate, 'productsPrice' => $productsPrice, 'productsPriceEach' => $productsPriceEach, 'rowClass' => $rowClass, 'buttonDelete' => $buttonDelete, 'checkBoxDelete' => $checkBoxDelete, 'id' => $products[$i]['id'], 'attributes' => $attrArray); } // end FOR loop $flag_disable_footer = TRUE; $flag_disable_header = TRUE; // This should be last line of the script: $zco_notifier->notify('NOTIFY_HEADER_END_SHOPPING_CART');
/** * Enter description here... * * @param unknown_type $method * @return unknown */ function quote($method = '') { global $order, $shipping_weight, $shipping_num_boxes, $total_count; // shipping adjustment switch (MODULE_SHIPPING_TABLE_MODE) { case 'price': $order_total = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices(); break; case 'weight': $order_total = $shipping_weight; break; case 'item': $order_total = $total_count - $_SESSION['cart']->free_shipping_items(); break; } $order_total_amount = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices(); $table_cost = preg_split("/[:,]/", MODULE_SHIPPING_TABLE_COST); $size = sizeof($table_cost); for ($i = 0, $n = $size; $i < $n; $i += 2) { if (round($order_total, 9) <= $table_cost[$i]) { if (strstr($table_cost[$i + 1], '%')) { $shipping = $table_cost[$i + 1] / 100 * $order_total_amount; } else { $shipping = $table_cost[$i + 1]; } break; } } if (MODULE_SHIPPING_TABLE_MODE == 'weight') { $shipping = $shipping * $shipping_num_boxes; // show boxes if weight switch (SHIPPING_BOX_WEIGHT_DISPLAY) { case 0: $show_box_weight = ''; break; case 1: $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')'; break; case 2: $show_box_weight = ' (' . number_format($shipping_weight * $shipping_num_boxes, 2) . TEXT_SHIPPING_WEIGHT . ')'; break; default: $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight, 2) . TEXT_SHIPPING_WEIGHT . ')'; break; } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE . $show_box_weight, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_TABLE_TEXT_WAY, 'cost' => $shipping + (MODULE_SHIPPING_TABLE_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_TABLE_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_TABLE_HANDLING)))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } return $this->quotes; }
function ot_shipping() { global $order, $currencies; $this->code = 'ot_shipping'; $this->title = MODULE_ORDER_TOTAL_SHIPPING_TITLE; $this->description = MODULE_ORDER_TOTAL_SHIPPING_DESCRIPTION; $this->sort_order = MODULE_ORDER_TOTAL_SHIPPING_SORT_ORDER; unset($_SESSION['shipping_tax_description']); $this->output = array(); if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') { switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) { case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) { $pass = true; } break; case 'international': if ($order->delivery['country_id'] != STORE_COUNTRY) { $pass = true; } break; case 'both': $pass = true; break; default: $pass = false; break; } if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) { $order->info['shipping_method'] = $this->title; $order->info['total'] -= $order->info['shipping_cost']; $order->info['shipping_cost'] = 0; } } $module = isset($_SESSION['shipping']) && isset($_SESSION['shipping']['id']) ? substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_')) : ''; if (is_object($order) && zen_not_null($order->info['shipping_method'])) { if ($GLOBALS[$module]->tax_class > 0) { if (!isset($GLOBALS[$module]->tax_basis)) { $shipping_tax_basis = STORE_SHIPPING_TAX_BASIS; } else { $shipping_tax_basis = $GLOBALS[$module]->tax_basis; } if ($shipping_tax_basis == 'Billing') { $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']); $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']); } elseif ($shipping_tax_basis == 'Shipping') { $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } else { if (STORE_ZONE == $order->billing['zone_id']) { $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']); $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']); } elseif (STORE_ZONE == $order->delivery['zone_id']) { $shipping_tax = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $shipping_tax_description = zen_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } else { $shipping_tax = 0; } } $shipping_tax_amount = zen_calculate_tax($order->info['shipping_cost'], $shipping_tax); $order->info['shipping_tax'] += $shipping_tax_amount; $order->info['tax'] += $shipping_tax_amount; $order->info['tax_groups']["{$shipping_tax_description}"] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax); $order->info['total'] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax); $_SESSION['shipping_tax_description'] = $shipping_tax_description; $_SESSION['shipping_tax_amount'] = $shipping_tax_amount; if (DISPLAY_PRICE_WITH_TAX == 'true') { $order->info['shipping_cost'] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax); } } if ($_SESSION['shipping']['id'] == 'free_free') { $order->info['shipping_method'] = FREE_SHIPPING_TITLE; $order->info['shipping_cost'] = 0; } } }
/** * Method to calculate cart totals(price and weight) * * @return void * @global object access to the db object */ function calculate() { global $db, $currencies; $this->total = 0; $this->weight = 0; $this->total_before_discounts = 0; $decimalPlaces = $currencies->get_decimal_places($_SESSION['currency']); // shipping adjustment $this->free_shipping_item = 0; $this->free_shipping_price = 0; $this->free_shipping_weight = 0; $this->download_count = 0; if (!is_array($this->contents)) { return 0; } // By default, Price Factor is based on Price and is called from function zen_get_attributes_price_factor // Setting a define for ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL to 1 to calculate the Price Factor from Special rather than Price switches this to be based on Special, if it exists if (!defined('ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL')) { define('ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL', 1); } reset($this->contents); while (list($products_id, ) = each($this->contents)) { $total_before_discounts = 0; $freeShippingTotal = $productTotal = $totalOnetimeCharge = $totalOnetimeChargeNoDiscount = 0; $qty = $this->contents[$products_id]['qty']; // products price // Dual Pricing start $product_query = "select products_id, products_price, products_price_w, products_tax_class_id, products_weight,\n/* Dual Pricing end */\n products_priced_by_attribute, product_is_always_free_shipping, products_discount_type, products_discount_type_from,\n products_virtual, products_model\n from " . TABLE_PRODUCTS . "\n where products_id = '" . (int) $products_id . "'"; if ($product = $db->Execute($product_query)) { $prid = $product->fields['products_id']; $products_tax = zen_get_tax_rate($product->fields['products_tax_class_id']); // Dual Pricing start if ($_SESSION['customer_id']) { $customers_id = $_SESSION['customer_id']; $customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = '{$customers_id}'"); if ($customer_check->fields['customers_whole'] != "0") { $i = $customer_check->fields['customers_whole']; $i--; $products_price_array = $product->fields['products_price_w']; $productsprice = explode("-", $products_price_array); $products_price = (double) $productsprice[$i]; if ($products_price == '0' || $products_price == '') { $products_price = (double) $productsprice[0]; } if ($products_price == '0') { $products_price = $product->fields['products_price']; } } else { $products_price = $product->fields['products_price']; } } else { $products_price = $product->fields['products_price']; } // Dual Pricing end // adjusted count for free shipping if ($product->fields['product_is_always_free_shipping'] != 1 and $product->fields['products_virtual'] != 1) { $products_weight = $product->fields['products_weight']; } else { $products_weight = 0; } $special_price = zen_get_products_special_price($prid); if ($special_price and $product->fields['products_priced_by_attribute'] == 0) { $products_price = $special_price; } else { $special_price = 0; } if (zen_get_products_price_is_free($product->fields['products_id'])) { // no charge $products_price = 0; } // adjust price for discounts when priced by attribute if ($product->fields['products_priced_by_attribute'] == '1' and zen_has_product_attributes($product->fields['products_id'], 'false')) { // reset for priced by attributes // $products_price = $products->fields['products_price']; if ($special_price) { $products_price = $special_price; } else { $products_price = $product->fields['products_price']; } } else { // discount qty pricing if ($product->fields['products_discount_type'] != '0') { $products_price = zen_get_products_discount_price_qty($product->fields['products_id'], $qty); } } // shipping adjustments for Product if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) { $this->free_shipping_item += $qty; $freeShippingTotal += $products_price; $this->free_shipping_weight += $qty * $product->fields['products_weight']; } // $this->total += zen_round(zen_add_tax($products_price, $products_tax),$currencies->get_decimal_places($_SESSION['currency'])) * $qty; $productTotal += $products_price; $this->weight += $qty * $products_weight; // ****** WARNING NEED TO ADD ATTRIBUTES AND QTY // calculate Product Price without Specials, Sales or Discounts $total_before_discounts += $product->fields['products_price']; } $adjust_downloads = 0; // attributes price $savedProductTotal = $productTotal; $attributesTotal = 0; if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $productTotal = 0; $adjust_downloads++; /* products_attributes_id, options_values_price, price_prefix, attributes_display_only, product_attribute_is_free, attributes_discounted */ $attribute_price_query = "select *\n from " . TABLE_PRODUCTS_ATTRIBUTES . "\n where products_id = '" . (int) $prid . "'\n and options_id = '" . (int) $option . "'\n and options_values_id = '" . (int) $value . "'"; $attribute_price = $db->Execute($attribute_price_query); // Dual Pricing start if ($_SESSION['customer_id']) { $customers_id = $_SESSION['customer_id']; $customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = '{$customers_id}'"); if ($customer_check->fields['customers_whole'] != "0") { $i = $customer_check->fields['customers_whole']; $i--; $options_value_price = (double) $attribute_price->fields['options_values_price_w']; } else { $options_value_price = $attribute_price->fields['options_values_price']; } } else { $options_value_price = $attribute_price->fields['options_values_price']; } // Dual Pricing end $new_attributes_price = 0; // calculate Product Price without Specials, Sales or Discounts // $new_attributes_price_before_discounts = 0; $discount_type_id = ''; $sale_maker_discount = ''; // bottom total // if ($attribute_price->fields['product_attribute_is_free']) { if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int) $prid)) { // no charge for attribute } else { // + or blank adds if ($attribute_price->fields['price_prefix'] == '-') { // appears to confuse products priced by attributes if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') { $shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty); $freeShippingTotal -= $shipping_attributes_price; } if ($attribute_price->fields['attributes_discounted'] == '1') { // calculate proper discount for attributes $new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty); $productTotal -= $new_attributes_price; } else { $productTotal -= $attribute_price->fields['options_values_price']; } // calculate Product Price without Specials, Sales or Discounts // $this->total_before_discounts -= $attribute_price->fields['options_values_price']; $total_before_discounts -= $attribute_price->fields['options_values_price']; } else { // appears to confuse products priced by attributes if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') { $shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty); $freeShippingTotal += $shipping_attributes_price; } if ($attribute_price->fields['attributes_discounted'] == '1') { // calculate proper discount for attributes $new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty); // Dual Pricing start //$productTotal += $new_attributes_price; if ($_SESSION['customer_id']) { if ($customer_check->fields['customers_whole'] != "0") { $new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price_w'], $qty); } } $this->total += $qty * zen_add_tax($new_attributes_price, $products_tax); // Dual Pricing end } else { $productTotal += $attribute_price->fields['options_values_price']; } // calculate Product Price without Specials, Sales or Discounts $total_before_discounts += $attribute_price->fields['options_values_price']; } // eof: attribute price // adjust for downloads // adjust products price $check_attribute = $attribute_price->fields['products_attributes_id']; $sql = "select *\n from " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . "\n where products_attributes_id = '" . $check_attribute . "'"; $check_download = $db->Execute($sql); if ($check_download->RecordCount()) { // count number of downloads $this->download_count += $check_download->RecordCount() * $qty; // do not count download as free when set to product/download combo if ($adjust_downloads == 1 and $product->fields['product_is_always_free_shipping'] != 2) { $freeShippingTotal += $products_price; $this->free_shipping_item += $qty; } // adjust for attributes price $freeShippingTotal += $new_attributes_price; //die('I SEE B ' . $this->free_shipping_price); } // echo 'I SEE ' . $this->total . ' vs ' . $this->free_shipping_price . ' items: ' . $this->free_shipping_item. '<br>'; //////////////////////////////////////////////// // calculate additional attribute charges $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); // products_options_value_text if (zen_get_attributes_type($attribute_price->fields['products_attributes_id']) == PRODUCTS_OPTIONS_TYPE_TEXT) { $text_words = zen_get_word_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_words_free'], $attribute_price->fields['attributes_price_words']); $text_letters = zen_get_letters_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_letters_free'], $attribute_price->fields['attributes_price_letters']); $productTotal += $text_letters; $productTotal += $text_words; if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) { $freeShippingTotal += $text_letters; $freeShippingTotal += $text_words; } // calculate Product Price without Specials, Sales or Discounts $total_before_discounts += $text_letters; $total_before_discounts += $text_words; } // attributes_price_factor $added_charge = 0; if ($attribute_price->fields['attributes_price_factor'] > 0) { //echo 'products_id: ' . $product->fields['products_id'] . ' Prices ' . '$chk_price: ' . $chk_price . ' $chk_special: ' . $chk_special . ' attributes_price_factor:' . $attribute_price->fields['attributes_price_factor'] . ' attributes_price_factor_offset: ' . $attribute_price->fields['attributes_price_factor_offset'] . '<br>'; $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']); $productTotal += $added_charge; if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) { $freeShippingTotal += $added_charge; } // calculate Product Price without Specials, Sales or Discounts $added_charge = zen_get_attributes_price_factor($chk_price, $chk_price, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']); $total_before_discounts += $added_charge; } // attributes_qty_prices $added_charge = 0; if ($attribute_price->fields['attributes_qty_prices'] != '') { $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], $qty); $productTotal += $added_charge; if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) { $freeShippingTotal += $added_charge; } // calculate Product Price without Specials, Sales or Discounts $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], 1); $total_before_discounts += $attribute_price->fields['options_values_price'] + $added_charge; } //// one time charges // attributes_price_onetime if ($attribute_price->fields['attributes_price_onetime'] > 0) { $totalOnetimeCharge += $attribute_price->fields['attributes_price_onetime']; // calculate Product Price without Specials, Sales or Discounts $totalOnetimeChargeNoDiscount += $attribute_price->fields['attributes_price_onetime']; } // attributes_price_factor_onetime $added_charge = 0; if ($attribute_price->fields['attributes_price_factor_onetime'] > 0) { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']); $totalOnetimeCharge += $added_charge; // calculate Product Price without Specials, Sales or Discounts $added_charge = zen_get_attributes_price_factor($chk_price, $chk_price, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']); $totalOnetimeChargeNoDiscount += $added_charge; } // attributes_qty_prices_onetime $added_charge = 0; if ($attribute_price->fields['attributes_qty_prices_onetime'] != '') { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices_onetime'], $qty); $totalOnetimeCharge += $added_charge; // calculate Product Price without Specials, Sales or Discounts $added_charge = zen_get_attributes_qty_prices_onetime($chk_price, $chk_price, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']); $totalOnetimeChargeNoDiscount += $added_charge; } //////////////////////////////////////////////// } $attributesTotal += zen_round($productTotal, $decimalPlaces); } // eof while } // attributes price $productTotal = $savedProductTotal + $attributesTotal; // attributes weight if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $attribute_weight_query = "select products_attributes_weight, products_attributes_weight_prefix\n from " . TABLE_PRODUCTS_ATTRIBUTES . "\n where products_id = '" . (int) $prid . "'\n and options_id = '" . (int) $option . "'\n and options_values_id = '" . (int) $value . "'"; $attribute_weight = $db->Execute($attribute_weight_query); // adjusted count for free shipping if ($product->fields['product_is_always_free_shipping'] != 1) { $new_attributes_weight = $attribute_weight->fields['products_attributes_weight']; } else { $new_attributes_weight = 0; } // shipping adjustments for Attributes if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) { if ($attribute_weight->fields['products_attributes_weight_prefix'] == '-') { $this->free_shipping_weight -= $qty * $attribute_weight->fields['products_attributes_weight']; } else { $this->free_shipping_weight += $qty * $attribute_weight->fields['products_attributes_weight']; } } // + or blank adds if ($attribute_weight->fields['products_attributes_weight_prefix'] == '-') { $this->weight -= $qty * $new_attributes_weight; } else { $this->weight += $qty * $new_attributes_weight; } } } // attributes weight /* // uncomment for odd shipping requirements needing this: // if 0 weight defined as free shipping adjust for functions free_shipping_price and free_shipping_item if (($product->fields['products_weight'] == 0 && ORDER_WEIGHT_ZERO_STATUS == 1) && !($product->fields['products_virtual'] == 1) && !(preg_match('/^GIFT/', addslashes($product->fields['products_model']))) && !($product->fields['product_is_always_free_shipping'] == 1)) { $freeShippingTotal += $products_price; $this->free_shipping_item += $qty; } */ //echo 'shopping_cart class Price: ' . $productTotal . ' qty: ' . $qty . '<br>'; $this->total += zen_round(zen_add_tax($productTotal, $products_tax), $decimalPlaces) * $qty; $this->total += zen_round(zen_add_tax($totalOnetimeCharge, $products_tax), $decimalPlaces); $this->free_shipping_price += zen_round(zen_add_tax($freeShippingTotal, $products_tax), $decimalPlaces) * $qty; if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) { $this->free_shipping_price += zen_round(zen_add_tax($totalOnetimeCharge, $products_tax), $decimalPlaces); } // ******* WARNING ADD ONE TIME ATTRIBUTES, PRICE FACTOR // calculate Product Price without Specials, Sales or Discounts //echo 'Product Attribute before: ' . $new_attributes_price_before_discounts . '<br>'; $total_before_discounts = $total_before_discounts * $qty; $total_before_discounts += $totalOnetimeChargeNoDiscount; $this->total_before_discounts += $total_before_discounts; } }
define('TOP_HEAD_H1_TITLE', str_replace('"', '', $meta_category_name)); } // CUSTOM META TAGS } // EOF break; case 'product_reviews_info_OFF': $sql = "select rd.reviews_text, r.reviews_rating, r.reviews_id, r.customers_name, p.products_id, p.products_price, p.products_tax_class_id, p.products_model, pd.products_name, p.product_is_free from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where r.reviews_id = '" . (int) $_GET['reviews_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int) $_SESSION['languages_id'] . "' and r.products_id = p.products_id and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = '" . (int) $_SESSION['languages_id'] . "'"; $review_metatags = $db->Execute($sql); if ($review_metatags->EOF) { $meta_tags_over_ride = true; } else { if (META_TAG_INCLUDE_PRICE == '1') { if ($review_metatags->fields['product_is_free'] != '1') { $meta_products_price = zen_get_products_actual_price($review_metatags->fields['products_id']); $meta_products_price = SECONDARY_SECTION . $currencies->display_price($meta_products_price, zen_get_tax_rate($review_metatags->fields['products_tax_class_id'])); } else { $meta_products_price = SECONDARY_SECTION . META_TAG_PRODUCTS_PRICE_IS_FREE_TEXT; } } else { $meta_products_price = ''; } if (zen_not_null($review_metatags->fields['products_model'])) { $meta_products_name = $review_metatags->fields['products_name'] . ' [' . $review_metatags->fields['products_model'] . ']'; } else { $meta_products_name = $review_metatags->fields['products_name']; } $meta_products_name = zen_clean_html($meta_products_name); $review_text_metatags = substr(strip_tags(stripslashes($review_metatags->fields['reviews_text'])), 0, 60); $reviews_rating_metatags = SUB_TITLE_RATING . ' ' . sprintf(TEXT_OF_5_STARS, $review_metatags->fields['reviews_rating']); define('META_TAG_TITLE', str_replace('"', '', $meta_products_name . $meta_products_price . PRIMARY_SECTION . TITLE . TERTIARY_SECTION . NAVBAR_TITLE));
function calculate_tax_deduction($amount, $od_amount, $method, $finalise = false) { global $order; $tax_address = zen_get_tax_locations(); switch ($method) { case 'Standard': $ratio1 = zen_round($od_amount / $amount, 2); $tod_amount = 0; reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $tax_rate = zen_get_tax_rate_from_desc($key, $tax_address['country_id'], $tax_address['zone_id']); $total_net += $tax_rate * $value; } if ($od_amount > $total_net) { $od_amount = $total_net; } reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $tax_rate = zen_get_tax_rate_from_desc($key, $tax_address['country_id'], $tax_address['zone_id']); $net = $tax_rate * $value; if ($net > 0) { $god_amount = $value * $ratio1; $tod_amount += $god_amount; if ($finalise) { $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; } } } if ($finalise) { $order->info['tax'] -= $tod_amount; } if ($finalise) { $order->info['total'] -= $tod_amount; } break; case 'Credit Note': $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']); $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']); $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate; if ($finalise) { $order->info['tax_groups'][$tax_desc] -= $tod_amount; } if ($finalise) { $order->info['tax'] -= $tod_amount; } if ($finalise) { $order->info['total'] -= $tod_amount; } break; default: } return $tod_amount; }
function calculate_deductions($order_total) { global $db, $order; $od_amount = array(); if ($order_total == 0) { return $od_amount; } $orderTotal = $this->get_order_total(); $orderTotalTax = $orderTotal['tax']; $taxGroups = $orderTotal['taxGroups']; $group_query = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . (int) $_SESSION['customer_id'] . "'"); if ($group_query->fields['customers_group_pricing'] != '0') { $group_discount = $db->Execute("select group_name, group_percentage from " . TABLE_GROUP_PRICING . "\n where group_id = '" . (int) $group_query->fields['customers_group_pricing'] . "'"); $gift_vouchers = $_SESSION['cart']->gv_only(); $discount = ($orderTotal['total'] - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100; // echo "discout = $discount<br>"; $od_amount['total'] = round($discount, 2); $ratio = $od_amount['total'] / $order_total; /** * when calculating the ratio add some insignificant values to stop divide by zero errors */ switch ($this->calculate_tax) { case 'None': if ($this->include_tax) { reset($order->info['tax_groups']); foreach ($order->info['tax_groups'] as $key => $value) { $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio; } } break; case 'Standard': if ($od_amount['total'] >= $order_total) { $ratio = 1; } $adjustedTax = $orderTotalTax * $ratio; if ($order->info['tax'] == 0) { return $od_amount; } $ratioTax = $orderTotalTax != 0 ? $adjustedTax / $orderTotalTax : 0; reset($order->info['tax_groups']); $tax_deduct = 0; foreach ($taxGroups as $key => $value) { $od_amount['tax_groups'][$key] = $value * $ratioTax; $tax_deduct += $od_amount['tax_groups'][$key]; } $od_amount['tax'] = $tax_deduct; break; case 'Credit Note': $tax_rate = zen_get_tax_rate($this->tax_class); $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate); $tax_description = zen_get_tax_description($this->tax_class); $od_amount['tax_groups'][$tax_description] = $od_amount['tax']; break; } } return $od_amount; }
$products_model = $product_info->fields['products_model']; $products_description = $product_info->fields['products_description']; if ($product_info->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') { $products_image = PRODUCTS_IMAGE_NO_IMAGE; } else { $products_image = $product_info->fields['products_image']; } $products_url = $product_info->fields['products_url']; $products_date_available = $product_info->fields['products_date_available']; $products_date_added = $product_info->fields['products_date_added']; $products_manufacturer = $product_info->fields['manufacturers_name']; $products_weight = $product_info->fields['products_weight']; $products_quantity = $product_info->fields['products_quantity']; $products_qty_box_status = $product_info->fields['products_qty_box_status']; $products_quantity_order_max = $product_info->fields['products_quantity_order_max']; $products_base_price = $currencies->display_price(zen_get_products_base_price((int) $_GET['products_id']), zen_get_tax_rate($product_info->fields['products_tax_class_id'])); $product_is_free = $product_info->fields['product_is_free']; $products_tax_class_id = $product_info->fields['products_tax_class_id']; $module_show_categories = PRODUCT_INFO_CATEGORIES; $module_next_previous = PRODUCT_INFO_PREVIOUS_NEXT; $products_id_current = (int) $_GET['products_id']; $products_discount_type = $product_info->fields['products_discount_type']; $products_discount_type_from = $product_info->fields['products_discount_type_from']; /** * Load product-type-specific main_template_vars */ $prod_type_specific_vars_info = DIR_WS_MODULES . 'pages/' . $current_page_base . '/main_template_vars_product_type.php'; if (file_exists($prod_type_specific_vars_info)) { include_once $prod_type_specific_vars_info; } $zco_notifier->notify('NOTIFY_MAIN_TEMPLATE_VARS_PRODUCT_TYPE_VARS_DOCUMENT_GENERAL_INFO');
/** * Obtain quote from shipping system/calculations * * @param string $method * @return array */ function quote($method = '') { global $order, $shipping_weight, $shipping_num_boxes; $total_weight_units = $shipping_weight; $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_WAY, 'cost' => MODULE_SHIPPING_PERWEIGHTUNIT_COST * ($total_weight_units * $shipping_num_boxes) + (MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING)))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = zen_image($this->icon, $this->title); } return $this->quotes; }
function quote($pShipHash = array()) { global $order, $currency; $currencies = new currencies(); $dest_country = $order->delivery['country']['countries_iso_code_2']; $dest_zone = 0; $error = false; for ($i = 1; $i <= $this->num_zones; $i++) { $countries_table = constant('MODULE_SHIPPING_SPECIALDELIVERY9AM_ZONES_COUNTRIES_' . $i); $country_zones = preg_split("#[,]#", $countries_table); if (in_array($dest_country, $country_zones)) { $dest_zone = $i; break; } } //12 FEB 04 MBeedell NO specified country (or *) then use this zone for all shipping rates if ($dest_zone == 0) { for ($i = 1; $i <= $this->num_zones; $i++) { $countries_table = constant('MODULE_SHIPPING_SPECIALDELIVERY9AM_ZONES_COUNTRIES_' . $i); if ($countries_table == '' or $countries_table == '*') { $dest_zone = $i; break; } } } if ($dest_zone == 0) { $error = true; } else { $shipping = -1; //12 FEB 04 MBeedell 'glue' together the rates from the 10 cost data entry boxes $zones_cost = constant('MODULE_SHIPPING_SPECIALDELIVERY9AM_ZONES_COST0_' . $dest_zone) . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY9AM_ZONES_COST1_' . $dest_zone) . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY9AM_ZONES_COST2_' . $dest_zone) . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY9AM_ZONES_COST3_' . $dest_zone); $zones_table = preg_split("#[:,]#", $zones_cost); $size = sizeof($zones_table); for ($i = 0; $i < $size; $i += 2) { if ($shippingWeight <= $zones_table[$i]) { $shipping = $zones_table[$i + 1]; //12 Feb 04 MBeedell - correctly format the total weight... if the weight exceeds the max // weight, then it is divided down over a number of separate packages - so the weight could end // up being a long fraction. $sw_text = number_format($shippingWeight, 3, $currencies->currencies[DEFAULT_CURRENCY]['decimal_point'], $currencies->currencies[DEFAULT_CURRENCY]['thousands_point']); $shipping_method = MODULE_SHIPPING_SPECIALDELIVERY9AM_TEXT_WAY . ' ' . $dest_country . ' : ' . $sw_text . ' ' . MODULE_SHIPPING_SPECIALDELIVERY9AM_TEXT_UNITS; $shipping_method = MODULE_SHIPPING_SPECIALDELIVERY9AM_TEXT_WAY . ' : ' . $sw_text . ' ' . MODULE_SHIPPING_SPECIALDELIVERY9AM_TEXT_UNITS; //12 Feb 04 MBeedell - if weight is over the max, then show the number of boxes being shipped if ($shippingNumBoxes > 1) { $sw_text = number_format($shippingNumBoxes, 0, $currency['decimal_point'], $currency['thousands_point']); $sw_text = number_format($shippingWeight, 0, $currencies->currencies[DEFAULT_CURRENCY]['decimal_point'], $currencies->currencies[DEFAULT_CURRENCY]['thousands_point']); $shipping_method = $shipping_method . ' in ' . $sw_text . ' boxes '; } break; } } if ($shipping == -1) { $shipping_cost = 0; $shipping_method = MODULE_SHIPPING_SPECIALDELIVERY9AM_UNDEFINED_RATE; //$shipping_method = $zones_cost; //12 FEB 04 MBeedell useful for debug-print out the rates list! } else { $shipping_cost = $shipping * $shippingNumBoxes + constant('MODULE_SHIPPING_SPECIALDELIVERY9AM_ZONES_HANDLING_' . $dest_zone); } } $this->quotes = array('id' => $this->code, 'module' => '<b>special</b><span style="font-weight:normal">delivery</span>® <span style="color:red">9:00am.</span>', 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['countries_id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) { $this->quotes['icon'] = $this->icon; } if ($error == true) { $this->quotes['error'] = MODULE_SHIPPING_SPECIALDELIVERY9AM_INVALID_ZONE; } return $this->quotes; }
function process() { global $order, $currencies; if (MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE == 'true') { switch (MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION) { case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) { $pass = true; } break; case 'international': if ($order->delivery['country_id'] != STORE_COUNTRY) { $pass = true; } break; case 'both': $pass = true; break; default: $pass = false; break; } // if ( ($pass == true) && ( ($order->info['total'] - $order->info['shipping_cost']) < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) { if ($pass == true && $order->info['subtotal'] < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) { $charge_it = 'true'; $cart_content_type = $_SESSION['cart']->get_content_type(); $gv_content_only = $_SESSION['cart']->gv_only(); if ($cart_content_type == 'physical' or $cart_content_type == 'mixed') { $charge_it = 'true'; } else { // check to see if everything is virtual, if so - skip the low order fee. if ($cart_content_type == 'virtual' and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'true') { $charge_it = 'false'; if ($gv_content_only > 0 and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'false') { $charge_it = 'true'; } } if ($gv_content_only > 0 and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'true') { // check to see if everything is gift voucher, if so - skip the low order fee. $charge_it = 'false'; if ($cart_content_type == 'virtual' and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'false') { $charge_it = 'true'; } } } if ($charge_it == 'true') { $tax_address = zen_get_tax_locations(); $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $tax_address['country_id'], $tax_address['zone_id']); $tax_description = zen_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $tax_address['country_id'], $tax_address['zone_id']); // calculate from flat fee or percentage if (substr(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, -1) == '%') { $low_order_fee = $order->info['subtotal'] * (MODULE_ORDER_TOTAL_LOWORDERFEE_FEE / 100); } else { $low_order_fee = MODULE_ORDER_TOTAL_LOWORDERFEE_FEE; } $order->info['tax'] += zen_calculate_tax($low_order_fee, $tax); $order->info['tax_groups']["{$tax_description}"] += zen_calculate_tax($low_order_fee, $tax); $order->info['total'] += $low_order_fee + zen_calculate_tax($low_order_fee, $tax); if (DISPLAY_PRICE_WITH_TAX == 'true') { $low_order_fee += zen_calculate_tax($low_order_fee, $tax); } $this->output[] = array('title' => $this->title . ':', 'text' => $currencies->format($low_order_fee, true, $order->info['currency'], $order->info['currency_value']), 'value' => $low_order_fee); } } } }
function cart() { global $db, $currencies; $decimals = $currencies->get_decimal_places($_SESSION['currency']); $this->content_type = $_SESSION['cart']->get_content_type(); /* Dual Pricing start */ $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_whole,\n/* Dual Pricing end */\n c.customers_email_address, ab.entry_company, ab.entry_street_address,\n ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,\n z.zone_name, co.countries_id, co.countries_name,\n co.countries_iso_code_2, co.countries_iso_code_3,\n co.address_format_id, ab.entry_state\n from (" . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab )\n left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id)\n where c.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and c.customers_default_address_id = ab.address_book_id"; $customer_address = $db->Execute($customer_address_query); $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n c.countries_id, c.countries_name, c.countries_iso_code_2,\n c.countries_iso_code_3, c.address_format_id, ab.entry_state\n from " . TABLE_ADDRESS_BOOK . " ab\n left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and ab.address_book_id = '" . (int) $_SESSION['sendto'] . "'"; $shipping_address = $db->Execute($shipping_address_query); $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n c.countries_id, c.countries_name, c.countries_iso_code_2,\n c.countries_iso_code_3, c.address_format_id, ab.entry_state\n from " . TABLE_ADDRESS_BOOK . " ab\n left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'"; $billing_address = $db->Execute($billing_address_query); // set default tax calculation for not-logged-in visitors $taxCountryId = $taxZoneId = 0; // get tax zone info for logged-in visitors if (isset($_SESSION['customer_id']) && (int) $_SESSION['customer_id'] > 0) { $taxCountryId = $taxZoneId = -1; $tax_address_query = ''; switch (STORE_PRODUCT_TAX_BASIS) { case 'Shipping': $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n from " . TABLE_ADDRESS_BOOK . " ab\n left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'"; break; case 'Billing': $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n from " . TABLE_ADDRESS_BOOK . " ab\n left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'"; break; case 'Store': if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) { $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n from " . TABLE_ADDRESS_BOOK . " ab\n left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'"; } else { $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n from " . TABLE_ADDRESS_BOOK . " ab\n left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'"; } } if ($tax_address_query != '') { $tax_address = $db->Execute($tax_address_query); if ($tax_address->recordCount() > 0) { $taxCountryId = $tax_address->fields['entry_country_id']; $taxZoneId = $tax_address->fields['entry_zone_id']; } } } $class =& $_SESSION['payment']; if (isset($_SESSION['cc_id'])) { $coupon_code_query = "select coupon_code\n from " . TABLE_COUPONS . "\n where coupon_id = '" . (int) $_SESSION['cc_id'] . "'"; $coupon_code = $db->Execute($coupon_code_query); } $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'payment_module_code' => $GLOBALS[$class]->code, 'coupon_code' => $coupon_code->fields['coupon_code'], 'shipping_method' => isset($_SESSION['shipping']['title']) ? $_SESSION['shipping']['title'] : '', 'shipping_module_code' => isset($_SESSION['shipping']['id']) && strpos($_SESSION['shipping']['id'], '_') > 0 ? $_SESSION['shipping']['id'] : $_SESSION['shipping'], 'shipping_cost' => isset($_SESSION['shipping']['cost']) ? $_SESSION['shipping']['cost'] : 0, 'subtotal' => 0, 'shipping_tax' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']); //print_r($GLOBALS[$class]); //echo $class; //print_r($GLOBALS); //echo $_SESSION['payment']; /* // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder if (isset(${$_SESSION['payment']}) && is_object(${$_SESSION['payment']})) { $this->info['payment_method'] = ${$_SESSION['payment']}->title; } */ /* // bof: move below calculations if ($this->info['total'] == 0) { if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) { $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID; } else { $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID; } } if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) { if ( isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && ($GLOBALS[$class]->order_status > 0) ) { $this->info['order_status'] = $GLOBALS[$class]->order_status; } } // eof: move below calculations */ $this->customer = array('firstname' => $customer_address->fields['customers_firstname'], 'lastname' => $customer_address->fields['customers_lastname'], 'company' => $customer_address->fields['entry_company'], 'street_address' => $customer_address->fields['entry_street_address'], 'suburb' => $customer_address->fields['entry_suburb'], 'city' => $customer_address->fields['entry_city'], 'postcode' => $customer_address->fields['entry_postcode'], 'state' => zen_not_null($customer_address->fields['entry_state']) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name'], 'zone_id' => $customer_address->fields['entry_zone_id'], 'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']), 'format_id' => (int) $customer_address->fields['address_format_id'], 'telephone' => $customer_address->fields['customers_telephone'], 'email_address' => $customer_address->fields['customers_email_address']); $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'], 'lastname' => $shipping_address->fields['entry_lastname'], 'company' => $shipping_address->fields['entry_company'], 'street_address' => $shipping_address->fields['entry_street_address'], 'suburb' => $shipping_address->fields['entry_suburb'], 'city' => $shipping_address->fields['entry_city'], 'postcode' => $shipping_address->fields['entry_postcode'], 'state' => zen_not_null($shipping_address->fields['entry_state']) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name'], 'zone_id' => $shipping_address->fields['entry_zone_id'], 'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']), 'country_id' => $shipping_address->fields['entry_country_id'], 'format_id' => (int) $shipping_address->fields['address_format_id']); $this->billing = array('firstname' => $billing_address->fields['entry_firstname'], 'lastname' => $billing_address->fields['entry_lastname'], 'company' => $billing_address->fields['entry_company'], 'street_address' => $billing_address->fields['entry_street_address'], 'suburb' => $billing_address->fields['entry_suburb'], 'city' => $billing_address->fields['entry_city'], 'postcode' => $billing_address->fields['entry_postcode'], 'state' => zen_not_null($billing_address->fields['entry_state']) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name'], 'zone_id' => $billing_address->fields['entry_zone_id'], 'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']), 'country_id' => $billing_address->fields['entry_country_id'], 'format_id' => (int) $billing_address->fields['address_format_id']); $index = 0; $products = $_SESSION['cart']->get_products(); for ($i = 0, $n = sizeof($products); $i < $n; $i++) { if ($i / 2 == floor($i / 2)) { $rowClass = "rowEven"; } else { $rowClass = "rowOdd"; } $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId); $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax_groups' => $taxRates, 'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId), 'price' => $products[$i]['price'], 'final_price' => zen_round($products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), $decimals), 'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']), 'weight' => $products[$i]['weight'], 'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'], 'product_is_free' => $products[$i]['product_is_free'], 'products_discount_type' => $products[$i]['products_discount_type'], 'products_discount_type_from' => $products[$i]['products_discount_type_from'], 'id' => $products[$i]['id'], 'rowClass' => $rowClass); if (STORE_PRODUCT_TAX_BASIS == 'Shipping' && isset($_SESSION['shipping']['id']) && stristr($_SESSION['shipping']['id'], 'storepickup') == TRUE) { $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], STORE_COUNTRY, STORE_ZONE); $this->products[$index]['tax'] = zen_get_tax_rate($products[$i]['tax_class_id'], STORE_COUNTRY, STORE_ZONE); } else { $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId); $this->products[$index]['tax'] = zen_get_tax_rate($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId); } $this->notify('NOTIFY_ORDER_CART_ADD_PRODUCT_LIST', array('index' => $index, 'products' => $products[$i])); if ($products[$i]['attributes']) { $subindex = 0; reset($products[$i]['attributes']); while (list($option, $value) = each($products[$i]['attributes'])) { /* //clr 030714 Determine if attribute is a text attribute and change products array if it is. if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){ $attr_value = $products[$i]['attributes_values'][$option]; } else { $attr_value = $attributes->fields['products_options_values_name']; } */ $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n pa.options_values_price, pa.price_prefix\n from " . TABLE_PRODUCTS_OPTIONS . " popt,\n " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,\n " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n where pa.products_id = '" . (int) $products[$i]['id'] . "'\n and pa.options_id = '" . (int) $option . "'\n and pa.options_id = popt.products_options_id\n and pa.options_values_id = '" . (int) $value . "'\n and pa.options_values_id = poval.products_options_values_id\n and popt.language_id = '" . (int) $_SESSION['languages_id'] . "'\n and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'"; $attributes = $db->Execute($attributes_query); //clr 030714 Determine if attribute is a text attribute and change products array if it is. if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) { $attr_value = $products[$i]['attributes_values'][$option]; } else { $attr_value = $attributes->fields['products_options_values_name']; } $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes->fields['price_prefix'], 'price' => $attributes->fields['options_values_price']); $this->notify('NOTIFY_ORDER_CART_ADD_ATTRIBUTE_LIST', array('index' => $index, 'subindex' => $subindex, 'products' => $products[$i], 'attributes' => $attributes)); $subindex++; } } // add onetime charges here //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']) /************************************** * Check for external tax handling code **************************************/ $this->use_external_tax_handler_only = FALSE; $this->notify('NOTIFY_ORDER_CART_EXTERNAL_TAX_HANDLING', array(), $index, $taxCountryId, $taxZoneId); if ($this->use_external_tax_handler_only == FALSE) { /********************************************* * Calculate taxes for this product *********************************************/ $shown_price = zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']) + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']); $this->info['subtotal'] += $shown_price; $this->notify('NOTIFIY_ORDER_CART_SUBTOTAL_CALCULATE', array('shown_price' => $shown_price)); // find product's tax rate and description $products_tax = $this->products[$index]['tax']; $products_tax_description = $this->products[$index]['tax_description']; // Dual Pricing start - no taxes for wholesale customers if ($customer_address->fields['customers_whole'] > 0) { $products_tax = 0; $this->products[$index]['tax'] = 0; $tax_add = 0; $this->products[$index]['tax_description'] = ''; } if ($customer_address->fields['customers_whole'] == 0) { // Dual pricing end - no taxes for wholesale customers if (DISPLAY_PRICE_WITH_TAX == 'true') { // calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled) $tax_add = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)); } else { // calculate the amount of tax for this product (assuming tax is NOT included in the price) // $tax_add = zen_round(($products_tax / 100) * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']); $tax_add = $products_tax / 100 * $shown_price; } $this->info['tax'] += $tax_add; foreach ($taxRates as $taxDescription => $taxRate) { $taxAdd = zen_calculate_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $taxRate) + zen_calculate_tax($this->products[$index]['onetime_charges'], $taxRate); if (isset($this->info['tax_groups'][$taxDescription])) { $this->info['tax_groups'][$taxDescription] += $taxAdd; } else { $this->info['tax_groups'][$taxDescription] = $taxAdd; } } //Dual Pricing start - no taxes for wholesale customers } // Dual pricing end - no taxes for wholesale customers /********************************************* * END: Calculate taxes for this product *********************************************/ } $index++; } // Update the final total to include tax if not already tax-inc if (DISPLAY_PRICE_WITH_TAX == 'true') { $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost']; } else { $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost']; } /* // moved to function create if ($this->info['total'] == 0) { if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) { $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID; } else { $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID; } } */ if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) { if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) { $this->info['order_status'] = $GLOBALS[$class]->order_status; } } $this->notify('NOTIFY_ORDER_CART_FINISHED'); }
function calculate_deductions($order_total) { global $db, $order, $messageStack; $od_amount = array(); $deduction = $this->calculate_credit($this->get_order_total()); $od_amount['total'] = $deduction; switch ($this->calculate_tax) { case 'None': $remainder = $order->info['total'] - $od_amount['total']; $tax_deduct = $order->info['tax'] - $remainder; // division by 0 if ($order->info['tax'] <= 0) { $ratio_tax = 0; } else { $ratio_tax = $tax_deduct / $order->info['tax']; } $tax_deduct = 0; /* if ($this->include_tax) { reset($order->info['tax_groups']); foreach ($order->info['tax_groups'] as $key=>$value) { $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio_tax; $tax_deduct += $od_amount['tax_groups'][$key]; } } */ $od_amount['tax'] = $tax_deduct; break; case 'Standard': if ($od_amount['total'] >= $order_total) { $ratio = 1; } else { $ratio = $od_amount['total'] / ($order_total - $order->info['tax']); } reset($order->info['tax_groups']); $tax_deduct = 0; foreach ($order->info['tax_groups'] as $key => $value) { $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio; $tax_deduct += $od_amount['tax_groups'][$key]; } $od_amount['tax'] = $tax_deduct; break; case 'Credit Note': $od_amount['total'] = $deduction; $tax_rate = zen_get_tax_rate($this->tax_class); $od_amount['tax'] = zen_calculate_tax($deduction, $tax_rate); $tax_description = zen_get_tax_description($this->tax_class); $od_amount['tax_groups'][$tax_description] = $od_amount['tax']; break; default: } return $od_amount; }