set_file("basket_js","basket.js");
$t->set_var("REMOVE_FROM_CART_JS", REMOVE_FROM_CART_JS);
$t->set_var("CLEAR_CART_JS", CLEAR_CART_JS);
$t->set_var("CART_QTY_ZERO_JS", CART_QTY_ZERO_JS);
$t->set_var("ALTER_CART_QTY_JS", ALTER_CART_QTY_JS);
$t->parse("basket_js", false);
$t->set_file("shopping_js","shopping.js");
$t->set_var("REQUIRED_PROPERTY_MSG", REQUIRED_PROPERTY_MSG);
$t->set_var("ADD_PRODUCT_MSG", ADD_PRODUCT_MSG);
$confirm_add = get_setting_value($settings, "confirm_add", 1);
$confirm_code = ($confirm_add) ? "confirm('".ADD_PRODUCT_MSG."')" : "true";
$t->set_var("confirm_code", $confirm_code);
$t->parse("shopping_js", false);
$t->templates_path = $settings["templates_dir"];
$t->set_file("main","basket.html");
$t->set_var("basket_href", "basket.php");
$t->set_var("current_href", "basket.php");
$t->set_var("checkout_href", "checkout.php");
$t->set_var("products_href", "products.php");
$t->set_var("CART_TITLE", CART_TITLE);
$t->set_var("EMPTY_CART_MSG", EMPTY_CART_MSG);
$t->set_var("PROD_CODE_MSG", PROD_CODE_MSG);
$t->set_var("PROD_TITLE_COLUMN", PROD_TITLE_COLUMN);
$t->set_var("PROD_QTY_COLUMN", PROD_QTY_COLUMN);
$t->set_var("PROD_PRICE_COLUMN", PROD_PRICE_COLUMN);
$t->set_var("PROD_TOTAL_COLUMN", PROD_TOTAL_COLUMN);
$t->set_var("PROD_TAX_TOTAL_COLUMN", PROD_TAX_TOTAL_COLUMN);
$t->set_var("GOODS_TOTAL_MSG", GOODS_TOTAL_MSG);
$t->set_var("TOTAL_DISCOUNT_MSG", TOTAL_DISCOUNT_MSG);
$t->set_var("GOODS_WITH_DISCOUNT_MSG",GOODS_WITH_DISCOUNT_MSG);
$t->set_var("PROD_SUBCOMPONENTS_MSG", PROD_SUBCOMPONENTS_MSG);
$t->set_var("CART_TOTAL_MSG", CART_TOTAL_MSG);
$t->set_var("CONTINUE_SHOPPING_MSG", CONTINUE_SHOPPING_MSG);
$t->set_var("REMOVE_FROM_CART_MSG",REMOVE_FROM_CART_MSG);
$t->set_var("COUPON_REMOVE_MSG", COUPON_REMOVE_MSG);
$t->set_var("CLEAR_CART_MSG", CLEAR_CART_MSG);
$t->set_var("ADD_TO_CART_MSG", ADD_TO_CART_MSG);
$t->set_var("VIEW_CART_MSG", VIEW_CART_MSG);
$t->set_var("AMEND_CART_MSG", AMEND_CART_MSG);
$t->set_var("GOTO_CHECKOUT_MSG", GOTO_CHECKOUT_MSG);
$t->set_var("COUPON_CODE_FIELD", COUPON_CODE_FIELD);
$t->set_var("APPLY_BUTTON", APPLY_BUTTON);
// generate page link with query parameters
$page = "basket.php";
$remove_parameters = array("rnd", "cart", "item_id", "type", "cart_id", "quantity", "new_quantity", "operation", "coupon_code", "coupon_id");
$get_vars = isset($_GET) ? $_GET : $HTTP_GET_VARS;
$query_string = get_query_string($get_vars, $remove_parameters, "", true);
$page .= $query_string;
$page_link = $page;
$page_link .= strlen($query_string) ? "&" : "?";
srand ((double) microtime() * 1000000);
$random_value = rand();
$currency = get_currency();
$currency_left = $currency["left"];
$currency_right = $currency["right"];
$currency_rate = $currency["rate"];
$tax_rates = get_tax_rates();
$user_type_id = get_session("session_user_type_id");
$user_discount_type = get_session("session_discount_type");
$user_discount_amount = get_session("session_discount_amount");
$tax_prices = get_setting_value($settings, "tax_prices", 0);
$product_code_basket = get_setting_value($settings, "product_code_basket", 0);
$remove_link = $page_link . "cart=RM&rnd=" . $random_value . "&cart_id=";
$remove_all_link = $page_link . "cart=CLR&rnd=" . $random_value;
$t->set_var("random_value", $random_value);
if ($tax_prices) {
if (isset($tax_rates["tax_name"])) {
$t->set_var("tax_name", $tax_rates["tax_name"]);
}
}
// set up return page
$rp_link = get_param("rp");
if(!$rp_link) $rp_link = "products.php";
$t->set_var("rp_href", htmlspecialchars($rp_link));
include("./header.php");
include("./footer.php");
$coupon_id = "";
$coupon_errors = "";
$operation = get_param("operation");
$shopping_cart = get_session("shopping_cart");
$coupons = get_session("session_coupons");
$coupons_enable = get_setting_value($settings, "coupons_enable");
if($coupons_enable && $operation == "add") {
$coupon_code = trim(get_param("coupon_code"));
if (!strlen($coupon_code)) {
$required_msg = str_replace("{field_name}", COUPON_CODE_FIELD, REQUIRED_MESSAGE);
$coupon_errors = $required_msg;
} else {
$sql = " SELECT * FROM " . $table_prefix . "coupons ";
$sql .= " WHERE coupon_code=" . $db->tosql($coupon_code, TEXT);
$db->query($sql);
if($db->next_record()) {
$is_active = $db->f("is_active");
$new_coupon_id = $db->f("coupon_id");
$coupon_title = $db->f("coupon_title");
$discount_type = $db->f("discount_type");
$coupon_discount = $db->f("discount_amount");
$free_postage = $db->f("free_postage");
$tax_free = $db->f("tax_free");
$items_all = $db->f("items_all");
$items_ids = $db->f("items_ids");
$expiry_date = "";
$is_expired = false;
$expiry_date_db = $db->f("expiry_date", DATETIME);
if (is_array($expiry_date_db)) {
$expiry_date = va_date($date_show_format, $expiry_date_db);
$expiry_date_ts = mktime (0,0,0, $expiry_date_db[MONTH], $expiry_date_db[DAY], $expiry_date_db[YEAR]);
$current_date_ts = time();
if($current_date_ts > $expiry_date_ts) {
$is_expired = true;
}
}
$minimum_amount = $db->f("minimum_amount");
$is_exclusive = $db->f("is_exclusive");
$quantity_limit = $db->f("quantity_limit");
$coupon_uses = $db->f("coupon_uses");
if (!$is_active) {
$coupon_errors = COUPON_NON_ACTIVE_MSG;
} else if ($quantity_limit > 0 && $coupon_uses >= $quantity_limit) {
$coupon_errors = COUPON_USED_MSG;
} else if ($is_expired) {
$coupon_errors = COUPON_EXPIRED_MSG;
} else {
$coupons_total = 0; $vouchers_total = 0; $coupon_applied = false; $exclusive_applied = false;
// check order coupons
if(is_array($coupons) && sizeof($coupons) > 0) {
foreach ($coupons as $coupon_id => $coupon_info) {
if ($coupon_info["DISCOUNT_TYPE"] == 5) {
$vouchers_total++;
} else {
$coupons_total++;
}
if (($coupon_info["DISCOUNT_TYPE"] <= 2 || $coupon_info["DISCOUNT_TYPE"] == 5) && $new_coupon_id == $coupon_info["COUPON_ID"]) {
$coupon_applied = true;
} else if ($coupon_info["EXCLUSIVE"] == true) {
$exclusive_applied = true;
}
}
}
// check products coupons
foreach ($shopping_cart as $cart_id => $item) {
if (isset($item["COUPONS"]) && is_array($item["COUPONS"])) {
foreach ($item["COUPONS"] as $coupon_id => $coupon_info) {
$coupons_total++;
if ($coupon_info["EXCLUSIVE"] == true) {
$exclusive_applied = true;
}
}
}
}
if ($coupon_applied) {
$coupon_errors = COUPON_APPLIED_MSG;
} else if ($exclusive_applied || ($is_exclusive && $coupons_total > 0)) {
$coupon_errors = COUPON_EXCLUSIVE_MSG;
}
}
if (!$coupon_errors) {
$search_items_ids = ",," . $items_ids . ",,";
$total_price = 0; $coupon_items = false;
foreach($shopping_cart as $cart_id => $item) {
$properties_more = $item["PROPERTIES_MORE"];
if (!$properties_more) {
$item_id = $item["ITEM_ID"];
$price = $item["PRICE"];
$is_price_edit = $item["PRICE_EDIT"];
$buying_price = $item["BUYING_PRICE"];
$properties_price = $item["PROPERTIES_PRICE"];
$properties_buying = $item["PROPERTIES_BUYING"];
//$discount_total = 0;
if (!$is_price_edit) {
if ($user_discount_type == 1) {
$price -= round(($price * $user_discount_amount) / 100, 2);
} else if ($user_discount_type == 2) {
$price -= round($user_discount_amount, 2);
} else if ($user_discount_type == 3) {
$price -= round(($price * $user_discount_amount) / 100, 2);
} else if ($user_discount_type == 4) {
$price -= round((($price - $buying_price) * $user_discount_amount) / 100, 2);
}
}
if ($user_discount_type == 1) {
$properties_price -= round(($properties_price * $user_discount_amount) / 100, 2);
} else if ($user_discount_type == 4) {
$properties_price -= round((($properties_price - $properties_buying) * $user_discount_amount) / 100, 2);
}
$price += $properties_price;
//$price -= $discount_total;
if ($discount_type == 3 || $discount_type == 4) {
if ($price >= $minimum_amount && ($items_all || strpos($search_items_ids, $item_id)) ) {
// add coupon to products
$coupon_items = true;
if ($discount_type == 3) {
$discount_amount = round(($price / 100) * $coupon_discount, 2);
} else {
$discount_amount = $coupon_discount;
}
if (!isset($item["COUPONS"]) || !isset($item["COUPONS"][$new_coupon_id])) {
$shopping_cart[$cart_id]["COUPONS"][$new_coupon_id] = array("COUPON_ID" => $new_coupon_id, "EXCLUSIVE" => $is_exclusive, "DISCOUNT_AMOUNT" => $discount_amount);
set_session("shopping_cart", $shopping_cart);
}
}
}
$quantity = $shopping_cart[$cart_id]["QUANTITY"];
$total_price += ($quantity * $price);
}
}
if (($discount_type == 3 || $discount_type == 4) && !$coupon_items) {
$coupon_errors = COUPON_PRODUCTS_MSG;
} else if ($discount_type <= 2 && $minimum_amount > $total_price) {
$coupon_errors = str_replace("{minimum_amount}", $currency_left . number_format($minimum_amount * $currency_rate, 2) . $currency_right, COUPON_ORDER_AMOUNT_MSG);
} else if ($discount_type <= 2 || $discount_type == 5) {
// add new coupon to system
$coupons[$new_coupon_id] = array("COUPON_ID" => $new_coupon_id, "DISCOUNT_TYPE" => $discount_type, "EXCLUSIVE" => $is_exclusive, "TAX_FREE" => $tax_free);
set_session("session_coupons", $coupons);
}
}
} else {
$coupon_errors = COUPON_NOT_FOUND_MSG;
}
}
} else if ($operation == "rm_coupon") {
$coupon_id = get_param("coupon_id");
remove_coupon($coupon_id);
}
// check if there are any coupon with free tax
$coupon_tax_free = false;
if (is_array($coupons)) {
foreach ($coupons as $coupon_id => $coupon_info) {
$tax_free = $coupon_info["TAX_FREE"];
if ($tax_free) {
$coupon_tax_free = true;
break;
}
}
}
// prepare total products quantities
$goods_total = 0;
$goods_tax_total = 0;
$goods_taxable = 0;
$total_quantity = 0;
if(is_array($shopping_cart))
{
$t->set_var("empty", "");
$t->set_var("items", "");
$t->set_var("coupons", "");
if ($tax_prices) {
$t->sparse("tax_headers", false);
}
foreach ($shopping_cart as $cart_id => $item) {
$properties_more = $item["PROPERTIES_MORE"];
if ($properties_more > 0) {
continue;
}
$item_id = $item["ITEM_ID"];
$properties = $item["PROPERTIES"];
$components = $item["COMPONENTS"];
$item_coupons = isset($item["COUPONS"]) ? $item["COUPONS"] : "";
$quantity = $item["QUANTITY"];
$sql = " SELECT item_name, item_type_id, manufacturer_code, small_image, short_description, ";
$sql .= " price, is_price_edit, is_sales, sales_price, buying_price, ";
$sql .= " tax_free, stock_level, use_stock_level, hide_out_of_stock, disable_out_of_stock ";
$sql .= " FROM " . $table_prefix . "items ";
$sql .= " WHERE item_id=" . $db->tosql($item_id, INTEGER);
$db->query($sql);
if($db->next_record())
{
// some price calculation
$item_type_id = $db->f("item_type_id");
$manufacturer_code = $db->f("manufacturer_code");
$price = $db->f("price");
$is_price_edit = $db->f("is_price_edit");
if ($is_price_edit) {
$price = $item["PRICE"];
}
$is_sales = $db->f("is_sales");
$sales_price = $db->f("sales_price");
$buying_price = $db->f("buying_price");
$item_name = get_translation($db->f("item_name"));
$item_name_js = str_replace("'", "\\'", htmlspecialchars($item_name));
$short_description = get_translation($db->f("short_description"));
$tax_free = ($coupon_tax_free || $db->f("tax_free"));
$stock_level = $db->f("stock_level");
$use_stock_level = $db->f("use_stock_level");
$hide_out_of_stock = $db->f("hide_out_of_stock");
$disable_out_of_stock = $db->f("disable_out_of_stock");
$small_image = $db->f("small_image");
$product_url = "product_details.php?item_id=" . $item_id;
$properties_discount = 0;
$discount_applicable = 1;
if (!$is_price_edit) {
$price = calculate_price($price, $is_sales, $sales_price);
$quantity_price = get_quantity_price($item_id, $quantity);
if (sizeof($quantity_price)) {
$price = $quantity_price[0];
$properties_discount = $quantity_price[1];
$discount_applicable = $quantity_price[2];
}
if ($discount_applicable) {
if ($user_discount_type == 1 || $user_discount_type == 3) {
$price -= round(($price * $user_discount_amount) / 100, 2);
} else if ($user_discount_type == 2) {
$price -= round($user_discount_amount, 2);
} else if ($user_discount_type == 4) {
$price -= round((($price - $buying_price) * $user_discount_amount) / 100, 2);
}
}
}
// check product subcomponents
$components_price = 0; $components_tax_amount = 0;
if (sizeof($components) > 0) {
$t->set_var("components", "");
foreach ($components as $property_id => $component_values) {
foreach ($component_values as $item_property_id => $component) {
$property_type_id = $component["type_id"];
$sub_item_id = $component["sub_item_id"];
if ($property_type_id == 2) {
$sql = " SELECT pr.property_name AS component_name, pr.additional_price AS component_price, ";
$sql .= " i.item_type_id, i.buying_price, i.price, i.is_sales, i.sales_price, i.tax_free, ";
$sql .= " i.stock_level, i.use_stock_level, i.hide_out_of_stock, i.disable_out_of_stock, ";
$sql .= " ip.price AS user_price, ip.discount_action AS user_price_action ";
$sql .= " FROM ((" . $table_prefix . "items_properties pr ";
$sql .= " INNER JOIN " . $table_prefix . "items i ON pr.sub_item_id=i.item_id)";
$sql .= " LEFT JOIN " . $table_prefix . "items_prices ip ON ";
$sql .= " (i.item_id=ip.item_id AND ip.min_quantity>=" . $db->tosql($quantity, INTEGER) . " AND ip.max_quantity<=" . $db->tosql($quantity, INTEGER);
$sql .= " AND (ip.user_type_id=0 OR ip.user_type_id=" . $db->tosql($user_type_id, INTEGER) . "))) ";
$sql .= " WHERE pr.property_id=" . $db->tosql($property_id, INTEGER);
$sql .= " ORDER BY ip.user_type_id DESC ";
} else {
$sql = " SELECT ipv.property_value AS component_name, ipv.additional_price AS component_price, ";
$sql .= " i.item_type_id, i.buying_price, i.price, i.is_sales, i.sales_price, i.tax_free, ";
$sql .= " i.stock_level, i.use_stock_level, i.hide_out_of_stock, i.disable_out_of_stock, ";
$sql .= " ip.price AS user_price, ip.discount_action AS user_price_action ";
$sql .= " FROM ((" . $table_prefix . "items_properties_values ipv ";
$sql .= " INNER JOIN " . $table_prefix . "items i ON ipv.sub_item_id=i.item_id)";
$sql .= " LEFT JOIN " . $table_prefix . "items_prices ip ON ";
$sql .= " (i.item_id=ip.item_id AND ip.min_quantity>=" . $db->tosql($quantity, INTEGER) . " AND ip.max_quantity<=" . $db->tosql($quantity, INTEGER);
$sql .= " AND (ip.user_type_id=0 OR ip.user_type_id=" . $db->tosql($user_type_id, INTEGER) . "))) ";
$sql .= " WHERE ipv.item_property_id=" . $db->tosql($item_property_id, INTEGER);
$sql .= " ORDER BY ip.user_type_id DESC ";
}
$db->query($sql);
if ($db->next_record()) {
$sub_type_id = $db->f("item_type_id");
$sub_tax_free = ($coupon_tax_free || $db->f("tax_free"));
$component_name = $db->f("component_name");
$component_price = $db->f("component_price");
if (!strlen($component_price)) {
$sub_price = $db->f("price");
$sub_buying = $db->f("buying_price");
$sub_is_sales = $db->f("is_sales");
$sub_sales = $db->f("sales_price");
$sub_user_price = $db->f("user_price");
$sub_user_action = $db->f("user_price_action");
$sub_prices = get_product_price($sub_item_id, $sub_price, $sub_buying, $sub_is_sales, $sub_sales, $sub_user_price, $sub_user_action, $user_discount_type, $user_discount_amount);
$component_price = $sub_prices["base"];
// update information in the cart as well
if ($sub_is_sales && $sub_sales > 0) {
$component["base_price"] = $sub_sales;
} else {
$component["base_price"] = $sub_price;
}
$component["buying"] = $db->f("buying_price");
$component["user_price"] = $db->f("user_price");
$component["user_price_action"] = $db->f("user_price_action");
$shopping_cart[$cart_id]["COMPONENTS"][$property_id][$item_property_id] = $component;
}
$component_tax_amount = set_tax_price($sub_item_id, $sub_type_id, $component_price, $sub_tax_free);
//$price += $component_price;
$components_price += $component_price;
$components_tax_amount += $component_tax_amount;
$t->set_var("component_name", $component_name);
if ($component_price != 0) {
$t->set_var("component_price", "(" . $currency_left . number_format($component_price * $currency_rate, 2) . $currency_right . ")");
}
$t->sparse("components", true);
}
}
}
$t->sparse("components_block", false);
} else {
$t->set_var("components_block", "");
}
// set item variables into html
$t->set_var("item_name", $item_name);
$t->set_var("short_description", $short_description);
$t->set_var("manufacturer_code", $manufacturer_code);
// show product code
if ($product_code_basket && $manufacturer_code) {
$t->sparse("product_code", false);
} else {
$t->set_var("product_code", "");
}
$t->set_var("product_url", $product_url);
if(strtoupper($settings["quantity_control"]) == "LISTBOX")
{
$max_quantity = $quantity + 10;
if(($disable_out_of_stock || $hide_out_of_stock) && $max_quantity > $stock_level && $use_stock_level)
$max_quantity = $stock_level;
// load data for listbox
$quantities = array();
for($i = 0; $i <= $max_quantity; $i++)
$quantities[] = array($i, $i);
$quantity_select = "";
$t->set_var("quantity", $quantity_select);
}
else if(strtoupper($settings["quantity_control"]) == "TEXTBOX")
{
$quantity_textbox = "set_var("quantity", $quantity_textbox);
} else {
$t->set_var("quantity", $quantity);
}
$t->set_var("small_image", $small_image);
// show properties if they available
$properties_values = "";
$properties_price = 0;
if(is_array($properties))
{
reset($properties);
while(list($property_id, $property_values) = each($properties))
{
$sql = " SELECT property_type_id, property_name, control_type ";
$sql .= " FROM " . $table_prefix . "items_properties ";
$sql .= " WHERE property_id=" . $db->tosql($property_id, INTEGER);
$db->query($sql);
if ($db->next_record()) {
$property_type_id = $db->f("property_type_id");
// show only product options and subcomponents separately
if ($property_type_id == 1) {
$property_name = get_translation($db->f("property_name"));
$control_type = $db->f("control_type");
$property_price = 0;
if (strtoupper($control_type) == "LISTBOX" || strtoupper($control_type) == "RADIOBUTTON"
|| strtoupper($control_type) == "CHECKBOXLIST") {
$values_list = "";
for($pv = 0; $pv < sizeof($property_values); $pv++) {
$sql = " SELECT property_value, additional_price, buying_price ";
$sql .= " FROM " . $table_prefix . "items_properties_values ipv ";
$sql .= " WHERE property_id=" . $db->tosql($property_id, INTEGER);
$sql .= " AND item_property_id=" . $db->tosql($property_values[$pv], INTEGER);
$db->query($sql);
if($db->next_record()) {
$additional_price = $db->f("additional_price");
$buying_price = $db->f("buying_price");
if ($properties_discount > 0) {
$additional_price -= round(($additional_price * $properties_discount) / 100, 2);
}
if ($discount_applicable && $user_discount_type == 1) {
$additional_price -= round(($additional_price * $user_discount_amount) / 100, 2);
} else if ($discount_applicable && $user_discount_type == 4) {
$additional_price -= round((($additional_price - $buying_price) * $user_discount_amount) / 100, 2);
}
$property_price += $additional_price;
$properties_price += $additional_price;
if ($values_list) { $values_list .= ", "; }
$values_list .= get_translation($db->f("property_value"));
}
}
$properties_values .= "
" . $property_name . ": " . $values_list;
if ($property_price > 0) {
$properties_values .= " (+ " . $currency_left . number_format($property_price * $currency_rate, 2) . $currency_right . ")";
} else if ($property_price < 0) {
$properties_values .= " (- " . $currency_left . number_format(abs($property_price) * $currency_rate, 2) . $currency_right . ")";
}
} else if ($property_values[0]) {
$property_value = get_translation($property_values[0]);
if (preg_match("/^http\:\/\//", $property_value)) {
$property_value = "" . basename($property_value) . "";
}
$properties_values .= "
" . $property_name . ": " . $property_value;
}
}
}
}
}
// show product coupons if availble
$product_discount = 0;
if(is_array($item_coupons))
{
foreach ($item_coupons as $coupon_id => $coupon_info)
{
$sql = " SELECT * ";
$sql .= " FROM " . $table_prefix . "coupons ";
$sql .= " WHERE coupon_id=" . $db->tosql($coupon_info["COUPON_ID"], INTEGER);
$db->query($sql);
if($db->next_record()) {
$remove_coupon_link = $page_link . "operation=rm_coupon&coupon_id=" . $coupon_id;
$is_active = $db->f("is_active");
$coupon_title = $db->f("coupon_title");
$discount_type = $db->f("discount_type");
$coupon_discount = $db->f("discount_amount");
$minimum_amount = $db->f("minimum_amount");
$quantity_limit = $db->f("quantity_limit");
$coupon_uses = $db->f("coupon_uses");
if (!$is_active) {
$coupon_code = $db->f("coupon_code");
$coupon_errors = COUPON_NON_ACTIVE_MSG;
remove_coupon($coupon_id);
} else if ($quantity_limit > 0 && $coupon_uses >= $quantity_limit) {
$coupon_code = $db->f("coupon_code");
$coupon_errors = COUPON_USED_MSG;
remove_coupon($coupon_id);
} else if ($price < $minimum_amount) {
$coupon_code = $db->f("coupon_code");
$coupon_errors = str_replace("{minimum_amount}", $currency_left . number_format($minimum_amount * $currency_rate, 2) . $currency_right, COUPON_PROD_PRICE_MSG);
remove_coupon($coupon_id);
} else {
if($discount_type == 3) {
$discount_amount = round((($price + $properties_price) / 100) * $coupon_discount, 2);
} else {
$discount_amount = $coupon_discount;
}
$product_discount += $discount_amount;
$properties_values .= "
" . $coupon_title . " (- " . $currency_left . number_format($discount_amount * $currency_rate, 2) . $currency_right . ")";
$properties_values .= "
" . COUPON_REMOVE_MSG . "";
}
}
}
}
$t->set_var("properties_values", $properties_values);
$price = round($price + $properties_price - $product_discount, 2);
$tax_amount = set_tax_price($item_id, $item_type_id, $price, $tax_free);
// add components price to the total product price
$price += $components_price;
$tax_amount += $components_tax_amount;
$item_total = $price * $quantity;
$item_tax_total = $tax_amount * $quantity;
$goods_total += $item_total;
$goods_tax_total += $item_tax_total;
if ($tax_free != 1) {
$goods_taxable += $item_total;
}
$total_quantity += $quantity;
$t->set_var("price", $currency_left . number_format($price * $currency_rate, 2) . $currency_right);
$t->set_var("item_total", $currency_left . number_format($item_total * $currency_rate, 2) . $currency_right);
if ($tax_prices) {
$t->set_var("item_tax_total", $currency_left . number_format($item_tax_total * $currency_rate, 2) . $currency_right);
$t->sparse("item_tax", false);
}
$t->set_var("item_type", PRODUCT_MSG);
$t->set_var("remove_href", $remove_link . $cart_id);
$t->parse("items", true);
}
else
{
unset($shopping_cart[$cart_id]);
}
}
}
set_session("shopping_cart", $shopping_cart);
// show summary information and discounts if there are any products
if ($total_quantity > 0) {
// show information about order coupons
$max_discount = $goods_total;
$max_tax_discount = $goods_tax_total;
$order_coupons = 0;
$total_discount = 0; $total_tax_discount = 0;
if(is_array($coupons)) {
//$t->set_var("REMOVE_FROM_CART_MSG", COUPON_REMOVE_MSG);
foreach ($coupons as $coupon_id => $coupon_info) {
$coupon_id = $coupon_info["COUPON_ID"];
$sql = " SELECT * FROM " . $table_prefix . "coupons ";
$sql .= " WHERE coupon_id=" . $db->tosql($coupon_id, INTEGER);
$db->query($sql);
if ($db->next_record()) {
$is_active = $db->f("is_active");
$discount_type = $db->f("discount_type");
$coupon_discount = $db->f("discount_amount");
$minimum_amount = $db->f("minimum_amount");
$quantity_limit = $db->f("quantity_limit");
$coupon_uses = $db->f("coupon_uses");
if (!$is_active) {
$coupon_code = $db->f("coupon_code");
$coupon_errors = COUPON_NON_ACTIVE_MSG;
remove_coupon($coupon_id);
} else if ($quantity_limit > 0 && $coupon_uses >= $quantity_limit) {
$coupon_code = $db->f("coupon_code");
$coupon_errors = COUPON_USED_MSG;
remove_coupon($coupon_id);
} else if ($goods_total < $minimum_amount) {
$coupon_code = $db->f("coupon_code");
$coupon_errors = str_replace("{minimum_amount}", $currency_left . number_format($minimum_amount * $currency_rate, 2) . $currency_right, COUPON_ORDER_AMOUNT_MSG);
remove_coupon($coupon_id);
} else {
// show coupon information if no errors occurred
$order_coupons++;
if ($discount_type == 1) {
$discount_amount = round(($goods_total / 100) * $coupon_discount, 2);
} else {
$discount_amount = $coupon_discount;
}
if ($discount_amount > $max_discount) {
$discount_amount = $max_discount;
}
$max_discount -= $discount_amount;
// check discount tax
$discount_tax_amount = round(($discount_amount * $goods_tax_total) / $goods_total, 2);
if ($discount_tax_amount > $max_tax_discount) {
$discount_tax_amount = $max_tax_discount;
}
$max_tax_discount -= $discount_tax_amount;
$t->set_var("coupon_title", $db->f("coupon_title"));
$t->set_var("discount_amount", "- " . $currency_left . number_format($discount_amount * $currency_rate, 2) . $currency_right);
if ($tax_prices) {
$t->set_var("discount_tax_amount", "- " . $currency_left . number_format($discount_tax_amount * $currency_rate, 2) . $currency_right);
$t->sparse("discount_tax", false);
}
$total_discount += $discount_amount;
$total_tax_discount += $discount_tax_amount;
$remove_coupon_link = $page_link . "operation=rm_coupon&coupon_id=" . $coupon_id;
$t->set_var("item_type", COUPON_MSG);
$t->set_var("remove_href", $remove_coupon_link);
$t->parse("coupons", true);
}
}
}
}
if ($coupon_errors) {
$t->set_var("errors_list", $coupon_errors);
$t->set_var("coupon_code", htmlspecialchars($coupon_code));
$t->parse("coupon_errors", false);
} else {
$t->set_var("coupon_code", "");
$t->set_var("coupon_errors", "");
}
$t->set_var("total_quantity", $total_quantity);
$t->set_var("goods_total", $currency_left . number_format($goods_total * $currency_rate, 2) . $currency_right);
if ($tax_prices) {
$t->set_var("goods_tax_total", $currency_left . number_format($goods_tax_total * $currency_rate, 2) . $currency_right);
$t->sparse("goods_tax", false);
}
$t->set_var("remove_all_href", $remove_all_link);
if($total_discount || $order_coupons > 0) {
$t->set_var("total_discount", "- " . $currency_left . number_format($total_discount * $currency_rate, 2) . $currency_right);
$t->set_var("goods_with_discount", $currency_left . number_format(($goods_total - $total_discount) * $currency_rate, 2) . $currency_right);
if ($tax_prices) {
$t->set_var("total_tax_discount_amount", "- " . $currency_left . number_format($total_tax_discount * $currency_rate, 2) . $currency_right);
$t->set_var("discounted_tax_amount", $currency_left . number_format(($goods_tax_total - $total_tax_discount) * $currency_rate, 2) . $currency_right);
$t->sparse("total_tax_discount", false);
$t->sparse("discounted_tax", false);
}
$t->parse("discount", false);
} else {
$t->set_var("discount", "");
}
$t->parse("basket", false);
$t->parse("basket_links", false);
if ($coupons_enable) {
$t->parse("coupon_form", false);
} else {
$t->set_var("coupon_form", "");
}
//todo
//basket_recommended("basket_recommended");
} else {
$t->set_var("coupon_form", "");
$t->set_var("basket", "");
$t->parse("empty", false);
}
$t->pparse("main");
?>