$sql_params["brackets"] = "(";
$sql_params["join"] = $related_type_join;
$sql_params["where"] = $related_type_where;
$items_ids = VA_Products::find_all_ids($sql_params, VIEW_CATEGORIES_ITEMS_PERM);
if (!$items_ids) {
    return;
}
$total_records = count($items_ids);
$allowed_items_ids = VA_Products::find_all_ids("i.item_id IN (" . $db->tosql($items_ids, INTEGERS_LIST) . ")", VIEW_ITEMS_PERM);
$pages_number = 5;
$n = new VA_Navigator($settings["templates_dir"], "navigator.html", $main_page);
$page_number = $n->set_navigator("ri_navigator", "ri_page", SIMPLE, $pages_number, $records_per_page, $total_records, false, $pass_parameters, array(), "#related-products");
$db->RecordsPerPage = $records_per_page;
$db->PageNumber = $page_number;
# ******************************  new  MS
$allowed_items_ids = VA_Products::find_all_ids("i.item_id IN (" . $db->tosql($items_ids, INTEGERS_LIST) . ")", VIEW_ITEMS_PERM);
//Customization by Vital - second image mouseover
$mouseover_images = array();
$sql = " SELECT item_id, image_small FROM " . $table_prefix . "items_images WHERE item_id IN (" . $db->tosql($allowed_items_ids, INTEGERS_LIST) . ") ORDER BY item_id, image_title ";
$db->query($sql);
while ($db->next_record()) {
    $mouseover_images[$db->f("item_id")][] = $db->f("image_small");
}
# *****************************  new MS
$sql = " SELECT   i.item_id, i.item_type_id, i.item_name, i.a_title, i.friendly_url, i.short_description, i.small_image, i.small_image_alt, ";
$sql .= " i.buying_price, i." . $price_field . ", i." . $properties_field . ", i." . $sales_field . ", i.is_sales, i.tax_id, i.tax_free, ";
$sql .= " i.buying_price, i." . $price_field . ", i." . $properties_field . ", i." . $sales_field . ", i.is_sales, i.tax_id, i.tax_free, ";
$sql .= " i.use_stock_level, i.stock_level, st_in.shipping_time_desc AS in_stock_message, st_out.shipping_time_desc AS out_stock_message ";
$sql .= $new_product_sql;
$sql .= " FROM (((";
$sql .= $table_prefix . "items i ";
示例#2
0
function add_root_categories_to_site_map_tree($type = "products", $first_title = "", $first_url = "", $show_categories = 0, $show_items = 0, $show_subitems = 0)
{
    global $db, $table_prefix, $settings;
    global $site_map_tree, $total_records;
    if (!$show_categories && !$show_items) {
        return;
    }
    $site_map_tree[$type] = array(SITEMAP_TITLE_INDEX => $first_title, SITEMAP_URL_INDEX => $first_url);
    $friendly_urls = get_setting_value($settings, "friendly_urls");
    $friendly_extension = get_setting_value($settings, "friendly_extension");
    $items_categories_ids = array();
    $article_top_category_id = 0;
    if ($show_categories) {
        if ($type == "products") {
            $found_categories = VA_Categories::find_all("c.category_id", array("c.category_name", "c.parent_category_id", "c.friendly_url"), array("order" => " ORDER BY c.category_order, c.category_name"));
            $category_url_prefix = "products.php?category_id=";
        } elseif (strpos($type, "articles_") === 0) {
            $article_top_category_id = (int) substr($type, 9);
            $found_categories = VA_Articles_Categories::find_all("c.category_id", array("c.category_name", "c.parent_category_id", "c.friendly_url"), array("order" => " ORDER BY c.category_order, c.category_name", "where" => " c.category_path LIKE '%" . $article_top_category_id . ",%' "));
            $category_url_prefix = "articles.php?category_id=";
        } elseif ($type == "forums") {
            $found_categories = VA_Forum_Categories::find_all("c.category_id", array("c.category_name", "c.friendly_url"), array("order" => " ORDER BY c.category_order, c.category_name"));
            $category_url_prefix = "forums.php?category_id=";
        } elseif ($type == "ads") {
            $found_categories = VA_Ads_Categories::find_all("c.category_id", array("c.category_name", "c.parent_category_id", "c.friendly_url"), array("order" => " ORDER BY c.category_order, c.category_name"));
            $category_url_prefix = "ads.php?category_id=";
        } elseif ($type == "manuals") {
            $found_categories = VA_Manuals_Categories::find_all("c.category_id", array("c.category_name", "c.friendly_url"), array("order" => " ORDER BY c.category_order, c.category_name"));
            $category_url_prefix = "manuals.php?category_id=";
        }
        if ($found_categories) {
            foreach ($found_categories as $cur_category_id => $cur_category) {
                $items_categories_ids[] = $cur_category_id;
                $parent_category_id = isset($cur_category["c.parent_category_id"]) ? $cur_category["c.parent_category_id"] : 0;
                $category_name = $cur_category["c.category_name"];
                if ($cur_category["c.friendly_url"] && $friendly_urls) {
                    $category_url = $cur_category["c.friendly_url"] . $friendly_extension;
                } else {
                    $category_url = $category_url_prefix . $cur_category_id;
                }
                if ($parent_category_id <= 0 || $parent_category_id == $article_top_category_id) {
                    $site_map_tree[$type][SITEMAP_SUBS_INDEX][] = $cur_category_id;
                } else {
                    $site_map_tree[$type][$parent_category_id][SITEMAP_SUBS_INDEX][] = $cur_category_id;
                }
                $site_map_tree[$type][$cur_category_id][SITEMAP_TITLE_INDEX] = $category_name;
                $site_map_tree[$type][$cur_category_id][SITEMAP_URL_INDEX] = $category_url;
            }
        }
    }
    $items_ids = array();
    if ($show_items) {
        if ($type == "products") {
            $item_url_prefix = "product_details.php?item_id=";
            $friendly_url_field = "i.friendly_url";
            $item_id = "i.item_id";
            $item_name_field = "i.item_name";
            $category_id_field = "ic.category_id";
        } elseif (strpos($type, "articles_") === 0) {
            $article_top_category_id = (int) substr($type, 9);
            $item_url_prefix = "article.php?article_id=";
            $friendly_url_field = "a.friendly_url";
            $item_id = "a.article_id";
            $item_name_field = "a.article_title";
            $category_id_field = "ac.category_id";
        } elseif ($type == "forums") {
            $item_url_prefix = "forum.php?forum_id=";
            $friendly_url_field = "fl.friendly_url";
            $item_id = "fl.forum_id";
            $item_name_field = "fl.forum_name";
            $category_id_field = "fl.category_id";
        } elseif ($type == "ads") {
            $item_url_prefix = "ads_details.php?item_id=";
            $friendly_url_field = "i.friendly_url";
            $item_id = "i.item_id";
            $item_name_field = "i.item_title";
            $category_id_field = "c.category_id";
        } elseif ($type == "manuals") {
            $item_url_prefix = "manuals_articles.php?manual_id=";
            $friendly_url_field = "ml.friendly_url";
            $item_id = "ml.manual_id";
            $item_name_field = "ml.manual_title";
            $category_id_field = "c.category_id";
        }
        $found_items = array();
        if ($show_categories && $items_categories_ids) {
            if ($type == "forums") {
                $found_items = VA_Forums::find_all("", array("fl.forum_id", "fl.forum_name", "fl.friendly_url", "fl.category_id"), array("where" => " fl.category_id IN (" . $db->tosql($items_categories_ids, INTEGERS_LIST) . ")", "order" => " ORDER BY fl.forum_order, fl.forum_name"));
            } elseif ($type == "manuals") {
                $found_items = VA_Manuals::find_all("", array("ml.manual_id", "ml.manual_title", "ml.friendly_url", "c.category_id"), array("where" => " c.category_id IN (" . $db->tosql($items_categories_ids, INTEGERS_LIST) . ")", "order" => " ORDER BY ml.manual_order, ml.manual_title"));
            } else {
                array_unshift($items_categories_ids, 0);
                foreach ($items_categories_ids as $items_categories_id) {
                    if ($type == "products") {
                        $sql = " SELECT * FROM " . $table_prefix . "categories ";
                        $sql .= " WHERE category_id=" . $db->tosql($items_categories_id, INTEGER);
                        $db->query($sql);
                        if ($db->next_record()) {
                            $show_sub_products = $db->f("show_sub_products");
                            $category_path = $db->f("category_path") . $items_categories_id . ",";
                        } else {
                            $show_sub_products = false;
                            $category_path = "";
                        }
                        $sql_params = array();
                        $sql_fields = array();
                        $sql_params["brackets"] = "((";
                        $sql_params["join"] = " LEFT JOIN " . $table_prefix . "items_categories ic ON i.item_id=ic.item_id) ";
                        if ($show_sub_products && $items_categories_id != 0) {
                            $sql_params["join"] .= "LEFT JOIN " . $table_prefix . "categories c ON c.category_id = ic.category_id)";
                            $sql_params["where"] = " (ic.category_id = " . $db->tosql($items_categories_id, INTEGER);
                            $sql_params["where"] .= " OR c.category_path LIKE '" . $db->tosql($category_path, TEXT, false) . "%')";
                            $sql_fields = array("i.item_id", "i.item_name", "i.friendly_url", $db->tosql($items_categories_id, INTEGER) . " 'ic.category_id'");
                        } else {
                            $sql_params["join"] .= ")";
                            $sql_params["where"] = " ic.category_id = " . $db->tosql($items_categories_id, INTEGER);
                            $sql_fields = array("i.item_id", "i.item_name", "i.friendly_url", "ic.category_id");
                        }
                        $sql_params["order"] = " ORDER BY i.item_order, i.item_name";
                        $found_items_tmp = VA_Products::find_all("", array("i.item_id", "i.item_name", "i.friendly_url", "ic.category_id"), $sql_params);
                        if ($show_sub_products && $items_categories_id != 0) {
                            foreach ($found_items_tmp as $index_tmp => $items_tmp) {
                                $found_items_tmp[$index_tmp]["ic.category_id"] = $db->tosql($items_categories_id, INTEGER);
                            }
                        }
                        $found_items = array_merge($found_items, $found_items_tmp);
                    } elseif (strpos($type, "articles_") === 0) {
                        $found_items_tmp = VA_Articles::find_all("", array("a.article_id", "a.article_title", "a.friendly_url", "ac.category_id"), array("where" => " ac.category_id=" . $db->tosql($items_categories_id, INTEGER), "order" => " ORDER BY a.article_order, a.article_id"));
                        $found_items = array_merge($found_items, $found_items_tmp);
                    } elseif ($type == "ads") {
                        $found_items_tmp = VA_Ads::find_all("", array("i.item_id", "i.item_title", "i.friendly_url", "c.category_id"), array("where" => " c.category_id=" . $db->tosql($items_categories_id, INTEGER), "order" => " ORDER BY i.item_order, i.item_title"));
                        $found_items = array_merge($found_items, $found_items_tmp);
                    }
                }
            }
        } else {
            // dont show categories - only items
            if ($type == "products") {
                $found_items = VA_Products::find_all("", array("i.item_id", "i.item_name", "i.friendly_url"), array("order" => " ORDER BY i.item_order, i.item_name"));
            } elseif (strpos($type, "articles_") === 0) {
                $found_items = VA_Articles::find_all("", array("a.article_id", "a.article_title", "a.friendly_url"), array("where" => " a.status_id IN ( 1, 2 ) AND ( c.category_path LIKE '0," . $db->tosql($article_top_category_id, INTEGER) . ",%' OR c.category_id=" . $db->tosql($article_top_category_id, INTEGER) . " )", "order" => " ORDER BY a.article_order, a.article_id"));
            } elseif ($type == "forums") {
                $found_items = VA_Forums::find_all("", array("fl.forum_id", "fl.forum_name", "fl.friendly_url"), array("order" => " ORDER BY fl.forum_order, fl.forum_name"));
            } elseif ($type == "ads") {
                $found_items = VA_Ads::find_all("", array("i.item_id", "i.item_title", "i.friendly_url"), array("order" => " ORDER BY i.item_order, i.item_title"));
            } elseif ($type == "manuals") {
                $found_items = VA_Manuals::find_all("", array("ml.manual_id", "ml.manual_title", "ml.friendly_url"), array("order" => " ORDER BY ml.manual_order, ml.manual_title"));
            }
        }
        if ($found_items) {
            $parent_items = array();
            foreach ($found_items as $cur_item) {
                $cur_item_id = isset($cur_item[$item_id]) ? $cur_item[$item_id] : 0;
                $parent_category_id = isset($cur_item[$category_id_field]) ? $cur_item[$category_id_field] : 0;
                if ($cur_item[$friendly_url_field] && $friendly_urls) {
                    $item_url = $cur_item[$friendly_url_field] . $friendly_extension;
                } else {
                    $item_url = $item_url_prefix . $cur_item_id;
                    if ($parent_category_id) {
                        $item_url .= "&category_id=" . $parent_category_id;
                    }
                }
                $items_ids[] = $cur_item_id;
                $cur_item_id = "i_" . $cur_item_id;
                if ($parent_category_id > 0) {
                    $site_map_tree[$type][$parent_category_id][SITEMAP_SUBS_INDEX][] = $cur_item_id;
                } else {
                    $parent_items[] = $cur_item_id;
                    //						$site_map_tree[$type][SITEMAP_SUBS_INDEX][] = $cur_item_id;
                }
                $site_map_tree[$type][$cur_item_id][SITEMAP_TITLE_INDEX] = $cur_item[$item_name_field];
                $site_map_tree[$type][$cur_item_id][SITEMAP_URL_INDEX] = $item_url;
            }
            if (sizeof($parent_items)) {
                if (isset($site_map_tree[$type][SITEMAP_SUBS_INDEX])) {
                    $subs = array_merge($parent_items, $site_map_tree[$type][SITEMAP_SUBS_INDEX]);
                } else {
                    $subs = $parent_items;
                }
                $site_map_tree[$type][SITEMAP_SUBS_INDEX] = $subs;
            }
        }
    }
    if ($show_subitems && (!$show_items || $items_ids)) {
        if ($type == "manuals") {
            $sql_manual = " SELECT article_id, article_title, parent_article_id, friendly_url, manual_id";
            $sql_manual .= " FROM " . $table_prefix . "manuals_articles ";
            $sql_manual .= " WHERE allowed_view=1";
            if ($show_items) {
                $sql_manual .= " AND manual_id IN (" . $db->tosql($items_ids, INTEGERS_LIST) . ")";
            }
            $sql_manual .= " ORDER BY article_order, article_title ";
            $db->query($sql_manual);
            while ($db->next_record()) {
                $article_id = $db->f("article_id");
                $manual_id = $show_items ? $db->f("manual_id") : 0;
                $parent_article_id = $db->f("parent_article_id");
                $friendly_url = $db->f("friendly_url");
                if ($friendly_url && $friendly_urls) {
                    $item_url = $friendly_url . $friendly_extension;
                } else {
                    $item_url = "manuals_article_details.php?article_id=" . $article_id;
                }
                $cur_item_id = "a_" . $article_id;
                if ($parent_article_id > 0) {
                    $site_map_tree[$type]["a_" . $parent_article_id][SITEMAP_SUBS_INDEX][] = $cur_item_id;
                } elseif ($manual_id > 0) {
                    $site_map_tree[$type]["i_" . $manual_id][SITEMAP_SUBS_INDEX][] = $cur_item_id;
                } else {
                    $site_map_tree[$type][SITEMAP_SUBS_INDEX][] = $cur_item_id;
                }
                $site_map_tree[$type][$cur_item_id][SITEMAP_TITLE_INDEX] = $db->f("article_title");
                $site_map_tree[$type][$cur_item_id][SITEMAP_URL_INDEX] = $item_url;
            }
        }
    }
    $ic = count($site_map_tree[$type]);
    if ($ic > 3) {
        $total_records += $ic - 2;
    } else {
        //unset($site_map_tree[$type]);
    }
}
$user_type_id = get_setting_value($user_info, "user_type_id", "");
$friendly_urls = get_setting_value($settings, "friendly_urls", 0);
$friendly_extension = get_setting_value($settings, "friendly_extension", "");
$html_template = get_setting_value($block, "html_template", "block_products_breadcrumb.html");
$t->set_file("block_body", $html_template);
$manf = get_param("manf");
$user = get_param("user");
$item_id = get_param("item_id");
$category_id = get_param("category_id");
$search_category_id = get_param("search_category_id");
$breadcrumbs_tree_array = array();
if (strlen($search_category_id)) {
    $category_id = $search_category_id;
}
if (!strlen($category_id) && strlen($item_id)) {
    $category_id = VA_Products::get_category_id($item_id);
    //Customization by Vital
    $session_category_id = get_session("category_id");
    if ($session_category_id && get_db_value("SELECT COUNT(*) FROM " . $table_prefix . "items_categories where item_id=" . $db->tosql($item_id, INTEGER) . " AND category_id=" . $session_category_id)) {
        $category_id = $session_category_id;
    }
    //END customization
}
$t->set_var("index_href", get_custom_friendly_url("index.php"));
if ($category_id) {
    $current_id = $category_id;
    $sql = " SELECT c.category_id, c.category_name, c.friendly_url, c.parent_category_id  FROM ";
    if (isset($site_id)) {
        $sql .= "(";
    }
    $sql .= $table_prefix . "categories c";
示例#4
0
function add_to_cart($sc_item_id, $sc_price, $sc_quantity, $type, $cart, &$new_cart_id, &$second_page_options, &$sc_errors, &$sc_message, $cart_item_id = "", $sc_item_name = "")
{
    global $db, $table_prefix, $site_id, $settings, $eol, $currency;
    $sc_errors = "";
    $sc_message = "";
    $item_added = false;
    $shopping_cart = get_session("shopping_cart");
    if (!is_array($shopping_cart)) {
        $shopping_cart = array();
    }
    $discount_type = get_session("session_discount_type");
    $discount_amount = get_session("session_discount_amount");
    $user_type_id = get_session("session_user_type_id");
    $price_type = get_session("session_price_type");
    if ($price_type == 1) {
        $price_field = "trade_price";
        $sales_field = "trade_sales";
        $additional_price_field = "trade_additional_price";
    } else {
        $price_field = "price";
        $sales_field = "sales_price";
        $additional_price_field = "additional_price";
    }
    $is_error = false;
    if (VA_Products::check_permissions($sc_item_id, VIEW_ITEMS_PERM)) {
        $sql = " SELECT item_type_id,item_name," . $price_field . ",is_price_edit,is_sales," . $sales_field . ",buying_price,";
        $sql .= " tax_id,tax_free,stock_level,";
        $sql .= " use_stock_level,hide_out_of_stock,disable_out_of_stock,min_quantity,max_quantity,quantity_increment ";
        $sql .= " FROM " . $table_prefix . "items ";
        $sql .= " WHERE item_id=" . $db->tosql($sc_item_id, INTEGER);
        $db->query($sql);
        if ($db->next_record()) {
            $item_type_id = $db->f("item_type_id");
            $item_name = $db->f("item_name");
            $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");
            $min_quantity = $db->f("min_quantity");
            if (!strlen($sc_quantity) && $min_quantity) {
                $sc_quantity = $min_quantity;
            }
            if ($sc_quantity < 1) {
                $sc_quantity = 1;
            }
            $max_quantity = $db->f("max_quantity");
            $quantity_increment = $db->f("quantity_increment");
            $buying_price = $db->f("buying_price");
            $tax_id = $db->f("tax_id");
            $tax_free = $db->f("tax_free");
            $is_price_edit = $db->f("is_price_edit");
            if ($is_price_edit) {
                $price = $sc_price;
            } else {
                $price = calculate_price($db->f($price_field), $db->f("is_sales"), $db->f($sales_field));
            }
            $properties_buying = 0;
            $properties_discount = 0;
            $discount_applicable = 1;
        } else {
            $is_error = true;
        }
    } else {
        $is_error = true;
    }
    if ($is_error) {
        // item doesn't exists or no longer available
        if ($type == "db") {
            $item = array("ITEM_ID" => intval($sc_item_id), "ITEM_TYPE_ID" => 0, "ITEM_NAME" => $sc_item_name, "ERROR" => PROD_NOT_AVAILABLE_ERROR, "PROPERTIES" => "", "PROPERTIES_PRICE" => 0, "PROPERTIES_PERCENTAGE" => 0, "PROPERTIES_BUYING" => 0, "PROPERTIES_DISCOUNT" => 0, "PROPERTIES_MORE" => 0, "COMPONENTS" => "", "QUANTITY" => $sc_quantity, "TAX_ID" => 0, "TAX_FREE" => 0, "DISCOUNT" => 0, "BUYING_PRICE" => 0, "PRICE_EDIT" => 0, "PRICE" => $sc_price);
            //-- add to cart with error
            $shopping_cart[] = $item;
            end($shopping_cart);
            $new_cart_id = key($shopping_cart);
            set_session("shopping_cart", $shopping_cart);
            return true;
        } else {
            return false;
        }
    }
    // calculate summary stock levels for products and options available in the cart
    $stock_levels = array();
    foreach ($shopping_cart as $cart_id => $cart_info) {
        $item_id = $cart_info["ITEM_ID"];
        $item_quantity = $cart_info["QUANTITY"];
        $item_properties = $cart_info["PROPERTIES"];
        $item_more_properties = $cart_info["PROPERTIES_MORE"];
        if (!$item_more_properties) {
            if (isset($stock_levels[$item_id])) {
                $stock_levels[$item_id] += $item_quantity;
            } else {
                $stock_levels[$item_id] = $item_quantity;
            }
            $item_components = $cart_info["COMPONENTS"];
            if (is_array($item_components) && sizeof($item_components) > 1) {
                foreach ($item_components as $property_id => $component_values) {
                    foreach ($component_values as $property_item_id => $component) {
                        $sub_item_id = $component["sub_item_id"];
                        $sub_quantity = $component["quantity"];
                        if ($sub_quantity < 1) {
                            $sub_quantity = 1;
                        }
                        if (isset($stock_levels[$sub_item_id])) {
                            $stock_levels[$sub_item_id] += $item_quantity * $sub_quantity;
                        } else {
                            $stock_levels[$sub_item_id] = $item_quantity * $sub_quantity;
                        }
                    }
                }
            }
        }
    }
    // check stock level for parent product
    if (isset($stock_levels[$sc_item_id])) {
        $total_quantity = $stock_levels[$sc_item_id] + $sc_quantity;
    } else {
        $total_quantity = $sc_quantity;
    }
    /*
    			//PRODUCT_MIN_LIMIT_MSG
    			$min_quantity = $db->f("min_quantity");
    			$max_quantity = $db->f("max_quantity");
    			$quantity_increment = $db->f("quantity_increment");
    */
    // check stock levels only if product added to the shopping cart
    if ($cart == "ADD" && $use_stock_level && $stock_level < $total_quantity && ($hide_out_of_stock || $disable_out_of_stock)) {
        if ($stock_level > 0) {
            $limit_error = str_replace("{limit_quantity}", $stock_level, PRODUCT_LIMIT_MSG);
            $limit_error = str_replace("{product_name}", get_translation($item_name), $limit_error);
            $sc_errors .= $limit_error . "<br>";
        } else {
            $sc_errors .= PRODUCT_OUT_STOCK_MSG . "<br>";
        }
        if ($type != "db") {
            return false;
        }
    } elseif ($cart == "ADD" && $min_quantity && $total_quantity < $min_quantity) {
        $limit_error = str_replace("{limit_quantity}", $min_quantity, PRODUCT_MIN_LIMIT_MSG);
        $limit_error = str_replace("{product_name}", get_translation($item_name), $limit_error);
        $sc_errors .= $limit_error . "<br>";
        if ($type != "db") {
            return false;
        }
    } elseif ($cart == "ADD" && $max_quantity && $total_quantity > $max_quantity) {
        $limit_error = str_replace("{limit_quantity}", $max_quantity, PRODUCT_LIMIT_MSG);
        $limit_error = str_replace("{product_name}", get_translation($item_name), $limit_error);
        $sc_errors .= $limit_error . "<br>";
        if ($type != "db") {
            return false;
        }
    } elseif ($cart == "ADD" && $quantity_increment && ($sc_quantity - $min_quantity) % $quantity_increment != 0) {
        $quantity_error = str_replace("{quantity}", $sc_quantity, PRODUCT_QUANTITY_ERROR);
        $quantity_error = str_replace("{product_name}", get_translation($item_name), $quantity_error);
        $sc_errors .= $quantity_error . "<br>";
        $quantities_list = "";
        $quantities_index = 0;
        $quantity_list = $min_quantity ? $min_quantity : $quantity_increment;
        while ((!$max_quantity || $quantity_list < $max_quantity) && $quantities_index < 5) {
            $quantities_index++;
            $quantities_list .= $quantity_list . ", ";
            $quantity_list += $quantity_increment;
        }
        if (!$max_quantity || $quantity_list < $max_quantity) {
            $quantities_list .= "...";
        }
        $quantities_allowed = str_replace("{quantities_list}", $quantities_list, PRODUCT_ALLOWED_QUANTITIES_MSG);
        $sc_errors .= $quantities_allowed . "<br>";
        if ($type != "db") {
            return false;
        }
    } elseif ($is_price_edit && $type != "options") {
        $error_message = "";
        if (!strlen($price)) {
            $error_message = str_replace("{field_name}", PRICE_MSG, REQUIRED_MESSAGE);
        } elseif (!is_numeric($price)) {
            $error_message = str_replace("{field_name}", PRICE_MSG, INCORRECT_VALUE_MESSAGE);
        } elseif ($price < 0) {
            $error_message = str_replace("{field_name}", PRICE_MSG, MIN_VALUE_MESSAGE);
            $error_message = str_replace("{min_value}", "0.01", $error_message);
        }
        if ($error_message) {
            $sc_errors .= $error_message . "<br>" . $eol;
            if ($type != "db") {
                return false;
            }
        } else {
            // convert value to basic currency
            $price = $price / $currency["rate"];
        }
    }
    // get properties from db
    $db_properties = array();
    if ($type == "db") {
        $sql = " SELECT property_id, property_value, property_values_ids FROM " . $table_prefix . "saved_items_properties ";
        $sql .= " WHERE cart_item_id=" . $db->tosql($cart_item_id, INTEGER);
        $db->query($sql);
        while ($db->next_record()) {
            $property_id = $db->f("property_id");
            $property_value = $db->f("property_value");
            $property_values_ids = $db->f("property_values_ids");
            if (strlen($property_value)) {
                $db_properties[$property_id] = array($property_value);
            } elseif (strlen($property_values_ids)) {
                $db_properties[$property_id] = explode(",", $property_values_ids);
            }
        }
    }
    $components = array();
    $components_values = array();
    $components_price = 0;
    $controls_price = 0;
    $properties = "";
    $properties_ids = "";
    $properties_info = "";
    $sql = " SELECT ip.property_type_id, ip.property_order, ip.usage_type, ip.property_id, ip.sub_item_id, ip.property_name, ";
    $sql .= " ip.quantity, ip.quantity_action, ip.property_price_type, ip.additional_price, ip.trade_additional_price, ";
    $sql .= " ip.control_type, ip.required, ip.parent_property_id, ip.parent_value_id, ip.free_price_type, ip.free_price_amount, ip.use_on_second ";
    $sql .= " FROM (" . $table_prefix . "items_properties ip ";
    $sql .= " LEFT JOIN " . $table_prefix . "items_properties_sites ips ON ip.property_id=ips.property_id) ";
    $sql .= " WHERE (ip.item_id=" . $db->tosql($sc_item_id, INTEGER) . " OR ip.item_type_id=" . $db->tosql($item_type_id, INTEGER) . ") ";
    if (isset($site_id)) {
        $sql .= " AND (ip.sites_all=1 OR ips.site_id=" . $db->tosql($site_id, INTEGER) . ")";
    } else {
        $sql .= " AND ip.sites_all=1 ";
    }
    if ($type == "db") {
        $sql .= " AND (ip.use_on_details=1 OR ip.use_on_list=1 OR ip.use_on_second=1)";
    } elseif ($type == "list") {
        $sql .= " AND ip.use_on_list=1 ";
    } elseif ($type == "table") {
        $sql .= " AND ip.use_on_table=1 ";
    } elseif ($type == "grid") {
        $sql .= " AND ip.use_on_grid=1 ";
    } elseif ($type == "options") {
        $sql .= " AND ip.use_on_second=1 ";
    } else {
        $sql .= " AND ip.use_on_details=1 ";
    }
    $sql .= " ORDER BY ip.property_order, ip.property_id ";
    $db->query($sql);
    while ($db->next_record()) {
        $property_id = $db->f("property_id");
        $property_name = $db->f("property_name");
        $property_order = $db->f("property_order");
        $usage_type = $db->f("usage_type");
        $parent_property_id = $db->f("parent_property_id");
        $parent_value_id = $db->f("parent_value_id");
        $property_type_id = $db->f("property_type_id");
        $property_name = get_translation($db->f("property_name"));
        $property_price_type = $db->f("property_price_type");
        $additional_price = $db->f($additional_price_field);
        $free_price_type = $db->f("free_price_type");
        $free_price_amount = $db->f("free_price_amount");
        $property_quantity_action = $db->f("quantity_action");
        $use_on_second = $db->f("use_on_second");
        $option_step = $use_on_second ? 2 : 1;
        if ($property_type_id == 2) {
            $sub_item_id = $db->f("sub_item_id");
            $sub_quantity = $db->f("quantity");
            if ($sub_quantity < 1) {
                $sub_quantity = 1;
            }
            $components[$property_id][0] = array("type_id" => 2, "usage_type" => $usage_type, "sub_item_id" => $sub_item_id, "quantity" => $sub_quantity, "quantity_action" => $property_quantity_action, "price" => $additional_price);
        } else {
            $property_type = $db->f("control_type");
            $property_required = $db->f("required");
            $property_values = array();
            $values_text = array();
            if ($properties_ids) {
                $properties_ids .= ",";
            }
            $properties_ids .= $property_id;
            if ($type == "db") {
                // get properties from db
                if (isset($db_properties[$property_id])) {
                    $property_values = $db_properties[$property_id];
                }
            } else {
                // get properties from form
                if ($property_type == "CHECKBOXLIST") {
                    $property_total = get_param("property_total_" . $property_id);
                    for ($i = 1; $i <= $property_total; $i++) {
                        $property_value = get_param("property_" . $property_id . "_" . $i);
                        if ($property_value) {
                            $property_values[] = $property_value;
                        }
                    }
                } else {
                    if ($property_type == "TEXTBOXLIST") {
                        $property_total = get_param("property_total_" . $property_id);
                        for ($i = 1; $i <= $property_total; $i++) {
                            $property_value = get_param("property_" . $property_id . "_" . $i);
                            if ($property_value) {
                                $value_id = get_param("property_value_" . $property_id . "_" . $i);
                                $property_values[] = $value_id;
                                $values_text[$value_id] = $property_value;
                            }
                        }
                    } else {
                        $property_value = get_param("property_" . $property_id);
                        if (strlen($property_value)) {
                            if ($property_type == "IMAGEUPLOAD" && !preg_match("/^http\\:\\/\\//", $property_value)) {
                                $property_value = $settings["site_url"] . "images/options/" . $property_value;
                            }
                            $property_values[] = $property_value;
                            if ($property_type == "TEXTBOX" || $property_type == "TEXTAREA") {
                                $values_text[$property_value] = $property_value;
                            }
                        }
                    }
                }
            }
            $control_price = calculate_control_price($property_values, $values_text, $property_price_type, $additional_price, $free_price_type, $free_price_amount);
            $controls_price += $control_price;
            // add all properties for further checks for their different use
            $properties_info[$property_id] = array("USAGE_TYPE" => $usage_type, "CONTROL" => $property_type, "TYPE" => $property_type_id, "NAME" => $property_name, "VALUES" => $property_values, "REQUIRED" => $property_required, "PARENT_PROPERTY_ID" => $parent_property_id, "PARENT_VALUE_ID" => $parent_value_id, "TEXT" => $values_text, "CONTROL_PRICE" => $control_price, "ORDER" => $property_order, "QUANTITY_ACTION" => $property_quantity_action, "OPTION_STEP" => $option_step, "BUYING" => 0, "PRICE" => 0, "PERCENTAGE" => 0);
        }
    }
    // check components
    foreach ($components as $property_id => $component_values) {
        $component = $component_values[0];
        if ($component["usage_type"] == 2) {
            $sql = " SELECT item_id FROM " . $table_prefix . "items_properties_assigned ";
            $sql .= " WHERE item_id=" . $db->tosql($sc_item_id, INTEGER);
            $sql .= " AND property_id=" . $db->tosql($property_id, INTEGER);
            $db->query($sql);
            if (!$db->next_record()) {
                // remove component if it wasn't assigned to product
                unset($components[$property_id]);
                continue;
            }
        }
        /*if (isset($component["sub_item_id"]) && $component["sub_item_id"]) {
        			if (!VA_Products::check_permissions($component["sub_item_id"], VIEW_ITEMS_PERM)) {
        				unset($components[$property_id]);
        				continue;
        			}
        		}*/
    }
    // check usage and required settings for product options and populate $product_properties array
    $product_properties = "";
    if (isset($properties_info) && is_array($properties_info)) {
        foreach ($properties_info as $property_id => $property_info) {
            $property_exists = true;
            if ($property_info["USAGE_TYPE"] == 2) {
                // check if option should be assigned to product first
                $sql = " SELECT item_id FROM " . $table_prefix . "items_properties_assigned ";
                $sql .= " WHERE item_id=" . $db->tosql($sc_item_id, INTEGER);
                $sql .= " AND property_id=" . $db->tosql($property_id, INTEGER);
                $db->query($sql);
                if (!$db->next_record()) {
                    // remove option if it wasn't assigned to product
                    $property_exists = false;
                    unset($properties_info[$property_id]);
                }
            }
            $parent_property_id = $property_info["PARENT_PROPERTY_ID"];
            $parent_value_id = $property_info["PARENT_VALUE_ID"];
            if ($property_exists && $parent_property_id) {
                $values = array();
                if (isset($properties_info[$parent_property_id]["VALUES"])) {
                    $values = $properties_info[$parent_property_id]["VALUES"];
                }
                if (!isset($properties_info[$parent_property_id]) || sizeof($values) == 0) {
                    $property_exists = false;
                    unset($properties_info[$property_id]);
                } else {
                    if ($parent_value_id && !in_array($parent_value_id, $values)) {
                        $property_exists = false;
                        unset($properties_info[$property_id]);
                    }
                }
            }
            if ($property_exists) {
                $property_values = $property_info["VALUES"];
                $property_required = $property_info["REQUIRED"];
                if (sizeof($property_values) > 0) {
                    $properties[$property_id] = $property_values;
                    if ($property_info["TYPE"] == 3) {
                        $components_values[$property_id] = $property_values;
                    }
                    $product_properties[$property_id] = $property_info;
                } else {
                    if ($property_required) {
                        $property_error = str_replace("{property_name}", $property_info["NAME"], REQUIRED_PROPERTY_MSG);
                        $property_error = str_replace("{product_name}", get_translation($item_name), $property_error);
                        $sc_errors .= $property_error . "<br>";
                    }
                }
            }
        }
    }
    // calculate summary stock levels for options recently selected
    $options_levels = array();
    foreach ($shopping_cart as $cart_id => $cart_info) {
        $item_id = $cart_info["ITEM_ID"];
        $item_quantity = $cart_info["QUANTITY"];
        $item_properties = $cart_info["PROPERTIES"];
        $item_more_properties = $cart_info["PROPERTIES_MORE"];
        if (!$item_more_properties) {
            if (is_array($item_properties)) {
                foreach ($item_properties as $property_id => $property_values) {
                    if (isset($product_properties[$property_id])) {
                        $ct = $product_properties[$property_id]["CONTROL"];
                        if (strtoupper($ct) == "LISTBOX" || strtoupper($ct) == "RADIOBUTTON" || strtoupper($ct) == "CHECKBOXLIST" || strtoupper($ct) == "TEXTBOXLIST") {
                            for ($ov = 0; $ov < sizeof($property_values); $ov++) {
                                $option_value_id = $property_values[$ov];
                                if (isset($options_levels[$option_value_id])) {
                                    $options_levels[$option_value_id] += $item_quantity;
                                } else {
                                    $options_levels[$option_value_id] = $item_quantity;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // check components values for selection
    if (sizeof($components_values)) {
        foreach ($components_values as $property_id => $values) {
            for ($v = 0; $v < sizeof($values); $v++) {
                $item_property_id = $values[$v];
                $sql = " SELECT ipv.sub_item_id, ipv.quantity, ipv.additional_price, ipv.trade_additional_price ";
                $sql .= " FROM " . $table_prefix . "items_properties_values ipv ";
                $sql .= " WHERE ipv.item_property_id=" . $db->tosql($item_property_id, INTEGER);
                $db->query($sql);
                if ($db->next_record()) {
                    $sub_item_id = $db->f("sub_item_id");
                    $sub_quantity = $db->f("quantity");
                    if ($sub_quantity < 1) {
                        $sub_quantity = 1;
                    }
                    $additional_price = $db->f($additional_price_field);
                    $components[$property_id][$item_property_id] = array("type_id" => 3, "sub_item_id" => $sub_item_id, "quantity" => $sub_quantity, "quantity_action" => $properties_info[$property_id]["QUANTITY_ACTION"], "price" => $additional_price);
                }
            }
        }
    }
    $second_page_options = 0;
    if ($type != "options" && $type != "db") {
        $sql = " SELECT COUNT(*) ";
        $sql .= " FROM (" . $table_prefix . "items_properties ip ";
        $sql .= " LEFT JOIN " . $table_prefix . "items_properties_sites ips ON ip.property_id=ips.property_id) ";
        $sql .= " WHERE (ip.item_id=" . $db->tosql($sc_item_id, INTEGER) . " OR ip.item_type_id=" . $db->tosql($item_type_id, INTEGER) . ") ";
        $sql .= " AND ip.use_on_second=1 AND ip.property_type_id<>2 ";
        if (isset($site_id)) {
            $sql .= " AND (ip.sites_all=1 OR ips.site_id=" . $db->tosql($site_id, INTEGER) . ")";
        } else {
            $sql .= " AND ip.sites_all=1 ";
        }
        if ($properties_ids) {
            $sql .= " AND ip.property_id NOT IN (" . $properties_ids . ") ";
        }
        $second_page_options = get_db_value($sql);
    }
    if ($sc_errors && $type != "db") {
        // error occurred can't continue process
        return false;
    }
    // TODO: add some new status parameter to check different shopping cart items
    if ($cart == "SHIPPING") {
        // use second_page_options property for a product we check shipping
        $second_page_options = true;
    }
    // begin calculate buying, price and percentage values
    $properties_price = 0;
    $properties_percentage = 0;
    if (is_array($properties)) {
        foreach ($properties as $property_id => $property_values) {
            if (strtoupper($product_properties[$property_id]["CONTROL"]) == "LISTBOX" || strtoupper($product_properties[$property_id]["CONTROL"]) == "RADIOBUTTON" || strtoupper($product_properties[$property_id]["CONTROL"]) == "CHECKBOXLIST" || strtoupper($product_properties[$property_id]["CONTROL"]) == "TEXTBOXLIST") {
                for ($pv = 0; $pv < sizeof($property_values); $pv++) {
                    if ($product_properties[$property_id]["TYPE"] == 3) {
                    } else {
                        $item_property_id = $property_values[$pv];
                        if (isset($options_levels[$item_property_id])) {
                            $option_quantity = $options_levels[$item_property_id] + $sc_quantity;
                        } else {
                            $option_quantity = $sc_quantity;
                        }
                        $sql = " SELECT buying_price, additional_price, trade_additional_price, percentage_price, additional_weight, ";
                        $sql .= " property_value, stock_level, use_stock_level, hide_out_of_stock ";
                        $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);
                        $sql .= " ORDER BY item_property_id ";
                        $db->query($sql);
                        if ($db->next_record()) {
                            $additional_price = $db->f($additional_price_field);
                            $percentage_price = $db->f("percentage_price");
                            $buying_price = $db->f("buying_price");
                            $properties_price += $additional_price;
                            $properties_percentage += $percentage_price;
                            $properties_buying += $buying_price;
                            $option_value = get_translation($db->f("property_value"));
                            $option_stock_level = $db->f("stock_level");
                            $option_use_stock = $db->f("use_stock_level");
                            $option_hide_stock = $db->f("hide_out_of_stock");
                            // populate properties array with prices information
                            $product_properties[$property_id]["BUYING"] += $buying_price;
                            $product_properties[$property_id]["PRICE"] += $additional_price;
                            $product_properties[$property_id]["PERCENTAGE"] += $percentage_price;
                        }
                        // check stock levels only if product added to shopping cart
                        if ($cart == "ADD" && $option_use_stock && $option_stock_level < $option_quantity && $option_hide_stock) {
                            if ($option_stock_level > 0) {
                                $limit_product = get_translation($item_name) . " (" . $product_properties[$property_id]["NAME"] . ": " . $option_value . ")";
                                $limit_error = str_replace("{limit_quantity}", $option_stock_level, PRODUCT_LIMIT_MSG);
                                $limit_error = str_replace("{product_name}", $limit_product, $limit_error);
                                $sc_errors .= $limit_error . "<br>";
                            } else {
                                $sc_errors .= PRODUCT_OUT_STOCK_MSG . "<br>";
                            }
                            if ($type != "db") {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
    // end calculate buying, price and percentage values
    // check if the item already in the cart than increase quantity
    $in_cart = false;
    if ($cart == "ADD" && !$second_page_options && $type != "options") {
        foreach ($shopping_cart as $in_cart_id => $item) {
            if ($item["ITEM_ID"] == $sc_item_id && !$item["PROPERTIES_MORE"]) {
                $item_properties = $item["PROPERTIES"];
                $item_properties_info = $item["PROPERTIES_INFO"];
                if (!is_array($item_properties) && !is_array($properties)) {
                    $in_cart = true;
                    break;
                } elseif (is_array($item_properties) && is_array($properties) && $item_properties_info == $product_properties) {
                    // compare if new product and product in the cart has the same options values
                    $in_cart = true;
                    break;
                }
            }
        }
    }
    if ($in_cart) {
        $new_quantity = $shopping_cart[$in_cart_id]["QUANTITY"] + $sc_quantity;
    } else {
        $new_quantity = $sc_quantity;
    }
    // check components prices and stock levels
    if (sizeof($components) > 0) {
        foreach ($components as $property_id => $component_values) {
            foreach ($component_values as $item_property_id => $component) {
                $sub_item_id = $component["sub_item_id"];
                $sub_quantity = $component["quantity"];
                if ($sub_quantity < 1) {
                    $sub_quantity = 1;
                }
                $component_price = $component["price"];
                if (isset($stock_levels[$sub_item_id])) {
                    $component_quantity = $stock_levels[$sub_item_id] + $sc_quantity * $sub_quantity;
                } else {
                    $component_quantity = $sc_quantity * $sub_quantity;
                }
                $sql = " SELECT i.item_type_id, i.item_name, i.buying_price, i." . $price_field . ", i.is_sales, i." . $sales_field . ", i.tax_id, i.tax_free, ";
                $sql .= " i.stock_level, i.use_stock_level, i.hide_out_of_stock, i.disable_out_of_stock ";
                $sql .= " FROM " . $table_prefix . "items i ";
                $sql .= " WHERE i.item_id=" . $db->tosql($sub_item_id, INTEGER);
                $db->query($sql);
                if ($db->next_record()) {
                    $sub_type_id = $db->f("item_type_id");
                    $sub_tax_id = $db->f("tax_id");
                    $sub_tax_free = $db->f("tax_free");
                    $sub_stock_level = $db->f("stock_level");
                    $sub_use_stock = $db->f("use_stock_level");
                    $sub_hide_stock = $db->f("hide_out_of_stock");
                    $sub_disable_stock = $db->f("disable_out_of_stock");
                    $sub_item_name = get_translation($db->f("item_name"));
                    // check stock levels only if product added to shopping cart
                    if ($cart == "ADD" && $sub_use_stock && $sub_stock_level < $component_quantity && ($sub_hide_stock || $sub_disable_stock)) {
                        if ($sub_stock_level > 0) {
                            $limit_product = get_translation($item_name);
                            if (isset($product_properties[$property_id]["NAME"])) {
                                $limit_product .= " (" . $product_properties[$property_id]["NAME"] . ": " . $sub_item_name . ")";
                            }
                            $limit_error = str_replace("{limit_quantity}", $sub_stock_level, PRODUCT_LIMIT_MSG);
                            $limit_error = str_replace("{product_name}", $limit_product, $limit_error);
                            $sc_errors .= $limit_error . "<br>";
                        } else {
                            $sc_errors .= PRODUCT_OUT_STOCK_MSG . "<br>";
                        }
                        if ($type != "db") {
                            return false;
                        }
                    }
                    $components[$property_id][$item_property_id]["item_type_id"] = $sub_type_id;
                    $components[$property_id][$item_property_id]["tax_id"] = $sub_tax_id;
                    $components[$property_id][$item_property_id]["tax_free"] = $sub_tax_free;
                    if (!strlen($component_price)) {
                        $sub_price = $db->f($price_field);
                        $sub_is_sales = $db->f("is_sales");
                        $sub_sales = $db->f($sales_field);
                        if ($sub_is_sales && $sub_sales > 0) {
                            $components[$property_id][$item_property_id]["base_price"] = $sub_sales;
                        } else {
                            $components[$property_id][$item_property_id]["base_price"] = $sub_price;
                        }
                        $user_price = false;
                        $user_price_action = 0;
                        $q_prices = get_quantity_price($sub_item_id, $new_quantity * $sub_quantity);
                        if ($q_prices) {
                            $user_price = $q_prices[0];
                            $user_price_action = $q_prices[2];
                        }
                        $components[$property_id][$item_property_id]["buying"] = $db->f("buying_price");
                        $components[$property_id][$item_property_id]["user_price"] = $user_price;
                        $components[$property_id][$item_property_id]["user_price_action"] = $user_price_action;
                        if ($in_cart) {
                            $shopping_cart[$in_cart_id]["COMPONENTS"][$property_id][$item_property_id] = $components[$property_id][$item_property_id];
                        }
                    }
                } else {
                    // there is no such subcomponent
                    $sc_errors .= "Component is missing.<br>";
                    if ($type != "db") {
                        return false;
                    }
                }
            }
        }
    }
    if ($in_cart && !$is_price_edit) {
        $shopping_cart[$in_cart_id]["QUANTITY"] += $sc_quantity;
        $quantity_price = get_quantity_price($item["ITEM_ID"], $shopping_cart[$in_cart_id]["QUANTITY"]);
        if (sizeof($quantity_price) > 0) {
            $shopping_cart[$in_cart_id]["PRICE"] = $quantity_price[0];
            $shopping_cart[$in_cart_id]["PROPERTIES_DISCOUNT"] = $quantity_price[1];
            $shopping_cart[$in_cart_id]["DISCOUNT"] = $quantity_price[2];
        }
        $item_added = true;
    } else {
        if ($type == "options") {
            // remove options for all following steps if they were added before
            $options_step = 2;
            $all_properties = $shopping_cart[$cart_id]["PROPERTIES"];
            $all_properties_info = $shopping_cart[$cart_id]["PROPERTIES_INFO"];
            if (is_array($all_properties)) {
                foreach ($all_properties_info as $property_id => $property_info) {
                    if ($property_info["OPTION_STEP"] >= $options_step) {
                        unset($all_properties[$property_id]);
                        unset($all_properties_info[$property_id]);
                    }
                }
            }
            if (is_array($properties)) {
                foreach ($properties as $property_id => $property_values) {
                    $all_properties[$property_id] = $property_values;
                }
                foreach ($product_properties as $property_id => $property_info) {
                    $all_properties_info[$property_id] = $property_info;
                }
            }
            $shopping_cart[$cart_id]["PROPERTIES"] = $all_properties;
            $shopping_cart[$cart_id]["PROPERTIES_INFO"] = $all_properties_info;
            $shopping_cart[$cart_id]["PROPERTIES_MORE"] = 0;
            // recalculate options totals
            $shopping_cart[$cart_id]["PROPERTIES_PRICE"] = 0;
            $shopping_cart[$cart_id]["PROPERTIES_PERCENTAGE"] = 0;
            $shopping_cart[$cart_id]["PROPERTIES_BUYING"] = 0;
            if (is_array($all_properties)) {
                foreach ($all_properties_info as $property_id => $property_info) {
                    $shopping_cart[$cart_id]["PROPERTIES_PRICE"] += $property_info["PRICE"];
                    $shopping_cart[$cart_id]["PROPERTIES_PERCENTAGE"] += $property_info["PERCENTAGE"];
                    $shopping_cart[$cart_id]["PROPERTIES_BUYING"] += $property_info["BUYING"];
                }
            }
            if ($cart == "WISHLIST") {
                add_to_saved_items($shopping_cart, $new_cart_id, 0, true);
            }
        } else {
            if (!$is_price_edit) {
                $quantity_price = get_quantity_price($sc_item_id, $sc_quantity);
                if (sizeof($quantity_price) > 0) {
                    $price = $quantity_price[0];
                    $properties_discount = $quantity_price[1];
                    $discount_applicable = $quantity_price[2];
                }
            }
            $item = array("ITEM_ID" => intval($sc_item_id), "ITEM_TYPE_ID" => $item_type_id, "CART_ITEM_ID" => $cart_item_id, "SAVED_TYPE_ID" => get_param("saved_type_id"), "ITEM_NAME" => $item_name, "ERROR" => $sc_errors, "PROPERTIES" => $properties, "PROPERTIES_INFO" => $product_properties, "PROPERTIES_PRICE" => $properties_price + $controls_price, "PROPERTIES_PERCENTAGE" => $properties_percentage, "PROPERTIES_BUYING" => $properties_buying, "PROPERTIES_DISCOUNT" => $properties_discount, "PROPERTIES_MORE" => $second_page_options, "COMPONENTS" => $components, "QUANTITY" => $sc_quantity, "TAX_ID" => $tax_id, "TAX_FREE" => $tax_free, "DISCOUNT" => $discount_applicable, "BUYING_PRICE" => $buying_price, "PRICE_EDIT" => $is_price_edit, "PRICE" => $price);
            //-- add to cart
            $shopping_cart[] = $item;
            end($shopping_cart);
            $new_cart_id = key($shopping_cart);
            if ($cart == "WISHLIST" && !$second_page_options) {
                add_to_saved_items($shopping_cart, $new_cart_id, 0, true);
            }
        }
        $item_added = true;
    }
    // save session
    set_session("shopping_cart", $shopping_cart);
    // return success message
    $sc_message = str_replace("{product_name}", get_translation($item_name), ADDED_PRODUCT_MSG);
    return $item_added;
}
示例#5
0
         $subscription_tax_id = 0;
         // re-calculate price in case if prices include some default tax rate
         $subscription_item_tax = get_tax_amount($tax_rates, 0, $subscription_fee, 1, $subscription_tax_id, $tax_free, $subscription_tax_percent, $default_tax_rates);
         $cart_item_id = $cart_id;
         $cart_items[$cart_item_id] = array("parent_cart_id" => "", "is_bundle" => 0, "top_order_item_id" => 0, "item_id" => 0, "id" => 0, "product_id" => 0, "parent_item_id" => 0, "item_user_id" => 0, "item_type_id" => 0, "supplier_id" => 0, "wishlist_item_id" => $wishlist_item_id, "item_code" => "", "manufacturer_code" => "", "selection_name" => "", "selection_order" => "", "item_image" => "", "item_image_alt" => "", "packages_number" => 0, "width" => 0, "height" => 0, "length" => 0, "weight" => 0, "shipping_cost" => 0, "is_shipping_free" => 1, "is_country_restriction" => 0, "shipping_rule_id" => 0, "price" => $subscription_fee, "quantity" => $quantity, "tax_id" => $subscription_tax_id, "tax_free" => $tax_free, "tax_percent" => $subscription_tax_percent, "real_price" => $subscription_fee, "discount_amount" => 0, "coupons" => "", "coupons_ids" => "", "affiliate_type" => $subscription_affiliate_type, "affiliate_amount" => $subscription_affiliate_amount, "merchant_type" => 0, "merchant_amount" => 0, "is_points_price" => 0, "points_price" => 0, "reward_type" => $subscription_points_type, "reward_amount" => $subscription_points_amount, "credit_reward_type" => $subscription_credits_type, "credit_reward_amount" => $subscription_credits_amount, "coupons" => "", "coupons_ids" => "", "coupons_discount" => 0, "buying_price" => 0, "item_name" => $subscription_name_initial, "product_name" => $subscription_name_initial, "product_title" => $subscription_name_initial, "item_title" => $subscription_name_initial, "discount_applicable" => 0, "properties_discount" => 0, "properties_info" => "", "properties_html" => "", "properties_text" => "", "downloadable" => 0, "downloads" => "", "stock_level" => "", "availability_time" => "", "short_description" => "", "description" => "", "full_description" => "", "generate_serial" => 0, "serial_period" => "", "activations_number" => "", "is_gift_voucher" => 0, "is_recurring" => $is_recurring, "recurring_price" => "", "recurring_period" => $recurring_period, "recurring_interval" => $recurring_interval, "recurring_payments_total" => "", "recurring_start_date" => "", "recurring_end_date" => "", "is_subscription" => 1, "is_account_subscription" => $is_account_subscription, "subscription_id" => $subscription_id, "subscription_period" => $subscription_period, "subscription_interval" => $subscription_interval, "subscription_suspend" => $subscription_suspend);
     }
     continue;
 }
 $properties_more = $item["PROPERTIES_MORE"];
 if ($properties_more) {
     continue;
 }
 $properties = $item["PROPERTIES"];
 $components = $item["COMPONENTS"];
 $item_coupons = isset($item["COUPONS"]) ? $item["COUPONS"] : "";
 if (VA_Products::check_permissions($item_id, VIEW_ITEMS_PERM)) {
     $sql = " SELECT i.item_code, i.manufacturer_code, i.item_type_id, i.supplier_id, i.user_id, i.item_name, i.short_description, i.full_description, ";
     $sql .= " i.friendly_url, ";
     // Customization by Vital - prod. link
     $sql .= " i.buying_price, i." . $price_field . ", i.is_price_edit, i.is_sales, i." . $sales_field . ", i.tax_id, i.tax_free, ";
     $sql .= " i.is_points_price, i.points_price, i.reward_type, i.reward_amount, i.credit_reward_type, i.credit_reward_amount, ";
     $sql .= " it.reward_type AS type_bonus_reward, it.reward_amount AS type_bonus_amount, ";
     $sql .= " it.credit_reward_type AS type_credit_reward, it.credit_reward_amount AS type_credit_amount, ";
     $sql .= " i.packages_number, i.width, i.height, i.length, ";
     $sql .= " i.stock_level, i.use_stock_level, i.hide_out_of_stock, i.disable_out_of_stock, i.weight, ";
     $sql .= " i.merchant_fee_type AS item_merchant_type, i.merchant_fee_amount AS item_merchant_amount, i.affiliate_commission_type AS item_affiliate_type, i.affiliate_commission_amount AS item_affiliate_amount, ";
     $sql .= " it.merchant_fee_type AS type_merchant_type, it.merchant_fee_amount AS type_merchant_amount, it.affiliate_commission_type AS type_affiliate_type, it.affiliate_commission_amount AS type_affiliate_amount, ";
     $sql .= " i.downloadable, i.download_period, i.download_path, i.generate_serial, i.serial_period, i.activations_number, ";
     $sql .= " st_in.availability_time AS in_stock_availability , st_out.availability_time AS out_stock_availability, ";
     $sql .= " i.shipping_rule_id, sr.is_country_restriction, i.shipping_cost, i.is_shipping_free, ";
     $sql .= " i.is_recurring, i.recurring_price, i.recurring_period, i.recurring_interval, ";