Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
if ($mode == 'picker') {
    $params = $_REQUEST;
    $params['extend'] = array('description');
    $params['skip_view'] = 'Y';
    list($products, $search) = fn_get_products($params, AREA == 'C' ? Registry::get('settings.Appearance.products_per_page') : Registry::get('settings.Appearance.admin_products_per_page'));
    if (!empty($_REQUEST['display']) || AREA == 'C' && !defined('EVENT_OWNER')) {
        fn_gather_additional_products_data($products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => true));
    }
    if (!empty($products)) {
        foreach ($products as $product_id => $product_data) {
            $products[$product_id]['options'] = fn_get_product_options($product_data['product_id'], DESCR_SL, true, false, true);
            if (!fn_allowed_for('ULTIMATE:FREE')) {
                $products[$product_id]['exceptions'] = fn_get_product_exceptions($product_data['product_id']);
                if (!empty($products[$product_id]['exceptions'])) {
                    foreach ($products[$product_id]['exceptions'] as $exceptions_data) {
                        $products[$product_id]['exception_combinations'][fn_get_options_combination($exceptions_data['combination'])] = '';
                    }
                }
            }
        }
    }
    $product_option_variants_link = array();
    if ($_REQUEST['linked_product_id']) {
        $product_option_variants_link = db_get_row("SELECT * FROM ?:product_option_variants_link WHERE product_id=?i AND option_variant_id=?i", $_REQUEST['linked_product_id'], $_REQUEST['option_variant']);
    }
    Registry::get('view')->assign('products_linked_to_option_variant', $product_option_variants_link);
    Registry::get('view')->assign('products', $products);
    Registry::get('view')->assign('search', $search);
    if (isset($_REQUEST['company_id'])) {
        Registry::get('view')->assign('picker_selected_company', $_REQUEST['company_id']);
    }
Ejemplo n.º 3
0
                 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'];
     }
function fn_exim_put_product_combination($product_id, $product_name, $combination_code, $combination, $amount, &$counter, $set_delimiter, $lang_code)
{
    $pair_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], $lang_code);
        }
        if (empty($object_id)) {
            $counter['S']++;
            return false;
        }
        $options = array();
        $_options = explode($set_delimiter, $combination);
        foreach ($_options as $key => $value) {
            $options[$key][$lang_code] = $value;
        }
        if (!empty($options)) {
            $_combination = array();
            foreach ($options as $option_pair) {
                $pair = explode($pair_delimiter, $option_pair[$lang_code]);
                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);
                    if (empty($option_id)) {
                        // Search for the global product options
                        $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", 0, $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);
                    // Checkboxed do not have descriptions
                    if (empty($variant_id) && in_array($pair[1], array('Yes', 'No'))) {
                        $variant_id = db_get_field("SELECT variant_id FROM ?:product_option_variants WHERE option_id = ?i AND position = ?i LIMIT 1", $option_id, $pair[1] == 'Yes' ? 1 : 0);
                    }
                    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_details = db_get_row('SELECT COUNT(*) as count, amount 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_details['count']) {
                if ($object_details['amount'] <= 0 && $_data['amount'] > 0) {
                    fn_send_product_notifications($object_id);
                }
                db_query('UPDATE ?:product_options_inventory SET ?u WHERE combination_hash = ?i', $_data, $combination_hash);
                fn_set_progress('echo', __('updating') . ' ' . __('product_combinations') . '...', false);
                $counter['E']++;
            } else {
                db_query('INSERT INTO ?:product_options_inventory ?e', $_data);
                fn_set_progress('echo', __('creating') . ' ' . __('product_combinations') . '...', false);
                $counter['N']++;
            }
            fn_set_progress('echo', '<b>' . $object_id . '</b>.<br />', false);
            return $combination_hash;
        }
    }
    $counter['S']++;
    return false;
}
Ejemplo n.º 5
0
        fn_set_hook('after_options_calculation', $mode, $data);
        $view->display($display_tpl);
        exit;
    }
}
if ($mode == 'picker') {
    $params = $_REQUEST;
    $params['type'] = 'extended';
    $params['skip_view'] = 'Y';
    list($products, $search) = fn_get_products($params, AREA == 'C' ? Registry::get('settings.Appearance.products_per_page') : Registry::get('settings.Appearance.admin_products_per_page'));
    if (!empty($_REQUEST['display']) || AREA == 'C' && !defined('EVENT_OWNER')) {
        foreach ($products as $k => $v) {
            fn_gather_additional_product_data($products[$k], true, true, true, true);
        }
    }
    if (!empty($products)) {
        foreach ($products as $k => $v) {
            $products[$k]['options'] = fn_get_product_options($v['product_id'], DESCR_SL, true, false, true);
            $products[$k]['exceptions'] = fn_get_product_exceptions($v['product_id']);
            if (!empty($products[$k]['exceptions'])) {
                foreach ($products[$k]['exceptions'] as $v) {
                    $products[$k]['exception_combinations'][fn_get_options_combination($v['combination'])] = '';
                }
            }
        }
    }
    $view->assign('products', $products);
    $view->assign('search', $search);
    $view->display('pickers/products_picker_contents.tpl');
    exit;
}
Ejemplo n.º 6
0
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 = '';
                    if (!empty($offer->{$cml}['product_features']->{$cml}['product_feature'])) {
                        foreach ($offer->{$cml}['product_features']->{$cml}['product_feature'] as $feature_data) {
                            $variant_name .= strval($feature_data->{$cml}['name']) . ':' . strval($feature_data->{$cml}['value']) . '; ';
                        }
                    }
                    $options_data[$product_id][] = array('variant_name' => $variant_name, 'amount' => $amount, 'combination_guid' => $combination_guid, 'price' => $prices['base_price']);
                    if (!empty($prices['base_price'])) {
                        fn_exim_1c_add_price(array('base_price' => 0), $product_id);
                    }
                } elseif ($import_mode == 'global_option') {
                    $combination = array();
                    foreach ($offer->{$cml}['product_features']->{$cml}['product_feature'] as $feature_data) {
                        if (isset($global_options_data[strval($feature_data->{$cml}['name'])])) {
                            if (!in_array(strval($feature_data->{$cml}['value']), $global_options_data[strval($feature_data->{$cml}['name'])]['variants'])) {
                                $global_options_data[strval($feature_data->{$cml}['name'])]['variants'][] = strval($feature_data->{$cml}['value']);
                            }
                            if (!in_array($product_id, $global_options_data[strval($feature_data->{$cml}['name'])]['product_ids'])) {
                                $global_options_data[strval($feature_data->{$cml}['name'])]['product_ids'][] = $product_id;
                            }
                        } else {
                            $global_options_data[strval($feature_data->{$cml}['name'])]['variants'][] = strval($feature_data->{$cml}['value']);
                            $global_options_data[strval($feature_data->{$cml}['name'])]['product_ids'][] = $product_id;
                        }
                        $combination[] = array('option_name' => strval($feature_data->{$cml}['name']), 'variant_name' => strval($feature_data->{$cml}['value']));
                    }
                    $options_data[$product_id][] = array('combination' => $combination, 'amount' => $amount, 'combination_guid' => $combination_guid);
                } elseif ($import_mode == 'individual_option') {
                    $combination = array();
                    foreach ($offer->{$cml}['product_features']->{$cml}['product_feature'] as $feature_data) {
                        $combination[] = array('option_name' => strval($feature_data->{$cml}['name']), 'variant_name' => strval($feature_data->{$cml}['value']));
                    }
                    $options_data[$product_id][] = array('combination' => $combination, 'amount' => $amount, 'combination_guid' => $combination_guid);
                }
            }
        }
        if ($schema_version == '2.07') {
            return;
        }
        if ($import_mode == 'standart') {
            foreach ($options_data as $pid => $variants_data) {
                $option_id = db_get_field("SELECT option_id FROM ?:product_options WHERE product_id = ?i", $pid);
                $option_id = empty($option_id) ? 0 : $option_id;
                $option_data = fn_exim_1c_create_option_structure($pid, $standart_option_name, $company_id, $type_option);
                foreach ($variants_data as $variant_data) {
                    $variant_id = db_get_field("SELECT variants.variant_id FROM ?:product_option_variants AS variants " . "LEFT JOIN ?:product_option_variants_descriptions AS variants_descriptions ON variants.variant_id = variants_descriptions.variant_id " . "WHERE variants.option_id = ?i AND variants_descriptions.lang_code = ?s AND variants_descriptions.variant_name = ?s", $option_id, $lang_code, $variant_data['variant_name']);
                    $variant_id = empty($variant_id) ? 0 : $variant_id;
                    $option_data['variants'][] = array('variant_name' => $variant_data['variant_name'], 'variant_id' => $variant_id, 'modifier_type' => 'A', 'modifier' => $variant_data['price'], 'weight_modifier' => 0, 'weight_modifier_type' => 'A', 'external_id' => $variant_data['combination_guid']);
                }
                $option_id = fn_update_product_option($option_data, $option_id, $lang_code);
                $empty_stock = true;
                foreach ($variants_data as $variant_data) {
                    $variant_id = db_get_field("SELECT variant_id FROM ?:product_option_variants WHERE external_id = ?s AND option_id = ?i", $variant_data['combination_guid'], $option_id);
                    $old_combination_hash = db_get_field("SELECT combination_hash FROM ?:product_options_inventory WHERE external_id = ?s", $variant_data['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", $variant_data['combination_guid'], $pid);
                    $combination_data = array('product_id' => $pid, 'combination_hash' => fn_generate_cart_id($pid, array('product_options' => array($option_id => $variant_id))), 'combination' => fn_get_options_combination(array($option_id => $variant_id)), 'amount' => $variant_data['amount'], 'external_id' => $variant_data['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);
                    }
                    if ($variant_data['amount'] > 0) {
                        $empty_stock = false;
                    }
                }
                // To hide products if they are out of stock
                if ($hide_product == 'Y') {
                    if ($empty_stock) {
                        db_query("UPDATE ?:products SET status = 'H' WHERE product_id = ?i", $pid);
                    }
                }
            }
        } elseif ($import_mode == 'global_option') {
            foreach ($global_options_data as $option => &$global_option_data) {
                $option_id = db_get_field("SELECT options.option_id FROM ?:product_options AS options " . "LEFT JOIN ?:product_options_descriptions AS options_descriptions ON options.option_id = options_descriptions.option_id " . "WHERE options.product_id = 0 AND options_descriptions.option_name = ?s", $option);
                $option_id = empty($option_id) ? 0 : $option_id;
                $option_data = fn_exim_1c_create_option_structure(0, $option, $company_id, $type_option);
                if ($option_id != 0) {
                    $old_variants = db_get_fields("SELECT variants_descriptions.variant_name FROM ?:product_option_variants AS variants " . "LEFT JOIN ?:product_option_variants_descriptions AS variants_descriptions ON variants.variant_id = variants_descriptions.variant_id " . "WHERE variants.option_id = ?i AND variants_descriptions.lang_code = ?s", $option_id, $lang_code);
                    $old_variants = array_diff($old_variants, $global_option_data['variants']);
                    $global_option_data['variants'] = fn_array_merge($global_option_data['variants'], $old_variants);
                }
                foreach ($global_option_data['variants'] as $variant) {
                    $variant_id = db_get_field("SELECT variants.variant_id FROM ?:product_option_variants AS variants " . "LEFT JOIN ?:product_option_variants_descriptions AS variants_descriptions ON variants.variant_id = variants_descriptions.variant_id " . "WHERE variants.option_id = ?i AND variants_descriptions.lang_code = ?s AND variants_descriptions.variant_name = ?s", $option_id, $lang_code, $variant);
                    $variant_id = empty($variant_id) ? 0 : $variant_id;
                    $option_data['variants'][] = array('variant_name' => $variant, 'variant_id' => $variant_id, 'modifier_type' => 'A', 'modifier' => 0, 'weight_modifier' => 0, 'weight_modifier_type' => 'A');
                }
                $option_id = fn_update_product_option($option_data, $option_id, $lang_code);
                $global_option_data['option_id'] = $option_id;
                foreach ($global_option_data['product_ids'] as $product_id) {
                    db_query("REPLACE INTO ?:product_global_option_links ?e", array('option_id' => $option_id, 'product_id' => $product_id));
                }
            }
            foreach ($options_data as $pid => $combinations) {
                foreach ($combinations as $_combination_data) {
                    $add_options_combination = array();
                    foreach ($_combination_data['combination'] as $combination) {
                        $option_id = $global_options_data[$combination['option_name']]['option_id'];
                        $variant_id = db_get_field("SELECT variants_descriptions.variant_id FROM ?:product_option_variants AS variants " . "LEFT JOIN ?:product_option_variants_descriptions AS variants_descriptions ON variants.variant_id = variants_descriptions.variant_id " . "WHERE lang_code = ?s AND option_id = ?i AND variant_name = ?s", $lang_code, $option_id, $combination['variant_name']);
                        $add_options_combination[$option_id] = $variant_id;
                    }
                    $old_combination_hash = db_get_field("SELECT combination_hash FROM ?:product_options_inventory WHERE external_id = ?s", $_combination_data['combination_guid']);
                    $image_pair_id = db_get_field("SELECT pair_id FROM ?:images_links WHERE object_id = ?i", $old_combination_hash);
                    $empty_stock = true;
                    db_query("DELETE FROM ?:product_options_inventory WHERE external_id = ?s AND product_id = ?i", $_combination_data['combination_guid'], $pid);
                    $combination_data = array('product_id' => $pid, 'combination_hash' => fn_generate_cart_id($pid, array('product_options' => $add_options_combination)), 'combination' => fn_get_options_combination($add_options_combination), 'amount' => $_combination_data['amount'], 'external_id' => $_combination_data['combination_guid']);
                    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);
                    }
                    if ($combination_data['amount'] > 0) {
                        $empty_stock = false;
                    }
                }
                // To hide products if they are out of stock
                if ($hide_product == 'Y') {
                    if ($empty_stock) {
                        db_query("UPDATE ?:products SET status = 'H' WHERE product_id = ?i", $pid);
                    }
                }
            }
        } elseif ($import_mode == 'individual_option') {
            foreach ($options_data as $pid => $combinations) {
                foreach ($combinations as $_combination_data) {
                    $add_options_combination = array();
                    foreach ($_combination_data['combination'] as $combination) {
                        $option_id = db_get_field("SELECT options.option_id FROM ?:product_options AS options " . "LEFT JOIN ?:product_options_descriptions AS options_descriptions ON options.option_id = options_descriptions.option_id " . "WHERE options_descriptions.lang_code = ?s AND options_descriptions.option_name = ?s AND options.product_id = ?i", $lang_code, $combination['option_name'], $pid);
                        $option_id = empty($option_id) ? 0 : $option_id;
                        $option_data = fn_exim_1c_create_option_structure($pid, $combination['option_name'], $company_id, $type_option);
                        $option_id = fn_update_product_option($option_data, $option_id, $lang_code);
                        $variant_id = db_get_field("SELECT variants_descriptions.variant_id FROM ?:product_option_variants AS variants " . "LEFT JOIN ?:product_option_variants_descriptions AS variants_descriptions ON variants.variant_id = variants_descriptions.variant_id " . "WHERE variants_descriptions.lang_code = ?s AND variants.option_id = ?i AND variants_descriptions.variant_name = ?s", $lang_code, $option_id, $combination['variant_name']);
                        if (empty($variant_id)) {
                            $variant = array('option_id' => $option_id, 'modifier_type' => 'A', 'modifier' => 0, 'weight_modifier' => 0, 'weight_modifier_type' => 'A');
                            $variant_id = db_query("INSERT INTO ?:product_option_variants ?e", $variant);
                            $variant = array('variant_id' => $variant_id, 'variant_name' => $combination['variant_name'], 'lang_code' => $lang_code);
                            db_query("INSERT INTO ?:product_option_variants_descriptions ?e", $variant);
                        }
                        $add_options_combination[$option_id] = $variant_id;
                    }
                    $old_combination_hash = db_get_field("SELECT combination_hash FROM ?:product_options_inventory WHERE external_id = ?s", $_combination_data['combination_guid']);
                    $image_pair_id = db_get_field("SELECT pair_id FROM ?:images_links WHERE object_id = ?i", $old_combination_hash);
                    $empty_stock = true;
                    db_query("DELETE FROM ?:product_options_inventory WHERE external_id = ?s AND product_id = ?i", $_combination_data['combination_guid'], $pid);
                    $combination_data = array('product_id' => $pid, 'combination_hash' => fn_generate_cart_id($pid, array('product_options' => $add_options_combination)), 'combination' => fn_get_options_combination($add_options_combination), 'amount' => $_combination_data['amount'], 'external_id' => $_combination_data['combination_guid']);
                    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);
                    }
                    if ($combination_data['amount'] > 0) {
                        $empty_stock = false;
                    }
                }
                // To hide products if they are out of stock
                if ($hide_product == 'Y') {
                    if ($empty_stock) {
                        db_query("UPDATE ?:products SET status = 'H' WHERE product_id = ?i", $pid);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 7
0
/**
 * 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;
    }
}
Ejemplo n.º 8
0
function fn_look_through_variants_prices($product_id, $options, $variants)
{
    $product = fn_get_product_data($product_id, $_SESSION['auth'], CART_LANGUAGE, '', true, true, true, true, $auth['area'] == 'A' && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'preview');
    $product['product_options'] = fn_get_product_options(array($product_id), CART_LANGUAGE);
    $product = fn_apply_options_rules($product);
    //var_dump($product['product_options']);
    $position = 0;
    $hashes = array();
    $combinations = fn_get_options_combinations($options, $variants);
    //var_dump($combinations);
    foreach ($combinations as $key => $combination) {
        $flagToUnsetArrayElement = 0;
        $productArrayOtionsVariants = fn_get_options_variants_by_option_variant_id($product_id, $combination);
        foreach ($combination as $optionId => $variantId) {
            if ($productArrayOtionsVariants[$optionId] && !in_array($variantId, $productArrayOtionsVariants[$optionId])) {
                $flagToUnsetArrayElement = 1;
            }
        }
        if ($flagToUnsetArrayElement == 1) {
            unset($combinations[$key]);
        }
    }
    //var_dump($combinations);
    if (!empty($combinations)) {
        foreach ($combinations as $combination) {
            $_data = array();
            $_data['product_id'] = $product_id;
            $_data['combination_hash'] = fn_generate_cart_id($product_id, array('product_options' => $combination));
            if (array_search($_data['combination_hash'], $hashes) === false) {
                $hashes[] = $_data['combination_hash'];
                $_data['combination'] = fn_get_options_combination($combination);
                $product['product_options'] = fn_get_selected_product_options($product['product_id'], $combination, CART_LANGUAGE);
                $product = fn_apply_options_rules($product);
                $_data['price'] = fn_calculate_price_of_a_product($product, $combination);
                $old_data = db_get_row("SELECT combination_hash, price " . "FROM ?:product_options_inventory_prices " . "WHERE product_id = ?i AND combination_hash = ?i AND temp = 1", $product_id, $_data['combination_hash']);
                /**
                 * Changes data before update combination
                 *
                 * @param array $combination Array of combination data
                 * @param array $data Combination data to update
                 * @param int $product_id Product identifier
                 * @param int $amount Default combination amount
                 * @param array $options Array of options identifiers
                 * @param array $variants Array of option variants identifiers arrays in order corresponding to $options parameter
                 */
                db_query("REPLACE INTO ?:product_options_inventory_prices ?e", $_data);
                $combinations[] = $combination;
            }
            echo str_repeat('. ', count($combination));
        }
    }
}
Ejemplo n.º 9
0
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']) && defined('ORDER_MANAGEMENT') ? $data['stored_price'] : 'N';
            if (empty($data['extra'])) {
                $data['extra'] = array();
            }
            $product_id = !empty($data['product_id']) ? intval($data['product_id']) : intval($key);
            if (!fn_check_add_product_to_cart($cart, $data, $product_id)) {
                continue;
            }
            // 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($ids[$_id]) && $key == $_id) {
                continue;
            }
            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') {
                    $allow_add = true;
                    // Check if the product price with options modifiers equals to zero
                    $price = fn_get_product_price($product_id, $amount, $auth);
                    $zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $product_id);
                    if (!floatval($price) && $zero_price_action == 'A') {
                        if (isset($cart['products'][$key]['custom_user_price'])) {
                            $price = $cart['products'][$key]['custom_user_price'];
                        } else {
                            $custom_user_price = empty($data['price']) ? 0 : $data['price'];
                        }
                    }
                    $price = fn_apply_options_modifiers($data['product_options'], $price, 'P', array(), array('product_data' => $data));
                    if (!floatval($price)) {
                        $data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
                        if (($zero_price_action == 'R' || $zero_price_action == 'A' && floatval($data['price']) < 0) && AREA == 'C') {
                            if ($zero_price_action == 'A') {
                                fn_set_notification('E', __('error'), __('incorrect_price_warning'));
                            }
                            $allow_add = false;
                        }
                        $price = empty($data['price']) ? 0 : $data['price'];
                    }
                    /**
                     * Recalculates price and checks if product can be added with the current price
                     *
                     * @param array $data Adding product data
                     * @param float $price Calculated product price
                     * @param boolean $allow_add Flag that determines if product can be added to cart
                     */
                    fn_set_hook('add_product_to_cart_check_price', $data, $price, $allow_add);
                    if (!$allow_add) {
                        continue;
                    }
                } else {
                    $price = empty($data['price']) ? 0 : $data['price'];
                }
            } else {
                $price = 0;
            }
            $_data = db_get_row('SELECT is_edp, options_type, tracking, unlimited_download FROM ?:products WHERE product_id = ?i', $product_id);
            if (isset($_data['is_edp'])) {
                $data['is_edp'] = $_data['is_edp'];
            } elseif (!isset($data['is_edp'])) {
                $data['is_edp'] = 0;
            }
            if (isset($_data['options_type'])) {
                $data['options_type'] = $_data['options_type'];
            }
            if (isset($_data['tracking'])) {
                $data['tracking'] = $_data['tracking'];
            }
            if (isset($_data['unlimited_download'])) {
                $data['extra']['unlimited_download'] = $_data['unlimited_download'];
            }
            // Check the sequential options
            if (!empty($data['tracking']) && $data['tracking'] == ProductTracking::TRACK_WITH_OPTIONS && $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;
                }
            }
            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]['product_code'] = fn_get_product_code($product_id, $data['product_options']);
                $cart['products'][$_id]['product'] = fn_get_product_name($product_id);
                $cart['products'][$_id]['amount'] = $amount;
                $cart['products'][$_id]['product_options'] = $data['product_options'];
                $cart['products'][$_id]['price'] = $price;
                if (!empty($zero_price_action) && $zero_price_action == 'A') {
                    if (isset($custom_user_price)) {
                        $cart['products'][$_id]['custom_user_price'] = $custom_user_price;
                    } elseif (isset($cart['products'][$key]['custom_user_price'])) {
                        $cart['products'][$_id]['custom_user_price'] = $cart['products'][$key]['custom_user_price'];
                    }
                }
                $cart['products'][$_id]['stored_price'] = $data['stored_price'];
                // add image for minicart
                $cart['products'][$_id]['main_pair'] = fn_get_cart_product_icon($product_id, $data);
                fn_define_original_amount($product_id, $_id, $cart['products'][$_id], $data);
                if ($update == true && $key != $_id) {
                    fn_delete_cart_product($cart, $key, false);
                }
            } 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;
                    fn_delete_cart_product($cart, $key, false);
                }
                $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;
            if (!empty($data['saved_object_id'])) {
                $cart['products'][$_id]['object_id'] = $data['saved_object_id'];
            }
            fn_set_hook('add_to_cart', $cart, $product_id, $_id);
            $ids[$_id] = $product_id;
        }
        /**
         * Change product data after adding product to cart
         *
         * @param array $product_data Product data
         * @param array $cart Cart data
         * @param array $auth Auth data
         * @param bool $update Flag the determains if cart data are updated
         */
        fn_set_hook('post_add_to_cart', $product_data, $cart, $auth, $update, $ids);
        $cart['recalculate'] = true;
        if (!empty($cart['chosen_shipping'])) {
            $cart['calculate_shipping'] = true;
            unset($cart['product_groups']);
        }
        return $ids;
    } else {
        return false;
    }
}
Ejemplo n.º 10
0
 public static function addNewCombination($product_id, $combination_id, $add_options_combination, $import_params, $amount = 0)
 {
     $old_combination_hash = db_get_field("SELECT combination_hash FROM ?:product_options_inventory WHERE external_id = ?s", $combination_id);
     $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_id, $product_id);
     $combination_data = array('product_id' => $product_id, 'combination_hash' => fn_generate_cart_id($product_id, array('product_options' => $add_options_combination)), 'combination' => fn_get_options_combination($add_options_combination), 'external_id' => $combination_id);
     if (isset($amount)) {
         $combination_data['amount'] = $amount;
         self::addProductOptionException($add_options_combination, $product_id, $import_params, $amount);
     }
     $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("REPLACE INTO ?:product_options_inventory ?e", $combination_data);
     } else {
         db_query("UPDATE ?:product_options_inventory SET ?u WHERE combination_hash = ?i", $combination_data, $combination_data['combination_hash']);
     }
     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);
     }
 }
Ejemplo n.º 11
0
    fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_event_unsubscribe'));
    return array(CONTROLLER_STATUS_REDIRECT, "events.search");
} elseif ($mode == 'view') {
    $event_data = db_get_row("SELECT * FROM ?:giftreg_events WHERE event_id = ?i", $_REQUEST['event_id']);
    fn_add_breadcrumb($event_data['title']);
    $event_data['fields'] = db_get_hash_single_array("SELECT * FROM ?:giftreg_event_fields WHERE ?:giftreg_event_fields.event_id = ?i", array('field_id', 'value'), $_REQUEST['event_id']);
    $event_data['products'] = fn_get_event_product($_REQUEST['event_id'], Registry::get('settings.Appearance.products_per_page'), empty($_REQUEST['page']) ? 1 : $_REQUEST['page']);
    foreach ($event_data['products'] as $k => &$product) {
        $product['extra'] = unserialize($product['extra']);
        $product_options = $product['extra'];
        $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;
Ejemplo n.º 12
0
function fn_price_list_print_products($params, &$worksheet, &$counter, &$row, &$width, $selected_fields, $price_schema, $styles)
{
    $worksheet->getRowDimension($row)->setRowHeight(FIELD_HEADING_HEIGHT);
    $col = 'A';
    foreach ($selected_fields as $field => $active) {
        $worksheet->setCellValue($col . $row, $price_schema['fields'][$field]['title']);
        $worksheet->getStyle($col . $row)->applyFromArray($styles['field_heading']);
        if (!isset($width[$col]) || $width[$col] < strlen($price_schema['fields'][$field]['title'])) {
            $width[$col] = strlen($price_schema['fields'][$field]['title']);
        }
        $col++;
    }
    $row++;
    $total = ITEMS_PER_PAGE;
    $fill = true;
    while (ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) {
        list($products, $search) = fn_get_products($params, ITEMS_PER_PAGE);
        $total = $search['total_items'];
        $params['page']++;
        $_params = array('get_icon' => true, 'get_detailed' => true, 'get_options' => Registry::get('addons.price_list.include_options') == 'Y' ? true : false, 'get_discounts' => false);
        fn_gather_additional_products_data($products, $_params);
        // Write products information
        foreach ($products as $product) {
            if (Registry::get('addons.price_list.include_options') == 'Y' && $product['has_options']) {
                $product_comb = fn_price_list_get_combination($product);
                if (!empty($selected_fields['image'])) {
                    $default_image = $product['main_pair'];
                    $comb_hashes = db_get_hash_single_array("SELECT oi.combination, oi.combination_hash FROM ?:product_options_inventory AS oi LEFT JOIN ?:images_links as il ON oi.combination_hash = il.object_id AND object_type = ?s WHERE oi.product_id = ?i", array('combination', 'combination_hash'), 'product_option', $product['product_id']);
                    if (!empty($comb_hashes)) {
                        $default_image = fn_get_image_pairs($product['product_id'], 'product', 'M', true, false, CART_LANGUAGE);
                    }
                }
                foreach ($product_comb['combinations'] as $c_id => $c_value) {
                    if (!empty($selected_fields['image'])) {
                        $combination = fn_get_options_combination($c_value);
                        if (!empty($comb_hashes[$combination])) {
                            $product['main_pair'] = fn_get_image_pairs($comb_hashes[$combination], 'product_option', 'M', true, true, CART_LANGUAGE);
                        } else {
                            $product['main_pair'] = $default_image;
                        }
                    }
                    $product['price'] = $product_comb['combination_prices'][$c_id];
                    $product['weight'] = $product_comb['combination_weight'][$c_id];
                    $product['amount'] = $product_comb['combination_amount'][$c_id];
                    $product['product_code'] = $product_comb['combination_code'][$c_id];
                    fn_price_list_print_product_data($product, $worksheet, $row, $width, $selected_fields, $styles, $c_value);
                    $row++;
                }
            } else {
                fn_price_list_print_product_data($product, $worksheet, $row, $width, $selected_fields, $styles);
                $row++;
            }
        }
        $counter->Out();
    }
    return true;
}
Ejemplo n.º 13
0
/**
 * Generates product variants combinations
 *
 * @param int $product_id Product identifier
 * @param int $amount Default combination amount
 * @param array $options Array of option identifiers
 * @param array $variants Array of option variant identifier arrays in the order according to the $options parameter
 * @return array Array of combinations
 */
function fn_look_through_variants($product_id, $amount, $options, $variants)
{
    /**
     * Changes params for getting product variants combinations
     *
     * @param int   $product_id Product identifier
     * @param int   $amount     Default combination amount
     * @param array $options    Array of options identifiers
     * @param array $variants   Array of option variants identifiers arrays in order corresponding to $options parameter
     * @param array $string     Array of combinations values
     * @param int   $cycle      Options and variants key
     */
    fn_set_hook('look_through_variants_pre', $product_id, $amount, $options, $variants);
    $position = 0;
    $hashes = array();
    $combinations = fn_get_options_combinations($options, $variants);
    if (!empty($combinations)) {
        foreach ($combinations as $combination) {
            $_data = array();
            $_data['product_id'] = $product_id;
            $_data['combination_hash'] = fn_generate_cart_id($product_id, array('product_options' => $combination));
            if (array_search($_data['combination_hash'], $hashes) === false) {
                $hashes[] = $_data['combination_hash'];
                $_data['combination'] = fn_get_options_combination($combination);
                $_data['position'] = $position++;
                $old_data = db_get_row("SELECT combination_hash, amount, product_code " . "FROM ?:product_options_inventory " . "WHERE product_id = ?i AND combination_hash = ?i AND temp = 'Y'", $product_id, $_data['combination_hash']);
                $_data['amount'] = isset($old_data['amount']) ? $old_data['amount'] : $amount;
                $_data['product_code'] = isset($old_data['product_code']) ? $old_data['product_code'] : '';
                /**
                 * Changes data before update combination
                 *
                 * @param array $combination Array of combination data
                 * @param array $data Combination data to update
                 * @param int $product_id Product identifier
                 * @param int $amount Default combination amount
                 * @param array $options Array of options identifiers
                 * @param array $variants Array of option variants identifiers arrays in order corresponding to $options parameter
                 */
                fn_set_hook('look_through_variants_update_combination', $combination, $_data, $product_id, $amount, $options, $variants);
                db_query("REPLACE INTO ?:product_options_inventory ?e", $_data);
                $combinations[] = $combination;
            }
            echo str_repeat('. ', count($combination));
        }
    }
    /**
     * Changes the product options combinations
     *
     * @param array $combination Array of combinations
     * @param int   $product_id  Product identifier
     * @param int   $amount      Default combination amount
     * @param array $options     Array of options identifiers
     * @param array $variants    Array of option variants identifiers arrays in order corresponding to $options parameter
     */
    fn_set_hook('look_through_variants_post', $combinations, $product_id, $amount, $options, $variants);
    return $combinations;
}
Ejemplo n.º 14
0
/**
 * 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;
}
Ejemplo n.º 15
0
function fn_look_through_variants($product_id, $amount, $options, $variants, $string, $cycle)
{
    static $position = 0;
    // Look through all variants
    foreach ($variants[$cycle] as $variant_id) {
        if (count($options) - 1 > $cycle) {
            $string[$cycle][$options[$cycle]] = $variant_id;
            $cycle++;
            $combination = fn_look_through_variants($product_id, $amount, $options, $variants, $string, $cycle);
            $cycle--;
            unset($string[$cycle]);
        } else {
            $_combination = array();
            if (!empty($string)) {
                foreach ($string as $val) {
                    foreach ($val as $opt => $var) {
                        $_combination[$opt] = $var;
                    }
                }
            }
            $_combination[$options[$cycle]] = $variant_id;
            $combination[] = $_combination;
        }
    }
    // if any combinations generated than write them to the database
    if (!empty($combination)) {
        foreach ($combination as $k => $v) {
            $_data = array();
            $_data['product_id'] = $product_id;
            $variants = $v;
            $_data['combination_hash'] = fn_generate_cart_id($product_id, array('product_options' => $variants));
            $_data['combination'] = fn_get_options_combination($v);
            $_data['position'] = $position++;
            $__amount = db_get_row("SELECT combination_hash, amount FROM ?:product_options_inventory WHERE product_id = ?i AND combination_hash = ?i AND temp = 'Y'", $product_id, $_data['combination_hash']);
            $_data['amount'] = empty($__amount) ? $amount : $__amount['amount'];
            db_query("REPLACE INTO ?:product_options_inventory ?e", $_data);
            echo str_repeat('. ', count($combination));
        }
    }
    return $combination;
}