本文整理汇总了PHP中fn_generate_cart_id函数的典型用法代码示例。如果您正苦于以下问题:PHP fn_generate_cart_id函数的具体用法?PHP fn_generate_cart_id怎么用?PHP fn_generate_cart_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fn_generate_cart_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fn_exim_put_product_combination
function fn_exim_put_product_combination($product_id, $product_name, $combination_code, $combination, $amount, &$counter, $lang_code = CART_LANGUAGE)
{
$pair_delimiter = ':';
$set_delimiter = ',';
if (!empty($combination)) {
// Get product_id
$object_id = 0;
if (!empty($product_id)) {
$object_exists = db_get_field('SELECT COUNT(*) FROM ?:products WHERE product_id = ?i', $product_id);
if ($object_exists) {
$object_id = $product_id;
}
}
if (empty($object_id) && !empty($product_name)) {
$object_id = db_get_field('SELECT product_id FROM ?:product_descriptions WHERE product = ?s AND lang_code = ?s', $product_name, $lang_code);
}
if (empty($object_id)) {
$counter['S']++;
return false;
}
$options = explode($set_delimiter, $combination);
if (!empty($options)) {
$_combination = array();
foreach ($options as $option_pair) {
$pair = explode($pair_delimiter, $option_pair);
if (is_array($pair)) {
array_walk($pair, 'fn_trim_helper');
$option_id = db_get_field("SELECT o.option_id FROM ?:product_options_descriptions as d INNER JOIN ?:product_options as o ON o.option_id = d.option_id AND o.product_id = ?i WHERE d.option_name = ?s AND d.lang_code = ?s LIMIT 1", $object_id, $pair[0], $lang_code);
$variant_id = db_get_field("SELECT v.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as v ON v.variant_id = d.variant_id AND v.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $option_id, $pair[1], $lang_code);
if (empty($option_id) || empty($variant_id)) {
$counter['S']++;
return false;
}
$_combination[$option_id] = $variant_id;
}
}
$combination = fn_get_options_combination($_combination);
$combination_hash = fn_generate_cart_id($object_id, array('product_options' => $_combination));
$object_exists = db_get_field('SELECT COUNT(*) FROM ?:product_options_inventory WHERE combination_hash = ?i AND product_id = ?i', $combination_hash, $object_id);
$_data = array('product_id' => $object_id, 'product_code' => $combination_code, 'combination_hash' => $combination_hash, 'combination' => $combination, 'amount' => $amount);
if ($object_exists) {
db_query('UPDATE ?:product_options_inventory SET ?u WHERE combination_hash = ?i', $_data, $combination_hash);
fn_echo(fn_get_lang_var('updating') . ' ' . fn_get_lang_var('product_combinations') . '...');
$counter['E']++;
} else {
db_query('INSERT INTO ?:product_options_inventory ?e', $_data);
fn_echo(fn_get_lang_var('creating') . ' ' . fn_get_lang_var('product_combinations') . '...');
$counter['N']++;
}
fn_echo('<b>' . $object_id . '</b>.<br />');
return $combination;
}
}
$counter['S']++;
return false;
}
示例2: fn_exim_1c_offers
function fn_exim_1c_offers($xml, $company_id, $lang_code)
{
$cml = fn_get_cml_tag_names();
$create_prices = Registry::get('addons.rus_exim_1c.exim_1c_create_prices');
$type_option = Registry::get('addons.rus_exim_1c.exim_1c_type_option');
$hide_product = Registry::get('addons.rus_exim_1c.exim_1c_add_out_of_stock');
$schema_version = Registry::get('addons.rus_exim_1c.exim_1c_schema_version');
if (isset($xml->{$cml}['packages']->{$cml}['prices_types']) && $create_prices == 'Y') {
$prices_1c = array();
$_prices_1c = db_get_array("SELECT price_1c, type, usergroup_id FROM ?:rus_exim_1c_prices");
foreach ($xml->{$cml}['packages']->{$cml}['prices_types']->{$cml}['price_type'] as $_price) {
foreach ($_prices_1c as $_price_1c) {
if ($_price_1c['price_1c'] == strval($_price->{$cml}['name'])) {
$_price_1c['external_id'] = strval($_price->{$cml}['id']);
$prices_1c[] = $_price_1c;
}
}
}
}
if (isset($xml->{$cml}['packages']->{$cml}['offers'])) {
$standart_option_name = Registry::get('addons.rus_exim_1c.exim_1c_standart_option_name');
$import_mode = Registry::get('addons.rus_exim_1c.exim_1c_import_mode_offers');
$standart_option_name = Registry::get('addons.rus_exim_1c.exim_1c_import_option_name');
$options_data = $global_options_data = array();
foreach ($xml->{$cml}['packages']->{$cml}['offers']->{$cml}['offer'] as $offer) {
$product = array();
$ids = fn_explode('#', strval($offer->{$cml}['id']));
$product_guid = array_shift($ids);
$combination_guid = !empty($ids) ? array_shift($ids) : '';
$product_id = db_get_field("SELECT product_id FROM ?:products WHERE external_id = ?s", $product_guid);
if (empty($product_id)) {
continue;
}
$amount = 0;
if (isset($offer->{$cml}['store'])) {
foreach ($offer->{$cml}['store'] as $store) {
$amount += strval($store[$cml['in_stock']]);
}
}
if (isset($offer->{$cml}['amount'])) {
$amount = strval($offer->{$cml}['amount']);
}
$prices = array();
if (isset($offer->{$cml}['prices'])) {
if ($create_prices == 'Y') {
foreach ($offer->{$cml}['prices']->{$cml}['price'] as $_price_data) {
foreach ($prices_1c as $price_1c) {
if (strval($_price_data->{$cml}['price_id']) == $price_1c['external_id']) {
if ($price_1c['type'] == 'base') {
$prices['base_price'] = strval($_price_data->{$cml}['price_per_item']);
}
if ($price_1c['type'] == 'list') {
$prices['list_price'] = strval($_price_data->{$cml}['price_per_item']);
}
if ($price_1c['usergroup_id'] > 0) {
$prices['qty_prices'][] = array('usergroup_id' => $price_1c['usergroup_id'], 'price' => strval($_price_data->{$cml}['price_per_item']));
}
}
}
}
} else {
$prices['base_price'] = strval($offer->{$cml}['prices']->{$cml}['price']->{$cml}['price_per_item']);
}
}
if (empty($prices)) {
$prices['base_price'] = 0;
}
if (empty($combination_guid)) {
db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", array('amount' => $amount), $product_id);
// To hide products if they are out of stock
if ($hide_product == 'Y') {
if ($amount == 0) {
db_query("UPDATE ?:products SET status = 'H' WHERE product_id = ?i", $product_id);
}
}
fn_exim_1c_add_price($prices, $product_id);
} else {
db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", array('tracking' => 'O'), $product_id);
if ($schema_version == '2.07') {
if (!empty($prices['base_price'])) {
fn_exim_1c_add_price(array('base_price' => 0), $product_id);
}
$option_id = db_get_field("SELECT option_id FROM ?:product_options WHERE product_id = ?i", $product_id);
$variant_id = db_get_field("SELECT variant_id FROM ?:product_option_variants WHERE external_id = ?s AND option_id = ?i", $combination_guid, $option_id);
db_query("UPDATE ?:product_option_variants SET modifier = ?i WHERE variant_id = ?i", $prices['base_price'], $variant_id);
$old_combination_hash = db_get_field("SELECT combination_hash FROM ?:product_options_inventory WHERE external_id = ?s", $combination_guid);
$image_pair_id = db_get_field("SELECT pair_id FROM ?:images_links WHERE object_id = ?i", $old_combination_hash);
db_query("DELETE FROM ?:product_options_inventory WHERE external_id = ?s AND product_id = ?i", $combination_guid, $product_id);
$combination_data = array('product_id' => $product_id, 'combination_hash' => fn_generate_cart_id($product_id, array('product_options' => array($option_id => $variant_id))), 'combination' => fn_get_options_combination(array($option_id => $variant_id)), 'amount' => $amount, 'external_id' => $combination_guid);
$variant_combination = db_get_field("SELECT combination_hash FROM ?:product_options_inventory WHERE combination_hash = ?i", $combination_data['combination_hash']);
if (empty($variant_combination)) {
db_query("INSERT INTO ?:product_options_inventory ?e", $combination_data);
}
if (!empty($image_pair_id)) {
db_query("UPDATE ?:images_links SET object_id = ?i WHERE pair_id = ?i", $combination_data['combination_hash'], $image_pair_id);
}
continue;
}
if ($import_mode == 'standart') {
$variant_name = '';
//.........这里部分代码省略.........
示例3: fn_add_product_to_wishlist
/**
* Add product to wishlist
*
* @param array $product_data array with data for the product to add)(product_id, price, amount, product_options, is_edp)
* @param array $wishlist wishlist data storage
* @param array $auth user session data
* @return mixed array with wishlist IDs for the added products, false otherwise
*/
function fn_add_product_to_wishlist($product_data, &$wishlist, &$auth)
{
// Check if products have cusom images
list($product_data, $wishlist) = fn_add_product_options_files($product_data, $wishlist, $auth, false, 'wishlist');
fn_set_hook('pre_add_to_wishlist', $product_data, $wishlist, $auth);
if (!empty($product_data) && is_array($product_data)) {
$wishlist_ids = array();
foreach ($product_data as $product_id => $data) {
if (empty($data['amount'])) {
$data['amount'] = 1;
}
if (!empty($data['product_id'])) {
$product_id = $data['product_id'];
}
if (empty($data['extra'])) {
$data['extra'] = array();
}
// Add one product
if (!isset($data['product_options'])) {
$data['product_options'] = fn_get_default_product_options($product_id);
}
// Generate wishlist id
$data['extra']['product_options'] = $data['product_options'];
$_id = fn_generate_cart_id($product_id, $data['extra']);
//$_SESSION['tessssssssssssssssssssssssssssssssssssssstttttttttttt'] = $data['extra'];
$_data = db_get_row('SELECT is_edp, options_type, tracking FROM ?:products WHERE product_id = ?i', $product_id);
$data['is_edp'] = $_data['is_edp'];
$data['options_type'] = $_data['options_type'];
$data['tracking'] = $_data['tracking'];
// Check the sequential options
if (!empty($data['tracking']) && $data['tracking'] == 'O' && $data['options_type'] == 'S') {
$inventory_options = db_get_fields("SELECT a.option_id FROM ?:product_options as a LEFT JOIN ?:product_global_option_links as c ON c.option_id = a.option_id WHERE (a.product_id = ?i OR c.product_id = ?i) AND a.status = 'A' AND a.inventory = 'Y'", $product_id, $product_id);
$sequential_completed = true;
if (!empty($inventory_options)) {
foreach ($inventory_options as $option_id) {
if (!isset($data['product_options'][$option_id]) || empty($data['product_options'][$option_id])) {
$sequential_completed = false;
break;
}
}
}
if (!$sequential_completed) {
fn_set_notification('E', __('error'), __('select_all_product_options'));
// Even if customer tried to add the product from the catalog page, we will redirect he/she to the detailed product page to give an ability to complete a purchase
$redirect_url = fn_url('products.view?product_id=' . $product_id . '&combination=' . fn_get_options_combination($data['product_options']));
$_REQUEST['redirect_url'] = $redirect_url;
//FIXME: Very very very BAD style to use the global variables in the functions!!!
return false;
}
}
$wishlist_ids[] = $_id;
$wishlist['products'][$_id]['product_id'] = $product_id;
$wishlist['products'][$_id]['product_options'] = $data['product_options'];
$wishlist['products'][$_id]['extra'] = $data['extra'];
$wishlist['products'][$_id]['amount'] = $data['amount'];
}
return $wishlist_ids;
} else {
return false;
}
}
示例4: db_get_field
} else {
$existent_amount = db_get_field("SELECT amount FROM ?:giftreg_event_products WHERE item_id = ?i AND event_id = ?i", $data['item_id'], $_REQUEST['event_id']);
if (!empty($data['amount'])) {
$data = fn_check_table_fields($data, 'giftreg_event_products');
db_query("UPDATE ?:giftreg_event_products SET ?u WHERE item_id = ?i AND event_id = ?i", $data, $item_id, $_REQUEST['event_id']);
} else {
db_query("DELETE FROM ?:giftreg_event_products WHERE item_id = ?i AND event_id = ?i", $item_id, $_REQUEST['event_id']);
}
}
}
$suffix = ".update?selected_section=products&event_id={$_REQUEST['event_id']}";
}
// Add products to the event
if ($mode == 'add_products') {
foreach ($_REQUEST['product_data'] as $product_id => $data) {
$data['item_id'] = fn_generate_cart_id($product_id, array("product_options" => @$data['product_options']), false);
$existent_amount = db_get_field("SELECT amount FROM ?:giftreg_event_products WHERE item_id = ?i", $data['item_id']);
if (!empty($data['product_options'])) {
$data['extra'] = serialize($data['product_options']);
}
$data['product_id'] = $product_id;
$data['event_id'] = $_REQUEST['event_id'];
if (!empty($data['amount'])) {
$data['amount'] += $existent_amount;
$data = fn_check_table_fields($data, 'giftreg_event_products');
db_query("REPLACE INTO ?:giftreg_event_products ?e", $data);
}
}
$suffix = ".update?selected_section=products&event_id={$_REQUEST['event_id']}";
}
// Add new event
示例5: fn_add_gift_certificate_to_wishlist
/**
* Add gift certificate to wishlist
*
* @param array $wishlist wishlist data storage
* @param array $gift_cert_data array with data for the certificate to add
* @return array array with gift certificate ID and data if addition is successful and empty array otherwise
*/
function fn_add_gift_certificate_to_wishlist(&$wishlist, $gift_cert_data)
{
if (!empty($gift_cert_data) && is_array($gift_cert_data)) {
fn_correct_gift_certificate($gift_cert_data);
// Generate wishlist id
$gift_cert_wishlist_id = fn_generate_gift_certificate_cart_id($gift_cert_data);
$wishlist['gift_certificates'][$gift_cert_wishlist_id] = $gift_cert_data;
$gift_cert_data['display_subtotal'] = $gift_cert_data['amount'];
if (!empty($gift_cert_data['products'])) {
$product_data = array();
foreach ($gift_cert_data['products'] as $w_id => $_data) {
if (empty($_data['amount'])) {
unset($gift_cert_data['products'][$w_id]);
continue;
}
if (empty($_data['product_options'])) {
$_data['product_options'] = fn_get_default_product_options($_data['product_id']);
}
$wishlist_id = fn_generate_cart_id($_data['product_id'], array('product_options' => $_data['product_options'], 'parent' => array('certificate' => $gift_cert_wishlist_id)), true);
$product_data[$wishlist_id] = $_data;
$wishlist['products'][$wishlist_id] = array('product_id' => $_data['product_id'], 'product_options' => $_data['product_options'], 'amount' => $_data['amount'], 'extra' => array('parent' => array('certificate' => $gift_cert_wishlist_id)));
$product = fn_get_product_data($_data['product_id'], $_SESSION['auth']);
$gift_cert_data['display_subtotal'] += $_data['amount'] * $product['price'];
}
$gift_cert_data['products'] = $wishlist['gift_certificates'][$gift_cert_wishlist_id]['products'] = $product_data;
}
return array($gift_cert_wishlist_id, $gift_cert_data);
} else {
return array();
}
}
示例6: fn_generate_cart_id
$product['combination_hash'] = fn_generate_cart_id($product['product_id'], $_REQUEST['product_data'][$product['product_id']], true);
$selected_options_for_hash = array();
if ($_REQUEST['product_data'][$product['product_id']]['extra']) {
$selected_options_for_hash["price_calc"] = array("total_price_calc" => (string) $product['price']);
}
$product_options_ids_for_hash = array();
foreach ($product['selected_options'] as $k1 => $v1) {
$product_options_ids_for_hash[] = $k1;
}
$product_options_ids_for_hash_ordered = db_get_array("SELECT option_id FROM ?:product_options WHERE option_id IN (?n) ORDER BY position", $product_options_ids_for_hash);
foreach ($product_options_ids_for_hash_ordered as $k2 => $v2) {
$selected_options_for_hash["product_options"][$v2['option_id']] = (string) $product['selected_options'][$v2['option_id']];
}
$_SESSION['ls_selected_options']['options'] = $_REQUEST['product_data'][$product['product_id']]['product_options'];
$_SESSION['ls_selected_options']['product_id'] = $product['product_id'];
$product['combination_hash_wishlist'] = fn_generate_cart_id($product['product_id'], $selected_options_for_hash);
Registry::get('view')->assign('ls_post_hash', $product['combination_hash']);
//get cart products details
list($ls_total_products, $ls_product_groups) = fn_calculate_cart_content($_SESSION['cart'], $auth, Registry::get('settings.General.estimate_shipping_cost') == 'Y' ? 'A' : 'S', true, 'F', true);
//copy product info to pass it as reference later
$ls_current_page_product = array($product['combination_hash'] => $product);
//copy the db hash
$ls_current_page_product[$product['combination_hash']]['ls_db_hash'] = $product['combination_hash'];
//set the product page order amount
$ls_current_page_product[$product['combination_hash']]['order_amount'] = 1;
//check to see if this product is already in cart
if (!fn_is_product_in_cart($ls_current_page_product, $ls_total_products, $product)) {
//set the product page order amount
$ls_current_page_product[$product['combination_hash']]['order_amount'] = 1;
$product['ls_order_amount'] = 1;
//for template logic to hide the add to cart button
示例7: fn_set_notification
} else {
fn_set_notification('W', __('warning'), __('exception_exist'));
}
}
fn_update_exceptions($_REQUEST['product_id']);
$suffix = ".exceptions?product_id={$_REQUEST['product_id']}";
}
if ($mode == 'm_delete_exceptions') {
db_query("DELETE FROM ?:product_options_exceptions WHERE exception_id IN (?n)", $_REQUEST['exception_ids']);
$suffix = ".exceptions?product_id={$_REQUEST['product_id']}";
}
}
if ($mode == 'add_combinations') {
if (is_array($_REQUEST['add_inventory'])) {
foreach ($_REQUEST['add_inventory'] as $k => $v) {
$combination_hash = fn_generate_cart_id($_REQUEST['product_id'], array('product_options' => $_REQUEST['add_options_combination'][$k]));
$combination = fn_get_options_combination($_REQUEST['add_options_combination'][$k]);
$product_code = fn_get_product_code($_REQUEST['product_id'], $_REQUEST['add_options_combination'][$k]);
$_data = array('product_id' => $_REQUEST['product_id'], 'combination_hash' => $combination_hash, 'combination' => $combination, 'product_code' => !empty($product_code) ? $product_code : '');
$_data = fn_array_merge($v, $_data);
db_query("REPLACE INTO ?:product_options_inventory ?e", $_data);
}
}
$suffix = ".inventory?product_id={$_REQUEST['product_id']}";
}
if ($mode == 'update_combinations') {
// Updating images
fn_attach_image_pairs('combinations', 'product_option', 0, CART_LANGUAGE, array());
$inventory = db_get_hash_array("SELECT * FROM ?:product_options_inventory WHERE product_id = ?i", 'combination_hash', $_REQUEST['product_id']);
foreach ($inventory as $i) {
$inventory_ids[] = $i['combination_hash'];
示例8: elseif
} elseif ($mode == 'ls_reload_product_data') {
//get page product details
//get the product id
if (!isset($_REQUEST['product_data'][$product['product_id']]['product_id'])) {
$product_id = reset(array_keys($_REQUEST['product_data']));
$_REQUEST['product_data'][$product['product_id']]['product_id'] = $product_id;
} else {
$product_id = $_REQUEST['product_data'][$product['product_id']]['product_id'];
}
//get the combination hash
$combination_hash = fn_generate_cart_id($product_id, $_REQUEST['product_data'][$product_id], true);
//check if the combination hash exists
if (!$combination_hash) {
//product with no options
//use cart combination hash
$combination_hash = fn_generate_cart_id($product['product_id'], $_REQUEST['product_data'][$product['product_id']], false);
// echo 'cart combination hash is ' . $product['combination_hash'];
}
//copy the product id
$ls_current_page_product[$combination_hash]['product_id'] = $product_id;
//assign the db hash
$ls_current_page_product[$combination_hash]['ls_db_hash'] = $combination_hash;
//assign the product options
foreach ($_REQUEST['product_data'][$product_id] as $option_id => $variant_id) {
$ls_current_page_product[$combination_hash]['product_options'][$option_id]['value'] = $variant_id;
}
//tests
$ls_msg['product_id'] = $product_id;
$ls_msg['combination_hash'] = $combination_hash;
//get product trackig and available since
$ls_current_page_product[$combination_hash]['tracking'] = db_get_field('SELECT tracking FROM ?:products WHERE product_id = ?i', $product_id);
示例9: fn_add_product_to_cart
function fn_add_product_to_cart($product_data, &$cart, &$auth, $update = false)
{
$ids = array();
if (!empty($product_data) && is_array($product_data)) {
if (!defined('GET_OPTIONS')) {
list($product_data, $cart) = fn_add_product_options_files($product_data, $cart, $auth, $update);
}
fn_set_hook('pre_add_to_cart', $product_data, $cart, $auth, $update);
foreach ($product_data as $key => $data) {
if (empty($key)) {
continue;
}
if (empty($data['amount'])) {
continue;
}
$data['stored_price'] = !empty($data['stored_price']) && AREA != 'C' ? $data['stored_price'] : 'N';
if (empty($data['extra'])) {
$data['extra'] = array();
}
$product_id = !empty($data['product_id']) ? $data['product_id'] : $key;
// Check if product options exist
if (!isset($data['product_options'])) {
$data['product_options'] = fn_get_default_product_options($product_id);
}
// Generate cart id
$data['extra']['product_options'] = $data['product_options'];
$_id = fn_generate_cart_id($product_id, $data['extra'], false);
if (isset($data['extra']['exclude_from_calculate'])) {
if (!empty($cart['products'][$key]) && !empty($cart['products'][$key]['extra']['aoc'])) {
$cart['saved_product_options'][$cart['products'][$key]['extra']['saved_options_key']] = $data['product_options'];
}
if (isset($cart['deleted_exclude_products'][$data['extra']['exclude_from_calculate']][$_id])) {
continue;
}
}
$amount = fn_normalize_amount(@$data['amount']);
if (!isset($data['extra']['exclude_from_calculate'])) {
if ($data['stored_price'] != 'Y') {
// Check if the product price with options modifiers equals to zero
$price = fn_get_product_price($product_id, $amount, $auth);
$price = fn_apply_options_modifiers($data['product_options'], $price, 'P');
if (!floatval($price)) {
$data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
$zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $product_id);
if (($zero_price_action == 'R' || $zero_price_action == 'A' && floatval($data['price']) < 0) && AREA == 'C') {
if ($zero_price_action == 'A') {
fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('incorrect_price_warning'));
}
continue;
}
$price = empty($data['price']) ? 0 : $data['price'];
}
} else {
$price = empty($data['price']) ? 0 : $data['price'];
}
} else {
$price = 0;
}
$data['is_edp'] = db_get_field('SELECT is_edp FROM ?:products WHERE product_id = ?i', $product_id);
if (!isset($cart['products'][$_id])) {
// If product doesn't exists in the cart
$amount = empty($data['original_amount']) ? fn_check_amount_in_stock($product_id, $amount, $data['product_options'], $_id, $data['is_edp'], 0, $cart, $update == true ? $key : 0) : $data['original_amount'];
if ($amount === false) {
continue;
}
$cart['products'][$_id]['product_id'] = $product_id;
$cart['products'][$_id]['amount'] = $amount;
$cart['products'][$_id]['product_options'] = $data['product_options'];
$cart['products'][$_id]['price'] = $price;
$cart['products'][$_id]['stored_price'] = $data['stored_price'];
fn_define_original_amount($product_id, $_id, $cart['products'][$_id], $data);
if ($update == true && $key != $_id) {
unset($cart['products'][$key]);
}
} else {
// If product is already exist in the cart
$_initial_amount = empty($cart['products'][$_id]['original_amount']) ? $cart['products'][$_id]['amount'] : $cart['products'][$_id]['original_amount'];
// If ID changed (options were changed), summ the total amount of old and new products
if ($update == true && $key != $_id) {
$amount += $_initial_amount;
unset($cart['products'][$key]);
}
$cart['products'][$_id]['amount'] = fn_check_amount_in_stock($product_id, ($update == true ? 0 : $_initial_amount) + $amount, $data['product_options'], $_id, !empty($data['is_edp']) && $data['is_edp'] == 'Y' ? 'Y' : 'N', 0, $cart, $update == true ? $key : 0);
}
$cart['products'][$_id]['extra'] = empty($data['extra']) ? array() : $data['extra'];
$cart['products'][$_id]['stored_discount'] = @$data['stored_discount'];
if (defined('ORDER_MANAGEMENT')) {
$cart['products'][$_id]['discount'] = @$data['discount'];
}
// Increase product popularity
if (empty($_SESSION['products_popularity']['added'][$product_id])) {
$_data = array('product_id' => $product_id, 'added' => 1, 'total' => POPULARITY_ADD_TO_CART);
db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE added = added + 1, total = total + ?i", $_data, POPULARITY_ADD_TO_CART);
$_SESSION['products_popularity']['added'][$product_id] = true;
}
$company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $product_id);
$cart['products'][$_id]['company_id'] = $company_id;
fn_set_hook('add_to_cart', $cart, $product_id, $_id);
$ids[$_id] = $product_id;
}
//.........这里部分代码省略.........
示例10: fn_buy_together_update_cart_products_post
/**
* Update buy together products
*
* @param array $cart Array of cart content and user information necessary for purchase
* @param array $product_data Array of new products data
* @param array $auth Array of user authentication data (e.g. uid, usergroup_ids, etc.)
* @return boolean Always true
*/
function fn_buy_together_update_cart_products_post(&$cart, &$product_data, &$auth)
{
if (!empty($cart['products'])) {
foreach ($cart['products'] as $_id => $product) {
if (!empty($product['extra']['buy_together']) && !empty($product['prev_cart_id']) && $product['prev_cart_id'] != $_id) {
foreach ($cart['products'] as $aux_id => $aux_product) {
if (!empty($aux_product['extra']['parent']['buy_together']) && $aux_product['extra']['parent']['buy_together'] == $product['prev_cart_id']) {
$cart['products'][$aux_id]['extra']['parent']['buy_together'] = $_id;
$cart['products'][$aux_id]['update_c_id'] = true;
}
}
}
}
foreach ($cart['products'] as $upd_id => $upd_product) {
if (!empty($upd_product['update_c_id']) && $upd_product['update_c_id'] == true) {
$new_id = fn_generate_cart_id($upd_product['product_id'], $upd_product['extra'], false);
if (!isset($cart['products'][$new_id])) {
unset($upd_product['update_c_id']);
$cart['products'][$new_id] = $upd_product;
unset($cart['products'][$upd_id]);
foreach ($cart['product_groups'] as $key_group => $group) {
if (in_array($upd_id, array_keys($group['products']))) {
unset($cart['product_groups'][$key_group]['products'][$upd_id]);
$cart['product_groups'][$key_group]['products'][$new_id] = $upd_product;
}
}
// update taxes
fn_update_stored_cart_taxes($cart, $upd_id, $new_id, false);
}
}
}
}
return true;
}
示例11: fn_update_option_combination
/**
* Updates/Creates options combination
*
* @param array $combination_data Combination data
* @param string $combination_hash Combination hash
* @return string Combination hash
*/
function fn_update_option_combination($combination_data, $combination_hash = 0)
{
/**
* Change parameters for updating options combination
*
* @param array $combination_data Combination data
* @param string $combination_hash Combination hash
*/
fn_set_hook('update_option_combination_pre', $combination_data, $combination_hash);
$inventory_amount = db_get_field('SELECT amount FROM ?:product_options_inventory WHERE combination_hash = ?s', $combination_hash);
if (empty($combination_hash)) {
$combination_hash = fn_generate_cart_id($combination_data['product_id'], array('product_options' => $combination_data['combination']));
$combination = fn_get_options_combination($combination_data['combination']);
$product_code = fn_get_product_code($combination_data['product_id'], $combination_data['combination']);
$_data = array('product_id' => $combination_data['product_id'], 'combination_hash' => $combination_hash, 'combination' => $combination, 'product_code' => !empty($product_code) ? $product_code : '', 'amount' => !empty($combination_data['amount']) ? $combination_data['amount'] : 0, 'position' => !empty($combination_data['position']) ? $combination_data['position'] : 0);
db_query("REPLACE INTO ?:product_options_inventory ?e", $_data);
} else {
// Forbid to update options in the existing combination. Only qty/code/pos.
unset($combination_data['combination']);
db_query("UPDATE ?:product_options_inventory SET ?u WHERE combination_hash = ?s", $combination_data, $combination_hash);
}
if (isset($combination_data['amount']) && $combination_data['amount'] > 0 && $inventory_amount <= 0) {
fn_send_product_notifications($combination_data['product_id']);
}
// Updating images
fn_attach_image_pairs('combinations', 'product_option');
/**
* Makes extra actions after updating options combination
*
* @param array $combination_data Combination data
* @param string $combination_hash Combination hash
* @param int $inventory_amount Previous (before update) inventory amount of the combination
*/
fn_set_hook('update_option_combination_pre', $combination_data, $combination_hash, $inventory_amount);
return $combination_hash;
}
示例12: fn_add_product_to_wishlist
/**
* Add product to wishlist
*
* @param array $product_data array with data for the product to add)(product_id, price, amount, product_options, is_edp)
* @param array $wishlist wishlist data storage
* @param array $auth user session data
* @return mixed array with wishlist IDs for the added products, false otherwise
*/
function fn_add_product_to_wishlist($product_data, &$wishlist, &$auth)
{
// Check if products have cusom images
list($product_data, $wishlist) = fn_add_product_options_files($product_data, $wishlist, $auth, false, 'wishlist');
fn_set_hook('pre_add_to_wishlist', $product_data, $wishlist, $auth);
if (!empty($product_data) && is_array($product_data)) {
$wishlist_ids = array();
foreach ($product_data as $product_id => $data) {
if (empty($data['amount'])) {
$data['amount'] = 1;
}
if (!empty($data['product_id'])) {
$product_id = $data['product_id'];
}
if (empty($data['extra'])) {
$data['extra'] = array();
}
// Add one product
if (!isset($data['product_options'])) {
$data['product_options'] = fn_get_default_product_options($product_id);
}
// Generate wishlist id
$data['extra']['product_options'] = $data['product_options'];
$wishlist_ids[] = $_id = fn_generate_cart_id($product_id, $data['extra']);
$wishlist['products'][$_id]['product_id'] = $product_id;
$wishlist['products'][$_id]['product_options'] = $data['product_options'];
$wishlist['products'][$_id]['extra'] = $data['extra'];
}
return $wishlist_ids;
} else {
return false;
}
}
示例13: unset
unset($_SESSION['shipping_rates']);
if (is_array($cart['products'])) {
$product_data = $_REQUEST['cart_products'];
list($product_data, $cart) = fn_add_product_options_files($product_data, $cart, $customer_auth, true);
unset($product_data['custom_files']);
foreach ($product_data as $k => $v) {
if (!isset($cart['products'][$k]['extra']['exclude_from_calculate'])) {
if (empty($v['extra'])) {
$v['extra'] = array();
}
unset($v['object_id']);
$amount = fn_normalize_amount($v['amount']);
$price = fn_get_product_price($v['product_id'], $amount, $customer_auth);
$v['extra'] = empty($cart['products'][$k]['extra']) ? array() : $cart['products'][$k]['extra'];
$v['extra']['product_options'] = empty($v['product_options']) ? array() : $v['product_options'];
$_id = fn_generate_cart_id($v['product_id'], $v['extra']);
if (!isset($cart['products'][$_id])) {
//if combination doesn't exist in the cart
$cart['products'][$_id] = $v;
$_product = $cart['products'][$k];
fn_define_original_amount($v['product_id'], $_id, $cart['products'][$_id], $_product);
unset($cart['products'][$k]);
} elseif ($k != $_id) {
// if the combination is exist but differs from the current
$amount += $cart['products'][$_id]['amount'];
unset($cart['products'][$k]);
}
if (empty($amount)) {
fn_delete_cart_product($cart, $_id);
continue;
} else {
示例14: generateCombinations
protected function generateCombinations($product)
{
$combinations = array();
if (!empty($product['product_options'])) {
$options = $product['product_options'];
$variants = array();
$variant_ids = array_keys($options);
foreach ($variant_ids as $key => $option_id) {
$variants[$key] = array_keys($options[$option_id]['variants']);
}
$combinations_ids = fn_get_options_combinations($variant_ids, $variants);
$combinations = array();
foreach ($combinations_ids as $key => $combination) {
$combinations[$key] = array('product_id' => $product['product_id'], 'product_code' => $product['product_code'], 'combination_hash' => fn_generate_cart_id($product['product_id'], array('product_options' => $combination)), 'combination' => $combination, 'amount' => $product['amount'], 'temp' => 'Y', 'position' => 0, 'image_pairs' => reset($product['images']));
}
}
return $combinations;
}
示例15: fn_get_selected_product_options_info
$product['product_options_ids'] = $product_options;
$product['product_options'] = fn_get_selected_product_options_info($product_options, CART_LANGUAGE);
$product['price'] = fn_get_product_price($product['product_id'], 1, $auth);
$product['avail_amount'] = $product['amount'] - $product['ordered_amount'];
// selected options combination
$product['product_options_combination'] = fn_get_options_combination($product_options);
fn_gather_additional_product_data($product, true, false, false, true);
// If option combination image is exists than replace the main image with it
$_options = $product_options;
if (!empty($product['product_options']) && is_array($product['product_options'])) {
foreach ($product['product_options'] as $_k => $_v) {
if ($_v['inventory'] == 'N') {
unset($_options[$_v['option_id']]);
}
}
}
$combination_hash = fn_generate_cart_id($product['product_id'], array('product_options' => $_options));
if (!empty($product['option_image_pairs']) && is_array($product['option_image_pairs'])) {
foreach ($product['option_image_pairs'] as $key => $opt_im) {
if ($opt_im['combination_hash'] == $combination_hash) {
$product['main_pair'] = $opt_im;
continue;
}
}
}
}
$view->assign('event_id', $_REQUEST['event_id']);
$view->assign('event_data', $event_data);
} elseif ($mode == 'access_key') {
fn_add_breadcrumb(fn_get_lang_var('access_key'));
}