require_once DIR_FS_INC . 'vam_date_short.inc.php'; require_once DIR_FS_INC . 'vam_get_path.inc.php'; require_once DIR_FS_INC . 'vam_get_product_path.inc.php'; require_once DIR_FS_INC . 'vam_get_products_name.inc.php'; require_once DIR_FS_INC . 'vam_get_products_image.inc.php'; $breadcrumb->add(NAVBAR_TITLE_ACCOUNT, vam_href_link(FILENAME_ACCOUNT, '', 'SSL')); require DIR_WS_INCLUDES . 'header.php'; if ($messageStack->size('account') > 0) { $vamTemplate->assign('error_message', $messageStack->output('account')); } $i = 0; $max = count($_SESSION['tracking']['products_history']); while ($i < $max) { $product_history_query = vamDBquery("select * from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id=pd.products_id and pd.language_id='" . (int) $_SESSION['languages_id'] . "' and p.products_status = '1' and p.products_id = '" . $_SESSION['tracking']['products_history'][$i] . "'"); $history_product = vam_db_fetch_array($product_history_query, true); $cpath = vam_get_product_path($_SESSION['tracking']['products_history'][$i]); if ($history_product['products_status'] != 0) { $history_product = array_merge($history_product, array('cat_url' => vam_href_link(FILENAME_DEFAULT, 'cat=' . $cpath))); $products_history[] = $product->buildDataArray($history_product); } $i++; } $order_content = ''; if (vam_count_customer_orders() > 0) { $orders_query = vam_db_query("select\n\t o.orders_id,\n\t o.date_purchased,\n\t o.delivery_name,\n\t o.delivery_country,\n\t o.billing_name,\n\t o.billing_country,\n\t ot.text as order_total,\n\t s.orders_status_name\n\t from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . "\n\t ot, " . TABLE_ORDERS_STATUS . " s\n\t where o.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\t and o.orders_id = ot.orders_id\n\t and ot.class = 'ot_total'\n\t and o.orders_status = s.orders_status_id\n\t and s.language_id = '" . (int) $_SESSION['languages_id'] . "'\n\t order by orders_id desc limit 3"); while ($orders = vam_db_fetch_array($orders_query)) { if (vam_not_null($orders['delivery_name'])) { $order_name = $orders['delivery_name']; $order_country = $orders['delivery_country']; } else { $order_name = $orders['billing_name'];
function calculate_tax_deduction($amount, $od_amount, $method) { global $order; $coupon_query = vam_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $_SESSION['cc_id'] . "'"); if (vam_db_num_rows($coupon_query) != 0) { $coupon_result = vam_db_fetch_array($coupon_query); $coupon_get = vam_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '" . $coupon_result['coupon_code'] . "'"); $get_result = vam_db_fetch_array($coupon_get); if ($get_result['coupon_type'] != 'S') { //RESTRICTION-------------------------------- if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) { // What to do here. // Loop through all products and build a list of all product_ids, price, tax class // at the same time create total net amount. // then // for percentage discounts. simply reduce tax group per product by discount percentage // or // for fixed payment amount // calculate ratio based on total net // for each product reduce tax group per product by ratio amount. $products = $_SESSION['cart']->get_products(); $valid_product = false; for ($i = 0; $i < sizeof($products); $i++) { $valid_product = false; $t_prid = vam_get_prid($products[$i]['id']); $cc_query = vam_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'"); $cc_result = vam_db_fetch_array($cc_query); if ($get_result['restrict_to_products']) { $pr_ids = preg_split("/[,]/", $get_result['restrict_to_products']); for ($p = 0; $p < sizeof($pr_ids); $p++) { if ($pr_ids[$p] == $t_prid) { $valid_product = true; } } } if ($get_result['restrict_to_categories']) { // v5.13a Tanaka 2005-4-30: New code, this correctly identifies valid products in subcategories $cat_ids = preg_split("/[,]/", $get_result['restrict_to_categories']); $my_path = vam_get_product_path($t_prid); $sub_cat_ids = preg_split("/[_]/", $my_path); for ($iii = 0; $iii < count($sub_cat_ids); $iii++) { for ($ii = 0; $ii < count($cat_ids); $ii++) { if ($sub_cat_ids[$iii] == $cat_ids[$ii]) { $valid_product = true; continue 2; } } } } if ($valid_product) { $price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity']; $price_incl_vat = $this->product_price($t_prid); $valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']); $total_price += $price_excl_vat; } } if (sizeof($valid_array) > 0) { // if ($valid_product) { if ($get_result['coupon_type'] == 'P') { $ratio = $get_result['coupon_amount'] / 100; } else { $ratio = $od_amount / $total_price; } if ($get_result['coupon_type'] == 'S') { $ratio = 1; } if ($method == 'Credit Note') { $tax_rate = vam_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tax_desc = vam_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); if ($get_result['coupon_type'] == 'P') { $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate; } else { $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100; } $order->info['tax_groups'][$tax_desc] -= $tod_amount; $order->info['total'] -= $tod_amount; $order->info['tax'] -= $tod_amount; } else { for ($p = 0; $p < sizeof($valid_array); $p++) { $tax_rate = vam_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']); $tax_desc = vam_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']); if ($tax_rate > 0) { $tod_amount = $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $order->info['tax_groups'][$tax_desc] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $order->info['total'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $order->info['tax'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; } } } } //NO RESTRICTION-------------------------------- } else { if ($get_result['coupon_type'] == 'F') { $tod_amount = 0; if ($method == 'Credit Note') { $tax_rate = vam_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tax_desc = vam_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate; $order->info['tax_groups'][TAX_ADD_TAX . $tax_desc] -= $tod_amount; } else { reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $ratio1 = $od_amount / ($amount - $order->info['tax_groups'][$key]); $tax_rate = vam_get_tax_rate_from_desc(str_replace(TAX_ADD_TAX, "", $key)); $net = $tax_rate * $order->info['tax_groups'][$key]; if ($net > 0) { $god_amount = $od_amount * $tax_rate / (100 + $tax_rate); $tod_amount += $god_amount; $order->info['tax_groups'][$key] -= $god_amount; } } } $order->info['total'] -= $tod_amount; $order->info['tax'] -= $tod_amount; } if ($get_result['coupon_type'] == 'P') { $tod_amount = 0; if ($method == 'Credit Note') { $tax_desc = vam_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100; $order->info['tax_groups'][TAX_ADD_TAX . $tax_desc] -= $tod_amount; } else { reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $god_amout = 0; $tax_rate = vam_get_tax_rate_from_desc(str_replace(TAX_ADD_TAX, "", $key)); $net = $tax_rate * $order->info['tax_groups'][$key]; if ($net > 0) { $god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount'] / 100; $tod_amount += $god_amount; $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; } } } $order->info['tax'] -= $tod_amount; } } } } return $tod_amount; }
$cID = str_replace('c', '', $cID); $_GET['cPath'] = vam_get_category_path($cID); } // new m URLS if (isset($_GET['manu'])) { $site = explode('_', $_GET['manu']); $mID = $site[0]; $mID = (int) str_replace('m', '', $mID); $_GET['manufacturers_id'] = $mID; } // calculate category path if (isset($_GET['cPath'])) { $cPath = vam_input_validation($_GET['cPath'], 'cPath', ''); } elseif (is_object($product) && !isset($_GET['manufacturers_id'])) { if ($product->isProduct()) { $cPath = vam_get_product_path($actual_products_id); } else { $cPath = ''; } } else { $cPath = ''; } if (vam_not_null($cPath)) { $cPath_array = vam_parse_category_path($cPath); $cPath = implode('_', $cPath_array); $current_category_id = $cPath_array[sizeof($cPath_array) - 1]; } else { $current_category_id = 0; } // include the breadcrumb class and start the breadcrumb trail require DIR_WS_CLASSES . 'breadcrumb.php';
function vam_fill_existing_fields($products_id, $languages_id) { global $currencies, $cPath, $PHP_SELF; $columns_query_raw = "\n select\n p.products_id,\n pd.products_name,\n pd.products_description,\n p.products_quantity,\n p.products_model,\n p.products_image,\n p.products_price,\n p.products_weight,\n p.products_tax_class_id,\n m.manufacturers_name,\n IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price,\n IF(s.status, s.specials_new_products_price, p.products_price) as final_price\n from\n " . TABLE_PRODUCTS . " p\n join " . TABLE_PRODUCTS_DESCRIPTION . " pd\n on (pd.products_id = p.products_id)\n left join " . TABLE_SPECIALS . " s\n on (p.products_id = s.products_id)\n left join " . TABLE_MANUFACTURERS . " m\n on (p.manufacturers_id = m.manufacturers_id)\n where\n p.products_id = '" . (int) $products_id . "'\n and pd.language_id = '" . (int) $languages_id . "'\n "; // print $columns_query_raw . "<br>\n"; $columns_query = vam_db_query($columns_query_raw); $columns_array = vam_db_fetch_array($columns_query); $field_array = array(); // Quantities may be used in columns or combination column $field_array['products_quantity'] = $columns_array['products_quantity'] == '' ? TEXT_NOT_AVAILABLE : $columns_array['products_quantity']; $field_array['products_model'] = $columns_array['products_model'] == '' ? TEXT_NOT_AVAILABLE : $columns_array['products_model']; $field_array['products_index_description'] = $columns_array['products_index_description'] == '' ? TEXT_NOT_AVAILABLE : $columns_array['products_index_description']; $field_array['products_description'] = $columns_array['products_description'] == '' ? TEXT_NOT_AVAILABLE : $columns_array['products_description']; $cPath_new = vam_get_product_path($columns_array['products_id']); $product_link = vam_href_link(FILENAME_PRODUCT_INFO, 'cPath=' . $cPath_new . '&products_id=' . $columns_array['products_id']); $field_array['products_image'] = '<a href="' . $product_link . '">' . vam_image(DIR_WS_IMAGES . trim($columns_array['products_image']), $columns_array['products_name']) . '</a>'; $field_array['products_name'] = $columns_array['products_name'] == '' ? TEXT_NOT_AVAILABLE : '<a href="' . $product_link . '">' . $columns_array['products_name'] . '</a>'; if (vam_not_null($columns_array['specials_new_products_price'])) { //$field_array['products_price'] = '<s>' . $currencies->display_price($columns_array['products_price'], vam_get_tax_rate($columns_array['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($columns_array['specials_new_products_price'], vam_get_tax_rate($columns_array['products_tax_class_id'])) . '</span>'; $field_array['products_price'] = '<s>' . $columns_array['products_price'] . '</s><br><span class="productSpecialPrice">' . $columns_array['specials_new_products_price'] . '</span>'; } else { //$field_array['products_price'] = $currencies->display_price($columns_array['products_price'], vam_get_tax_rate($columns_array['products_tax_class_id'])); $field_array['products_price'] = $columns_array['products_price']; } //$field_array['final_price'] = $currencies->display_price($columns_array['final_price'], vam_get_tax_rate($columns_array['products_tax_class_id'])); $field_array['final_price'] = $columns_array['final_price']; if ($columns_array['price_in_cart_only'] == '1') { $field_array['products_price'] = ' <span class="smalltext">'; $field_array['products_price'] .= '<script language="javascript"><!--' . "\n"; $field_array['products_price'] .= 'document.write(\'' . '<a href="javascript:popupWindow(\\\'' . vam_href_link(FILENAME_POPUP_PRICE_IN_CART) . '\\\')">' . TEXT_WHY_HIDE_PRICE . '</a>\');' . "\n"; $field_array['products_price'] .= '//--></script>' . "\n"; $field_array['products_price'] .= '<noscript>'; $field_array['products_price'] .= '<a href="' . vam_href_link(FILENAME_POPUP_PRICE_IN_CART) . '" target="_new">' . TEXT_WHY_HIDE_PRICE . '</a>'; $field_array['products_price'] .= '</noscript>'; $field_array['products_price'] .= ' </span>'; $field_array['final_price'] = $field_array['products_price']; } $raw_weight = number_format($columns_array['products_weight'], 1); if ($raw_weight - floor($raw_weight) == 0) { $raw_weight = number_format($columns_array['products_weight'], 0); } $field_array['products_weight'] = $raw_weight == 0.0 ? TEXT_NOT_AVAILABLE : $raw_weight; $field_array['manufacturers_name'] = $columns_array['manufacturers_name'] == '' ? TEXT_NOT_AVAILABLE : $columns_array['manufacturers_name']; $field_array['buy_now'] = ' <div class="buttonSet" style="margin-left:10px;"> <span class="buttonAction">' . vam_draw_hidden_field('products_id', $columns_array['products_id']) . 'incart_button' . '</span> </div>'; // Show Option/Attribute values if there are any $field_array['products_options'] = ' '; //$options_array = vam_get_products_attributes ($columns_array['products_id'], (int)$languages_id, $columns_array['products_tax_class_id']); if (is_array($options_array) && count($options_array) > 0) { $field_array['products_options'] = ''; foreach ($options_array as $options) { $field_array['products_options'] .= vam_select_attributes($columns_array['products_id'], $options, $languages_id, $columns_array['products_tax_class_id']); } } $field_array['popup_image'] = TEXT_NOT_AVAILABLE; $popup_array['image'] = $columns_array['products_image']; if (vam_not_null($popup_array['image'])) { $field_array['popup_image'] = '<script language="javascript"><!--' . "\n"; $field_array['popup_image'] .= 'document.write(\'<a href="javascript:popupWindow(\\\'' . vam_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $columns_array['products_id']) . '\\\')">' . TEXT_POPUP . '</a>\');' . "\n"; $field_array['popup_image'] .= '//--></script>' . "\n"; $field_array['popup_image'] .= '<noscript>' . "\n"; $field_array['popup_image'] .= '<a href="' . vam_href_link(DIR_WS_IMAGES . $columns_array['image']) . '" target="_blank">' . TEXT_POPUP . '</a>' . "\n"; $field_array['popup_image'] .= '</noscript>' . "\n"; } return $field_array; }