$review_user_name .= " (" . GUEST_MSG . ")"; } $review_user_class = $review_user_id ? "forumUser" : "forumGuest"; //Customization by Vital //$rating = round($db->f("rating"), 0); if ($db->f("rating") != null) { $rating += round($db->f("rating"), 0); $rating_count++; } //$rating_image = $rating ? "rating-" . $rating : "not-rated"; //$t->set_var("rating_image", $rating_image); //END customization $t->set_var("review_user_class", $review_user_class); $t->set_var("review_user_name", $review_user_name); $date_added = $db->f("date_added", DATETIME); $date_added_string = va_date($datetime_show_format, $date_added); $t->set_var("review_date_added", $date_added_string); $t->set_var("review_summary", htmlspecialchars($db->f("summary"))); $t->set_var("review_comments", nl2br(htmlspecialchars($db->f("comments")))); $t->parse("negative_review", true); } while ($db->next_record()); } //Customization by Vital if ($rating_count != 0) { $rating = round($rating / $rating_count, 0); $rating_image = "rating-" . $rating; } else { $rating_image = "not-rated"; } $t->set_var("rating_image", $rating_image); $t->set_var("rating_count", $rating_count);
function check_add_coupons($auto_apply, $new_coupon_code, &$new_coupon_error) { global $db, $site_id, $table_prefix, $date_show_format; global $currency; $shopping_cart = get_session("shopping_cart"); $order_coupons = get_session("session_coupons"); $user_info = get_session("session_user_info"); $user_id = get_setting_value($user_info, "user_id", ""); $user_type_id = get_setting_value($user_info, "user_type_id", ""); $user_tax_free = get_setting_value($user_info, "tax_free", 0); $user_discount_type = get_session("session_discount_type"); $user_discount_amount = get_session("session_discount_amount"); if (!is_array($shopping_cart) || sizeof($shopping_cart) < 1) { return; } // check basic product prices before any further checks foreach ($shopping_cart as $cart_id => $item) { $item_id = $item["ITEM_ID"]; $properties_more = $item["PROPERTIES_MORE"]; if (!$item_id || $properties_more > 0) { continue; } $item_type_id = $item["ITEM_TYPE_ID"]; $properties = $item["PROPERTIES"]; $quantity = $item["QUANTITY"]; $tax_id = $item["TAX_ID"]; $tax_free = $item["TAX_FREE"]; $discount_applicable = $item["DISCOUNT"]; $buying_price = $item["BUYING_PRICE"]; $price = $item["PRICE"]; $is_price_edit = $item["PRICE_EDIT"]; $properties_price = $item["PROPERTIES_PRICE"]; $properties_percentage = $item["PROPERTIES_PERCENTAGE"]; $properties_buying = $item["PROPERTIES_BUYING"]; $properties_discount = $item["PROPERTIES_DISCOUNT"]; $components = $item["COMPONENTS"]; if ($discount_applicable) { 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 ($properties_percentage && $price) { $properties_price += round($price * $properties_percentage / 100, 2); } if ($properties_discount > 0) { $properties_price -= round($properties_price * $properties_discount / 100, 2); } if ($discount_applicable) { 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; // add components prices if (is_array($components) && sizeof($components) > 0) { foreach ($components as $property_id => $component_values) { foreach ($component_values as $property_item_id => $component) { $component_price = $component["price"]; $component_tax_id = $component["tax_id"]; $component_tax_free = $component["tax_free"]; if ($user_tax_free) { $component_tax_free = $user_tax_free; } $sub_item_id = $component["sub_item_id"]; $sub_quantity = $component["quantity"]; if ($sub_quantity < 1) { $sub_quantity = 1; } $sub_type_id = $component["item_type_id"]; if (!strlen($component_price)) { $sub_price = $component["base_price"]; $sub_buying = $component["buying"]; $sub_user_price = $component["user_price"]; $sub_user_action = $component["user_price_action"]; $sub_prices = get_product_price($sub_item_id, $sub_price, $sub_buying, 0, 0, $sub_user_price, $sub_user_action, $user_discount_type, $user_discount_amount); $component_price = $sub_prices["base"]; } // add to the item price component price $price += $component_price; } } } $shopping_cart[$cart_id]["BASIC_PRICE"] = $price; // basic price to calculate discount amount for product coupons $shopping_cart[$cart_id]["DISCOUNTED_PRICE"] = $price; // product price with all coupon discounts } // end of product prices check // check if any product coupons should be removed $exclusive_applied = false; $new_coupons_total = 0; $coupons_total = 0; foreach ($shopping_cart as $cart_id => $item) { $item_id = $item["ITEM_ID"]; $properties_more = $item["PROPERTIES_MORE"]; if (!$item_id || $properties_more > 0) { continue; } $item_type_id = $item["ITEM_TYPE_ID"]; $basic_price = $item["BASIC_PRICE"]; $discounted_price = $item["DISCOUNTED_PRICE"]; $quantity = $item["QUANTITY"]; // product coupons if (isset($item["COUPONS"]) && is_array($item["COUPONS"])) { foreach ($item["COUPONS"] as $coupon_id => $coupon_info) { if ($auto_apply && $coupon_info["AUTO_APPLY"]) { // always remove auto-apply coupons unset($shopping_cart[$cart_id]["COUPONS"][$coupon_id]); } else { $sql = " SELECT * FROM " . $table_prefix . "coupons "; $sql .= " WHERE coupon_id=" . $db->tosql($coupon_id, INTEGER); $db->query($sql); if ($db->next_record()) { $discount_type = $db->f("discount_type"); $coupon_discount = $db->f("discount_amount"); $min_quantity = $db->f("min_quantity"); $max_quantity = $db->f("max_quantity"); $minimum_amount = $db->f("minimum_amount"); $maximum_amount = $db->f("maximum_amount"); $is_exclusive = $db->f("is_exclusive"); // check cart fields and total values $min_cart_quantity = $db->f("min_cart_quantity"); $max_cart_quantity = $db->f("max_cart_quantity"); $min_cart_cost = $db->f("min_cart_cost"); $max_cart_cost = $db->f("max_cart_cost"); $cart_items_all = $db->f("cart_items_all"); $cart_items_ids = $db->f("cart_items_ids"); $cart_items_types_ids = $db->f("cart_items_types_ids"); check_cart_totals($cart_quantity, $cart_cost, $shopping_cart, $cart_items_all, $cart_items_ids, $cart_items_types_ids); if ($quantity < $min_quantity || $basic_price < $minimum_amount || $max_quantity && $max_quantity < $quantity || $maximum_amount && $maximum_amount < $basic_price || $cart_quantity < $min_cart_quantity || $cart_cost < $min_cart_cost || $max_cart_quantity && $max_cart_quantity < $cart_quantity || $max_cart_cost && $max_cart_cost < $cart_cost) { unset($shopping_cart[$cart_id]["COUPONS"][$coupon_id]); } else { // descrease product price for coupon discount $discount_amount = $coupon_info["DISCOUNT_AMOUNT"]; $discounted_price -= $discount_amount; $shopping_cart[$cart_id]["DISCOUNTED_PRICE"] = $discounted_price; if ($is_exclusive) { $exclusive_applied = true; } $coupons_total++; } } else { unset($shopping_cart[$cart_id]["COUPONS"][$coupon_id]); } } } } } // check if any order coupons should be removed // cart_quantity and cart_cost variable is used to check order coupons if (is_array($order_coupons)) { foreach ($order_coupons as $coupon_id => $coupon_info) { if ($auto_apply && $coupon_info["AUTO_APPLY"]) { // always remove auto-apply coupons unset($order_coupons[$coupon_id]); } else { $sql = " SELECT c.* FROM "; if (isset($site_id)) { $sql .= "("; } $sql .= $table_prefix . "coupons c"; if (isset($site_id)) { $sql .= " LEFT JOIN " . $table_prefix . "coupons_sites s ON s.coupon_id=c.coupon_id)"; } $sql .= " WHERE c.coupon_id=" . $db->tosql($coupon_id, INTEGER); if (isset($site_id)) { $sql .= " AND (c.sites_all=1 OR s.site_id=" . $db->tosql($site_id, INTEGER, true, false) . ")"; } else { $sql .= " AND c.sites_all=1 "; } $sql .= " ORDER BY c.apply_order "; $db->query($sql); if ($db->next_record()) { $discount_type = $db->f("discount_type"); $coupon_discount = $db->f("discount_amount"); $is_exclusive = $db->f("is_exclusive"); // check cart fields and cart totals $min_cart_quantity = $db->f("min_cart_quantity"); $max_cart_quantity = $db->f("max_cart_quantity"); $min_cart_cost = $db->f("min_cart_cost"); $max_cart_cost = $db->f("max_cart_cost"); check_cart_totals($cart_quantity, $cart_cost, $shopping_cart, 1, "", ""); if ($cart_quantity < $min_cart_quantity || $cart_cost < $min_cart_cost || $max_cart_quantity && $max_cart_quantity < $cart_quantity || $max_cart_cost && $max_cart_cost < $cart_cost) { unset($order_coupons[$coupon_id]); } else { if ($is_exclusive) { $exclusive_applied = true; } $coupons_total++; } } else { unset($order_coupons[$coupon_id]); } } } } // check if new coupons could be added $new_coupons = array(); $coupon_title = ""; if (strlen($new_coupon_code)) { $sql = " SELECT c.* FROM (" . $table_prefix . "coupons c"; if (isset($site_id)) { $sql .= " LEFT JOIN " . $table_prefix . "coupons_sites s ON s.coupon_id=c.coupon_id)"; } else { $sql .= ")"; } $sql .= " WHERE c.coupon_code=" . $db->tosql($new_coupon_code, TEXT); if (isset($site_id)) { $sql .= " AND (c.sites_all=1 OR s.site_id=" . $db->tosql($site_id, INTEGER, true, false) . ")"; } else { $sql .= " AND c.sites_all=1 "; } $sql .= " ORDER BY c.apply_order "; $db->query($sql); if ($db->next_record()) { $new_coupon_id = $db->f("coupon_id"); $start_date_db = $db->f("start_date", DATETIME); $expiry_date_db = $db->f("expiry_date", DATETIME); $coupon_title = $db->f("coupon_title"); $new_coupons[$new_coupon_id] = $db->Record; $new_coupons[$new_coupon_id]["start_date_db"] = $start_date_db; $new_coupons[$new_coupon_id]["expiry_date_db"] = $expiry_date_db; } } $discount_types = array("3,4", "1,2", "5"); // check products coupons, then order coupons and only then vouchers if ($auto_apply) { for ($dt = 0; $dt < sizeof($discount_types); $dt++) { $sql = " SELECT c.* FROM "; if (isset($site_id)) { $sql .= " ( "; } $sql .= $table_prefix . "coupons c"; if (isset($site_id)) { $sql .= " LEFT JOIN " . $table_prefix . "coupons_sites s ON s.coupon_id=c.coupon_id)"; } $sql .= " WHERE c.is_auto_apply=1 "; $sql .= " AND c.discount_type IN (" . $discount_types[$dt] . ") "; if (isset($site_id)) { $sql .= " AND (c.sites_all=1 OR s.site_id=" . $db->tosql($site_id, INTEGER, true, false) . ")"; } else { $sql .= " AND c.sites_all=1 "; } $sql .= " ORDER BY c.apply_order "; $db->query($sql); while ($db->next_record()) { $new_coupon_id = $db->f("coupon_id"); $start_date_db = $db->f("start_date", DATETIME); $expiry_date_db = $db->f("expiry_date", DATETIME); $new_coupons[$new_coupon_id] = $db->Record; $new_coupons[$new_coupon_id]["start_date_db"] = $start_date_db; $new_coupons[$new_coupon_id]["expiry_date_db"] = $expiry_date_db; } } } // check if new coupons could be added if (sizeof($new_coupons) > 0) { foreach ($new_coupons as $new_coupon_id => $data) { $coupon_error = ""; $is_active = $data["is_active"]; $new_coupon_id = $data["coupon_id"]; $coupon_auto_apply = $data["is_auto_apply"]; $coupon_code = $data["coupon_code"]; $coupon_title = $data["coupon_title"]; $discount_type = $data["discount_type"]; $discount_quantity = $data["discount_quantity"]; $coupon_discount = $data["discount_amount"]; $free_postage = $data["free_postage"]; $coupon_tax_free = $data["coupon_tax_free"]; $coupon_order_tax_free = $data["order_tax_free"]; $items_all = $data["items_all"]; $items_ids = $data["items_ids"]; $items_types_ids = $data["items_types_ids"]; $search_items_ids = explode(",", $items_ids); $search_items_types_ids = explode(",", $items_types_ids); $cart_items_all = $data["cart_items_all"]; $cart_items_ids = $data["cart_items_ids"]; $cart_items_types_ids = $data["cart_items_types_ids"]; $users_all = $data["users_all"]; $users_use_limit = $data["users_use_limit"]; $users_ids = $data["users_ids"]; $users_types_ids = $data["users_types_ids"]; $search_users_ids = explode(",", $users_ids); $search_users_types_ids = explode(",", $users_types_ids); $expiry_date = ""; $is_expired = false; $expiry_date_db = $data["expiry_date_db"]; 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 = va_timestamp(); if ($current_date_ts > $expiry_date_ts) { $is_expired = true; } } $start_date = ""; $is_upcoming = false; $start_date_db = $data["start_date_db"]; if (is_array($start_date_db)) { $start_date = va_date($date_show_format, $start_date_db); $start_date_ts = mktime(0, 0, 0, $start_date_db[MONTH], $start_date_db[DAY], $start_date_db[YEAR]); $current_date_ts = va_timestamp(); if ($current_date_ts < $start_date_ts) { $is_upcoming = true; } } // check number how many times user can use coupon $user_not_limited = false; if ($users_use_limit && $user_id) { if ($discount_type == 3 || $discount_type == 4) { $sql = " SELECT COUNT(*) FROM " . $table_prefix . "orders_items oi "; $sql .= " WHERE oi.user_id=" . $db->tosql($user_id, INTEGER); $sql .= " AND (oi.coupons_ids=" . $db->tosql($new_coupon_id, TEXT); $sql .= " OR oi.coupons_ids LIKE '" . $db->tosql($new_coupon_id, INTEGER) . ",%'"; $sql .= " OR oi.coupons_ids LIKE '%," . $db->tosql($new_coupon_id, INTEGER) . "'"; $sql .= " OR oi.coupons_ids LIKE '%," . $db->tosql($new_coupon_id, INTEGER) . ",%') "; } else { $sql = " SELECT COUNT(*) FROM (" . $table_prefix . "orders o "; $sql .= " INNER JOIN " . $table_prefix . "orders_coupons oc ON o.order_id=oc.order_id) "; $sql .= " WHERE o.user_id=" . $db->tosql($user_id, INTEGER); $sql .= " AND oc.coupon_id=" . $db->tosql($new_coupon_id, INTEGER); } $user_uses = get_db_value($sql); if ($users_use_limit > $user_uses) { $user_not_limited = true; } } // check goods cost limits $orders_period = $data["orders_period"]; $orders_interval = $data["orders_interval"]; $orders_min_goods = $data["orders_min_goods"]; $orders_max_goods = $data["orders_max_goods"]; $orders_goods_coupon = false; if ($user_id && ($orders_min_goods || $orders_max_goods)) { // check if user buy something in the past $sql = " SELECT SUM(o.goods_total) FROM (" . $table_prefix . "orders o "; $sql .= " INNER JOIN " . $table_prefix . "order_statuses os ON o.order_status=os.status_id) "; $sql .= " WHERE o.user_id=" . $db->tosql($user_id, INTEGER); $sql .= " AND os.paid_status=1 "; if ($orders_period && $orders_interval) { $cd = va_time(); if ($orders_period == 1) { $od = mktime(0, 0, 0, $cd[MONTH], $cd[DAY] - $orders_interval, $cd[YEAR]); } elseif ($orders_period == 2) { $od = mktime(0, 0, 0, $cd[MONTH], $cd[DAY] - $orders_interval * 7, $cd[YEAR]); } elseif ($orders_period == 3) { $od = mktime(0, 0, 0, $cd[MONTH] - $orders_interval, $cd[DAY], $cd[YEAR]); } else { $od = mktime(0, 0, 0, $cd[MONTH], $cd[DAY], $cd[YEAR] - $orders_interval); } $sql .= " AND order_placed_date>=" . $db->tosql($od, DATETIME); } $user_goods_cost = get_db_value($sql); if ($user_goods_cost >= $orders_min_goods && ($user_goods_cost <= $orders_max_goods || !strlen($orders_max_goods))) { $orders_goods_coupon = true; } } // check for friends coupons $friends_coupon = false; $friends_discount_type = $data["friends_discount_type"]; $friends_all = $data["friends_all"]; $friends_ids = $data["friends_ids"]; $friends_types_ids = $data["friends_types_ids"]; $friends_period = $data["friends_period"]; $friends_interval = $data["friends_interval"]; $friends_min_goods = $data["friends_min_goods"]; $friends_max_goods = $data["friends_max_goods"]; $search_friends_ids = explode(",", $friends_ids); $search_friends_types_ids = explode(",", $friends_types_ids); if ($friends_discount_type == 1) { // check if user friends buy something $user_friends_goods = 0; if ($user_id) { $sql = " SELECT SUM(o.goods_total) FROM (" . $table_prefix . "orders o "; $sql .= " INNER JOIN " . $table_prefix . "order_statuses os ON o.order_status=os.status_id) "; $sql .= " WHERE o.friend_user_id=" . $db->tosql($user_id, INTEGER); $sql .= " AND os.paid_status=1 "; if ($friends_period && $friends_interval) { $cd = va_time(); if ($friends_period == 1) { $od = mktime(0, 0, 0, $cd[MONTH], $cd[DAY] - $friends_interval, $cd[YEAR]); } elseif ($friends_period == 2) { $od = mktime(0, 0, 0, $cd[MONTH], $cd[DAY] - $friends_interval * 7, $cd[YEAR]); } elseif ($friends_period == 3) { $od = mktime(0, 0, 0, $cd[MONTH] - $friends_interval, $cd[DAY], $cd[YEAR]); } else { $od = mktime(0, 0, 0, $cd[MONTH], $cd[DAY], $cd[YEAR] - $friends_interval); } $sql .= " AND order_placed_date>=" . $db->tosql($od, DATETIME); } $user_friends_goods = get_db_value($sql); } if ($user_friends_goods >= $friends_min_goods && ($user_friends_goods <= $friends_max_goods || !strlen($friends_max_goods))) { $friends_coupon = true; } } elseif ($friends_discount_type == 2) { $friend_code = get_session("session_friend"); $friend_user_id = get_friend_info(); $friend_type_id = get_session("session_friend_type_id"); // check whose friends could use coupon if ($friends_all && $friend_user_id || $friend_user_id && in_array($friend_user_id, $search_friends_ids) || $friend_type_id && in_array($friend_type_id, $search_friends_types_ids)) { $friends_coupon = true; } } // global options $is_exclusive = $data["is_exclusive"]; $quantity_limit = $data["quantity_limit"]; $coupon_uses = $data["coupon_uses"]; // check cart total values $min_cart_quantity = $data["min_cart_quantity"]; $max_cart_quantity = $data["max_cart_quantity"]; $min_cart_cost = $data["min_cart_cost"]; $max_cart_cost = $data["max_cart_cost"]; if ($discount_type <= 2) { $cart_items_all = 1; } // for order coupons always use all cart products to calculate totals check_cart_totals($cart_quantity, $cart_cost, $shopping_cart, $cart_items_all, $cart_items_ids, $cart_items_types_ids); // product specific fields $min_quantity = $data["min_quantity"]; $max_quantity = $data["max_quantity"]; $minimum_amount = $data["minimum_amount"]; $maximum_amount = $data["maximum_amount"]; // check if coupon can be applied if (!$is_active) { $coupon_error = COUPON_NON_ACTIVE_MSG; } elseif ($quantity_limit > 0 && $coupon_uses >= $quantity_limit) { $coupon_error = COUPON_USED_MSG; } elseif ($is_expired) { $coupon_error = COUPON_EXPIRED_MSG; } elseif ($is_upcoming) { $coupon_error = COUPON_UPCOMING_MSG; } elseif (($exclusive_applied || $is_exclusive && $coupons_total > 0) && $discount_type != 5 && !is_only_gift_certificate()) { //Customization by Vital - allow gift cert. with other coupons $coupon_error = COUPON_EXCLUSIVE_MSG; } elseif ($discount_type <= 4 && $min_cart_cost > $cart_cost) { $coupon_error = str_replace("{cart_amount}", currency_format($min_cart_cost), MIN_CART_COST_ERROR); } elseif ($discount_type <= 4 && $max_cart_cost && $max_cart_cost < $cart_cost) { $coupon_error = str_replace("{cart_amount}", currency_format($max_cart_cost), MAX_CART_COST_ERROR); } elseif ($discount_type <= 4 && $min_cart_quantity > $cart_quantity) { $coupon_error = str_replace("{min_quantity}", $min_cart_quantity, COUPON_MIN_QTY_ERROR); } elseif ($discount_type <= 4 && $max_cart_quantity && $max_cart_quantity < $cart_quantity) { $coupon_error = str_replace("{max_quantity}", $max_cart_quantity, COUPON_MAX_QTY_ERROR); } elseif (!($users_all || $user_id && in_array($user_id, $search_users_ids) || $user_type_id && in_array($user_type_id, $search_users_types_ids))) { $coupon_error = COUPON_CANT_BE_USED_MSG; // coupon can't be used for current user } elseif ($users_use_limit && !$user_not_limited) { // coupon can't be used more times if ($users_use_limit == 1) { $coupon_error = COUPON_CAN_BE_USED_ONCE_MSG; } else { $coupon_error = str_replace("{use_limit}", $users_use_limit, COUPON_SAME_USE_LIMIT_MSG); } } elseif ($friends_discount_type > 0 && !$friends_coupon) { $coupon_error = COUPON_CANT_BE_USED_MSG; // coupon has friends options which can't be used for current user } elseif (($orders_min_goods || $orders_max_goods) && !$orders_goods_coupon) { $coupon_error = COUPON_CANT_BE_USED_MSG; // the sum of user purchased goods doesn't match with goods values for this coupon } // end coupons checks if (!$coupon_error) { // check products coupons $coupon_items = false; foreach ($shopping_cart as $cart_id => $item) { $item_id = $item["ITEM_ID"]; $item_type_id = $item["ITEM_TYPE_ID"]; $properties_more = $item["PROPERTIES_MORE"]; //Customization by Vital $properties_info_array = $item["PROPERTIES_INFO"]; $properties_info_array = reset($properties_info_array); $coupon_size_applies = array(); if (preg_match('#\\((.*?)\\)#', $coupon_title, $sizes)) { //get all sizes $sizes[1] = strtolower(str_replace(" ", "", $sizes[1])); //remove spaces and lowercase it $coupon_size_applies = explode(",", $sizes[1]); //place them in array } //place them in array $size_does_not_apply = false; $item_size = ""; if (count($coupon_size_applies) != 0 && strcasecmp($properties_info_array["NAME"], "size") == 0) { $sql = "SELECT property_value FROM va_items_properties_values WHERE item_property_id=" . $properties_info_array["VALUES"][0]; $db->query($sql); if ($db->next_record()) { $item_size = strtolower($db->f("property_value")); } $size_does_not_apply = !in_array($item_size, $coupon_size_applies); } //Check if the coupon applies for the item size if (strcasecmp($properties_info_array["NAME"], "size") == 0 && !$items_all) { $sql = "SELECT COUNT(*) FROM va_coupons_sizes WHERE coupon_id=" . $new_coupon_id . " AND item_id=" . $item_id . " AND item_size_id=" . $properties_info_array["VALUES"][0]; $size_is_in = get_db_value($sql); $sql = "SELECT COUNT(*) FROM va_coupons_sizes WHERE coupon_id=" . $new_coupon_id . " AND item_id=" . $item_id; $other_sizes = get_db_value($sql); $size_does_not_apply = $size_is_in == 0 && $other_sizes != 0 ? true : false; } //$coupon_error = $size_does_not_apply." ".$coupon_size_applies; //if (!$item_id || $properties_more > 0) { //original line if (!$item_id || $properties_more > 0 || $size_does_not_apply) { //EDN customization // ignore the products which has options to be added first continue; } $quantity = $item["QUANTITY"]; $basic_price = $item["BASIC_PRICE"]; $discounted_price = $item["DISCOUNTED_PRICE"]; // add a new coupon if ($discount_type == 3 || $discount_type == 4) { if ($basic_price >= $minimum_amount && $quantity >= $min_quantity && (!$maximum_amount || $basic_price <= $maximum_amount) && (!$max_quantity || $quantity <= $max_quantity) && ($items_all || in_array($item_id, $search_items_ids) || in_array($item_type_id, $search_items_types_ids))) { // add coupon to products $coupon_items = true; if ($discount_type == 3) { $discount_amount = round($basic_price / 100 * $coupon_discount, 2); } else { $discount_amount = $coupon_discount; } if ($discount_amount > $discounted_price) { $discount_amount = $discounted_price; } $shopping_cart[$cart_id]["DISCOUNTED_PRICE"] -= $discount_amount; if (!isset($shopping_cart[$cart_id]["COUPONS"][$new_coupon_id])) { // calculate number of new applied coupons $new_coupons_total++; } $shopping_cart[$cart_id]["COUPONS"][$new_coupon_id] = array("COUPON_ID" => $new_coupon_id, "EXCLUSIVE" => $is_exclusive, "DISCOUNT_QUANTITY" => $discount_quantity, "DISCOUNT_AMOUNT" => $discount_amount, "AUTO_APPLY" => $coupon_auto_apply); if ($is_exclusive) { $exclusive_applied = true; } $coupons_total++; } } } if (($discount_type == 3 || $discount_type == 4) && !$coupon_items) { $coupon_error = COUPON_PRODUCTS_MSG; } // end products checks // check order coupons if ($discount_type <= 2 || $discount_type == 5) { if (!isset($order_coupons[$new_coupon_id])) { $new_coupons_total++; } // add new coupon to system $order_coupons[$new_coupon_id] = array("COUPON_ID" => $new_coupon_id, "DISCOUNT_TYPE" => $discount_type, "EXCLUSIVE" => $is_exclusive, "COUPON_TAX_FREE" => $coupon_tax_free, "MIN_QUANTITY" => $min_cart_quantity, "MAX_QUANTITY" => $max_cart_quantity, "MIN_AMOUNT" => $min_cart_cost, "MAX_AMOUNT" => $max_cart_cost, "ORDER_TAX_FREE" => $coupon_order_tax_free, "AUTO_APPLY" => $coupon_auto_apply); if ($is_exclusive) { $exclusive_applied = true; } $coupons_total++; } // end order coupons checks } if (strtolower($coupon_code) == strtolower($new_coupon_code) && $coupon_error) { $new_coupon_error = $coupon_error; } } } // end check a new coupons and auto-applied coupons // update shopping cart and order coupons set_session("shopping_cart", $shopping_cart); set_session("session_coupons", $order_coupons); // return number of applied coupons return $new_coupons_total; }
function get_field_value($field_source) { global $db, $db_columns, $related_columns, $related_table_alias, $apply_translation, $date_formats, $date_edit_format, $datetime_edit_format; if (preg_match_all("/\\{(\\w+)\\}/i", $field_source, $matches)) { $field_value = $field_source; for ($p = 0; $p < sizeof($matches[1]); $p++) { $f_source = $matches[1][$p]; // get field type $column_type = TEXT; $column_name = ""; $column_format = ""; if (isset($db_columns[$f_source])) { $column_type = $db_columns[$f_source][1]; $column_name = $f_source; } else { if (isset($related_table_alias) && $related_table_alias && preg_match("/^" . $related_table_alias . "_/", $f_source)) { $related_column_name = preg_replace("/^" . $related_table_alias . "_/", "", $f_source); if (isset($related_columns[$related_column_name])) { $column_type = $related_columns[$related_column_name][1]; $column_name = $f_source; } } else { $date_formats_regexp = implode("|", $date_formats); if (preg_match("/" . $date_formats_regexp . "\$/", $f_source, $format_match)) { $f_source_wf = preg_replace("/_" . $format_match[0] . "\$/", "", $f_source); if (isset($db_columns[$f_source_wf]) && ($db_columns[$f_source_wf][1] == DATE || $db_columns[$f_source_wf][1] == DATETIME)) { $column_name = $f_source_wf; $column_type = $db_columns[$column_name][1]; $column_format = $format_match[0]; } } } } if ($column_name) { if ($column_type == DATE) { $f_source_value = $db->f($column_name, DATETIME); if (is_array($f_source_value)) { if ($column_format) { $f_source_value = va_date(array($column_format), $f_source_value); } else { $f_source_value = va_date($date_edit_format, $f_source_value); } } } else { if ($column_type == DATETIME) { $f_source_value = $db->f($column_name, DATETIME); if (is_array($f_source_value)) { if ($column_format) { $f_source_value = va_date(array($column_format), $f_source_value); } else { $f_source_value = va_date($datetime_edit_format, $f_source_value); } } } else { $f_source_value = $db->f($column_name); if ($apply_translation) { $f_source_value = get_translation($f_source_value); } } } $field_value = str_replace("{" . $f_source . "}", $f_source_value, $field_value); } } } else { $field_value = $field_source; } return $field_value; }
$country = get_db_value("SELECT country_name FROM " . $table_prefix . "countries WHERE country_id=" . $db->tosql($country_id, INTEGER, true, false)); $delivery_country = get_db_value("SELECT country_name FROM " . $table_prefix . "countries WHERE country_id=" . $db->tosql($delivery_country_id, INTEGER, true, false)); $t->set_var("company_select", $company_select); $t->set_var("state", $state); $t->set_var("country", $country); $t->set_var("delivery_company_select", $delivery_company_select); $t->set_var("delivery_state", $delivery_state); $t->set_var("delivery_country", $delivery_country); $t->set_var("cc_number", $cc_number); $t->set_var("cc_number_first", get_session("session_cc_number_first")); $t->set_var("cc_number_last", get_session("session_cc_number_last")); $t->set_var("cc_security_code", $cc_security_code); $cc_type = get_array_value($r->get_value("cc_type"), $credit_cards); $t->set_var("cc_type", $cc_type); $cc_start = va_date(array("MM", " / ", "YYYY"), $r->get_value("cc_start_date")); $cc_expiry = va_date(array("MM", " / ", "YYYY"), $r->get_value("cc_expiry_date")); $t->set_var("cc_start_date", $cc_start); $t->set_var("cc_expiry_date", $cc_expiry); $t->set_block("payment_info", $payment_info); $t->parse("payment_info", false); } if ($cc_info["admin_notification"]) { $admin_subject = get_setting_value($cc_info, "admin_subject", ""); $admin_subject = get_translation($admin_subject); $admin_message = get_currency_message(get_translation($admin_message), $currency); // PGP enable $admin_notification_pgp = get_setting_value($cc_info, "admin_notification_pgp", 0); $t->set_block("admin_subject", $admin_subject); $t->set_block("admin_message", $admin_message); $mail_to = get_setting_value($cc_info, "admin_email", $settings["admin_email"]); $mail_to = str_replace(";", ",", $mail_to);
} else { $subscription_periods = array(1 => DAYS_QTY_MSG, 2 => WEEKS_QTY_MSG, 3 => MONTHS_QTY_MSG, 4 => YEARS_QTY_MSG); $period_message = $subscription_periods[$subscription_period]; $period_message = str_replace("{quantity}", $subscription_interval, $period_message); } $t->set_var("subscription_id_value", $type_subscription_id); $t->set_var("subscription_id_checked", $subscription_id_checked); $t->set_var("subscription_name", $subscription_name); $t->set_var("subscription_fee", currency_format($subscription_fee)); $t->set_var("subscription_period", $period_message); $t->parse("subscription_id", true); } if (strlen($user_id)) { $expiry_date = $r->get_value("expiry_date"); if (is_array($expiry_date)) { $t->set_var("expiry_date", va_date($date_show_format, $expiry_date)); $t->parse("expiry_date_info", false); } if ($r->get_value("subscription_id")) { $t->parse("current_subscription", false); } if (is_array($expiry_date) || $r->get_value("subscription_id")) { $t->parse("subscription_title", false); } } else { $t->parse("subscription_title", false); $t->parse("subscription_options", false); } } if (strlen($user_id) && strlen(trim(get_setting_value($user_profile, "intro_text_registered")))) { $t->set_var("intro_text", get_translation($user_profile["intro_text_registered"]));
$order_currency["point"] = $db->f("decimal_point"); $order_currency["separator"] = $db->f("thousands_separator"); $vc = md5($order_id . $placed_date[3] . $placed_date[4] . $placed_date[5]); if ($orders_currency != 1) { $order_currency["left"] = $currency["left"]; $order_currency["right"] = $currency["right"]; $order_currency["decimals"] = $currency["decimals"]; $order_currency["point"] = $currency["point"]; $order_currency["separator"] = $currency["separator"]; if (strtolower($currency["code"]) != strtolower($order_currency_code)) { $order_currency["rate"] = $currency["rate"]; } } $t->set_var("order_id", $order_id); $t->set_var("vc", $vc); $t->set_var("order_placed_date", va_date($datetime_show_format, $placed_date)); $t->set_var("order_status", get_translation($db->f("status_name"))); $tracking_number = $db->f("shipping_tracking_id"); if (strlen($tracking_number) > 3 && strpos($db->f("shipping_type_desc"), "USPS") !== false) { $tracking = '<a class="tracking" href="https://tools.usps.com/go/TrackConfirmAction.action?tLabels=' . $tracking_number . '" target="_blank">' . $tracking_number . '</a>'; } else { $tracking = $tracking_number; } $t->set_var("tracking", $tracking); $t->set_var("order_total", currency_format($order_total, $order_currency)); if ($is_placed || $paid_status) { $t->set_var("pay_link", ""); } else { $t->sparse("pay_link", false); } if ($user_invoice_activation) {
if ($orders_currency != 1) { $order_currency["left"] = $currency["left"]; $order_currency["right"] = $currency["right"]; $order_currency["decimals"] = $currency["decimals"]; $order_currency["point"] = $currency["point"]; $order_currency["separator"] = $currency["separator"]; if (strtolower($currency["code"]) != strtolower($order_currency_code)) { $order_currency["rate"] = $currency["rate"]; } } $user_name = $db->f("name"); if (!strlen($user_name)) { $user_name = $db->f("first_name") . " " . $db->f("last_name"); } $order_placed_date = $db->f("order_placed_date", DATETIME); $order_placed_date = va_date($datetime_show_format, $order_placed_date); if (get_setting_value($order_info, "show_delivery_country_id", 0) == 1) { $country_id = $db->f("delivery_country_id"); $state_id = $db->f("delivery_state_id"); } elseif (get_setting_value($order_info, "show_country_id", 0) == 1) { $country_id = $db->f("country_id"); $state_id = $db->f("state_id"); } else { $country_id = $settings["country_id"]; $state_id = get_setting_value($settings, "state_id", ""); } $status_name = get_translation($db->f("status_name")); $admin_order_url = $admin_order->get_url(); $remote_address = $db->f("remote_address"); $site_name = $db->f("site_name"); $orders[] = array($order_id, $order_total, $user_name, $order_placed_date, $status_name, $country_id, $state_id, $admin_order_url, $remote_address, $order_currency, $site_name);
$address_to_email = '<div style="border: 1px solid #E9E9E9; width: 40%; margin: 1px;"><b style="float: left; background: #E9E9E9; padding: 4px 0; text-align: center; width: 100%;">Shipping Address</b><div style="clear: both; padding: 4px;">' . $shipping_first_name . ' ' . $shipping_last_name . '<br />' . $shipping_address . '<br />' . $shipping_city_country . '</div></div>'; //END customization $t->set_var("goods_total", currency_format($goods_total)); $t->set_var("goods_total_value", number_format($goods_total, 2, ".", "")); $t->set_var("total_discount", currency_format($total_discount)); $t->set_var("goods_with_discount", currency_format($goods_with_discount)); $t->set_var("shipping_cost", currency_format($shipping_cost)); $t->set_var("tax_percent", number_format($tax_percent, 2) . "%"); $t->set_var("tax_total", currency_format($tax_total)); $t->set_var("tax_cost", currency_format($tax_total)); $t->set_var("processing_fee", currency_format($processing_fee)); $t->set_var("order_total", currency_format($order_total)); $t->set_var("order_total_value", number_format($order_total, 2, ".", "")); $t->set_var("order_placed_date", va_date($datetime_show_format, $order_placed_date)); $t->set_var("cc_start_date", va_date(array("MM", " / ", "YYYY"), $cc_start_date)); $t->set_var("cc_expiry_date", va_date(array("MM", " / ", "YYYY"), $cc_expiry_date)); $t->set_var("cc_type", $variables["cc_type"]); $t->set_var("company_select", $variables["company_select"]); $t->set_var("state", $variables["state"]); $t->set_var("country", $variables["country"]); $t->set_var("delivery_company_select", $variables["delivery_company_select"]); $t->set_var("delivery_state", $variables["delivery_state"]); $t->set_var("delivery_country", $variables["delivery_country"]); $t->set_var("status_name", $order_status_name); $t->set_var("order_status_name", $order_status_name); $t->set_var("status_final_message", $final_message); } $is_failed = false; $is_pending = false; $is_success = false; if (strlen($error_message)) {
$delete_url = new VA_URL("user_wishlist.php", false); $delete_url->add_parameter("cart_item_id", DB, "cart_item_id"); $delete_url->add_parameter("operation", CONSTANT, "delete"); do { $cart_item_id = $db->f("cart_item_id"); $item_id = $db->f("item_id"); $price = $db->f("price"); $quantity = $db->f("quantity"); $quantity_bought = $db->f("quantity_bought"); $item_name = $db->f("item_name"); $type_name = $db->f("type_name"); $friendly_url = $db->f("friendly_url"); $date_added = $db->f("date_added", DATETIME); $a_title = get_translation($db->f("a_title")); $t->set_var("cart_item_id", $db->f("cart_item_id")); $t->set_var("date_added", va_date($datetime_show_format, $date_added)); $t->set_var("item_id", get_translation($item_id)); $t->set_var("a_title", htmlspecialchars($a_title)); $t->set_var("item_name", get_translation($db->f("item_name"))); $t->set_var("type_name", get_translation($db->f("type_name"))); $t->set_var("price", currency_format($price)); $t->set_var("quantity", $quantity); $t->set_var("quantity_bought", $quantity_bought); $t->set_var("cart_url", $cart_url->get_url()); $t->set_var("delete_url", $delete_url->get_url()); if ($friendly_urls && strlen($friendly_url)) { $t->set_var("product_details_url", htmlspecialchars($friendly_url . $friendly_extension)); } else { $product_link = get_custom_friendly_url("product_details.php") . "?item_id=" . $item_id; $t->set_var("product_details_url", htmlspecialchars($product_link)); }
function xml_add_url($loc, $lastmod = "", $changefreq = "", $priority = "") { global $total_count, $count; global $sitemap_count; global $sitemap_started; global $site_map_folder; $count++; $xml = ""; $filename = $site_map_folder . "sitemap" . $sitemap_count . ".xml"; if (!$sitemap_started) { if (file_exists($filename) && is_writable($filename)) { $fp = @fopen($filename, "w"); @fwrite($fp, ''); @fclose($fp); } $sitemap_started = true; $xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"" . chr(63) . ">\n"; $xml .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; } $xml .= "\t<url>\n"; $xml .= "\t\t<loc>" . htmlspecialchars($loc, ENT_QUOTES, "UTF-8") . "</loc>\n"; if (!strlen($lastmod)) { $datetime_loc_format = array("YYYY", "-", "MM", "-", "DD", "T", "HH", ":", "mm", ":", "ss", "+00:00"); $lastmod = va_date($datetime_loc_format); } if (strlen($lastmod)) { $xml .= "\t\t<lastmod>" . $lastmod . "</lastmod>\n"; } if (strlen($changefreq)) { $xml .= "\t\t<changefreq>" . $changefreq . "</changefreq>\n"; } if (strlen($priority)) { $xml .= "\t\t<priority>" . $priority . "</priority>\n"; } $xml .= "\t</url>\n"; if (file_exists($filename)) { clearstatcache(); $size = filesize($filename); if ($size > 10000000 || $count % 50000 == 0) { // due to Google Sitemap protocol limitations $sitemap_started = false; $xml .= "</urlset>"; $total_count = $total_count + $count; $count = 0; $sitemap_count++; } } $fp = @fopen($filename, "a"); @fwrite($fp, $xml); @fclose($fp); }
$t->set_var("details_url", $details_remote_url); } // get fields values $article_date_string = ""; $date_end_string = ""; if (strpos($list_fields, ",article_date,")) { $article_date = $db->f("article_date", DATETIME); $article_date_string = va_date($datetime_show_format, $article_date); $t->set_var("article_date", $article_date_string); $t->global_parse("article_date_block", false, false, true); } else { $t->set_var("article_date_block", ""); } if (strpos($list_fields, ",date_end,")) { $date_end = $db->f("date_end", DATETIME); $date_end_string = va_date($datetime_show_format, $date_end); $t->set_var("date_end", $date_end_string); $t->global_parse("date_end_block", false, false, true); } else { $t->set_var("date_end_block", ""); } if (strlen($article_date_string) || strlen($date_end_string)) { $t->global_parse("date_block", false, false, true); } for ($i = 0; $i < sizeof($article_fields); $i++) { $field_name = $article_fields[$i]; $fields[$field_name] = get_currency_message(get_translation($db->f($field_name)), $currency); if (strlen($fields[$field_name]) && strpos($list_fields, "," . $field_name . ",")) { $t->set_var($field_name, $fields[$field_name]); $t->global_parse($field_name . "_block", false, false, true); } else {