Ejemplo n.º 1
0
function fn_product_price_calculator_clone_product_post($product_id, $pid, $orig_name, $new_name)
{
    if (fn_check_price_calc($product_id) == 'Y') {
        $fields = fn_get_fields($product_id);
        if (!empty($fields)) {
            foreach ($fields as $v) {
                $v['product_id'] = $pid;
                db_query('INSERT INTO ?:ppc ?e', $v);
            }
        }
        $formula = db_get_field('SELECT formula FROM ?:ppc_formula WHERE product_id = ?i', $product_id);
        $for_des = fn_get_formula_description($product_id);
        $product_options = fn_get_product_options($product_id, CART_LANGUAGE);
        $new_product_options = fn_get_product_options($pid, CART_LANGUAGE);
        foreach ($product_options as $k => $v) {
            foreach ($new_product_options as $k1 => $v1) {
                if ($v['option_name'] == $v1['option_name']) {
                    $formula = str_replace("[opt_{$k}]", "[opt_{$k1}]", $formula);
                    $formula = str_replace("[optw_{$k}]", "[optw_{$k1}]", $formula);
                    break;
                }
            }
        }
        db_query('INSERT INTO ?:ppc_formula VALUES (?i, ?s, ?s)', $pid, $formula, $for_des);
    }
}
function fn_exim_set_product_option_exception($product_id, $combinations, &$counter, $set_delimiter, $lang_code)
{
    static $_product_id = 0;
    static $_product_option = array();
    $result = array();
    if ($_product_id != $product_id) {
        $_options = fn_get_product_options($product_id, $lang_code);
        foreach ($_options as $option) {
            $_product_option[$option['option_name']] = $option;
            unset($_product_option[$option['option_name']]['variants']);
            foreach ($option['variants'] as $variant) {
                $_product_option[$option['option_name']]['variants'][$variant['variant_name']] = $variant;
            }
        }
    }
    foreach ($combinations as $lang_code => $combination) {
        $combination = explode($set_delimiter, $combination);
        foreach ($combination as $option_variant) {
            list($option, $variant) = explode('=', $option_variant);
            $option = trim($option);
            $variant = trim($variant);
            $option_id = isset($_product_option[$option]) ? $_product_option[$option]['option_id'] : 0;
            if (strpos($variant, '#') !== false) {
                $variant_id = strtolower($variant) == '#no' ? '-2' : '-1';
            } else {
                $variant_id = isset($_product_option[$option]['variants'][$variant]) ? $_product_option[$option]['variants'][$variant]['variant_id'] : 0;
            }
            if (empty($option_id) || empty($variant_id)) {
                $counter['S']++;
                return false;
            }
            $result[$option_id] = $variant_id;
        }
    }
    $combination = array('product_id' => $product_id, 'combination' => serialize($result));
    if (db_get_field('SELECT COUNT(*) FROM ?:product_options_exceptions WHERE combination = ?s', serialize($result)) > 0) {
        $counter['S']++;
    } else {
        db_query('INSERT INTO ?:product_options_exceptions ?e', $combination);
        $counter['N']++;
    }
    return $combination;
}
Ejemplo n.º 3
0
function fn_get_product_options_inventory($params, $items_per_page = 0, $lang_code = DESCR_SL)
{
    $default_params = array('page' => 1, 'product_id' => 0, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:product_options_inventory WHERE product_id = ?i", $params['product_id']);
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $inventory = db_get_array("SELECT * FROM ?:product_options_inventory WHERE product_id = ?i ORDER BY position {$limit}", $params['product_id']);
    foreach ($inventory as $k => $v) {
        $inventory[$k]['combination'] = fn_get_product_options_by_combination($v['combination']);
        $inventory[$k]['image_pairs'] = fn_get_image_pairs($v['combination_hash'], 'product_option', 'M', true, true, $lang_code);
        $inventory[$k]['additional_image_pairs'] = fn_get_image_pairs($v['combination_hash'], 'product_option', 'A', true, true, $lang_code);
    }
    $product_options = fn_get_product_options($params['product_id'], $lang_code, true, true);
    $product_inventory = db_get_field("SELECT tracking FROM ?:products WHERE product_id = ?i", $params['product_id']);
    return array($inventory, $params, $product_options, $product_inventory);
}
Ejemplo n.º 4
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.º 5
0
function fn_add_product_options_files($product_data, &$cart, &$auth, $update = false, $location = 'cart')
{
    // Check if products have cusom images
    if (!$update) {
        $uploaded_data = fn_filter_uploaded_data('product_data');
    } else {
        $uploaded_data = fn_filter_uploaded_data('cart_products');
    }
    // Check for the already uploaded files
    if (!empty($product_data['custom_files']['uploaded'])) {
        foreach ($product_data['custom_files']['uploaded'] as $file_id => $file_data) {
            if (Storage::instance('images')->isExist('sess_data/' . fn_basename($file_data['path']))) {
                $id = $file_data['product_id'] . $file_data['option_id'] . $file_id;
                $uploaded_data[$id] = array('name' => $file_data['name'], 'path' => 'sess_data/' . fn_basename($file_data['path']));
                $product_data['custom_files'][$id] = $file_data['product_id'] . '_' . $file_data['option_id'];
            }
        }
    }
    if (!empty($uploaded_data) && !empty($product_data['custom_files'])) {
        $files_data = array();
        foreach ($uploaded_data as $key => $file) {
            $file_info = fn_pathinfo($file['name']);
            $file['extension'] = empty($file_info['extension']) ? '' : $file_info['extension'];
            $file['is_image'] = fn_get_image_extension($file['type']);
            $_data = explode('_', $product_data['custom_files'][$key]);
            $product_id = empty($_data[0]) ? 0 : $_data[0];
            $option_id = empty($_data[1]) ? 0 : $_data[1];
            $file_id = str_replace($option_id . $product_id, '', $key);
            if (empty($file_id)) {
                $files_data[$product_id][$option_id][] = $file;
            } else {
                $files_data[$product_id][$option_id][$file_id] = $file;
            }
        }
    }
    unset($product_data['custom_files']);
    foreach ($product_data as $key => $data) {
        $product_id = !empty($data['product_id']) ? $data['product_id'] : $key;
        // Check if product has cusom images
        if ($update || isset($files_data[$key])) {
            $hash = $key;
        } else {
            $hash = $product_id;
        }
        $_options = fn_get_product_options($product_id);
        if (!empty($files_data[$hash]) && is_array($files_data[$hash])) {
            foreach ($files_data[$hash] as $option_id => $files) {
                foreach ($files as $file_id => $file) {
                    // Check for the allowed extensions
                    if (!empty($_options[$option_id]['allowed_extensions'])) {
                        if (empty($file['extension']) && !empty($_options[$option_id]['allowed_extensions']) || !preg_match("/\\b" . $file['extension'] . "\\b/i", $_options[$option_id]['allowed_extensions'])) {
                            fn_set_notification('E', __('error'), $file['name'] . ': ' . __('text_forbidden_uploaded_file_extension', array('[ext]' => $file['extension'], '[exts]' => $_options[$option_id]['allowed_extensions'])));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    // Check for the max file size
                    if (!empty($_options[$option_id]['max_file_size'])) {
                        if (empty($file['size'])) {
                            $file['size'] = filesize($file['path']);
                        }
                        if ($file['size'] > $_options[$option_id]['max_file_size'] * 1024) {
                            fn_set_notification('E', __('error'), $file['name'] . ': ' . __('text_forbidden_uploaded_file_size', array('[size]' => $_options[$option_id]['max_file_size'] . ' kb')));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    $_file_path = 'sess_data/file_' . uniqid(TIME);
                    list(, $_file_path) = Storage::instance('custom_files')->put($_file_path, array('file' => $file['path']));
                    if (!$_file_path) {
                        fn_set_notification('E', __('error'), __('text_cannot_create_file', array('[file]' => $file['name'])));
                        unset($files_data[$hash][$option_id][$file_id]);
                        continue;
                    }
                    $file['path'] = $_file_path;
                    $file['file'] = fn_basename($file['path']);
                    if ($file['is_image']) {
                        $file['thumbnail'] = 'image.custom_image?image=' . $file['file'] . '&type=T';
                        $file['detailed'] = 'image.custom_image?image=' . $file['file'] . '&type=D';
                    }
                    $file['location'] = $location;
                    if ($update) {
                        $cart['products'][$key]['extra']['custom_files'][$option_id][] = $file;
                    } else {
                        $data['extra']['custom_files'][$option_id][] = $file;
                    }
                }
                if ($update) {
                    if (!empty($cart['products'][$key]['product_options'][$option_id])) {
                        $cart['products'][$key]['product_options'][$option_id] = md5(serialize($cart['products'][$key]['extra']['custom_files'][$option_id]));
                    }
                } else {
                    if (!empty($data['extra']['custom_files'][$option_id])) {
                        $data['product_options'][$option_id] = md5(serialize($data['extra']['custom_files'][$option_id]));
                    }
                }
            }
            // Check the required options
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && !$update) {
                        if (empty($data['product_options'][$option['option_id']])) {
                            fn_set_notification('E', __('error'), __('product_cannot_be_added'));
                            unset($product_data[$key]);
                            return array($product_data, $cart);
                        }
                    }
                }
            }
        } else {
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && empty($cart['products'][$hash]['extra']['custom_files'][$option['option_id']]) && empty($data['extra']['custom_files'][$option['option_id']])) {
                        fn_set_notification('E', __('error'), __('product_cannot_be_added'));
                        unset($product_data[$key]);
                        return array($product_data, $cart);
                    }
                }
            }
        }
        if ($update) {
            foreach ($_options as $option) {
                if ($option['option_type'] == 'F' && empty($cart['products'][$key]['extra']['custom_files'][$option['option_id']])) {
                    unset($cart['products'][$key]['extra']['custom_files'][$option['option_id']]);
                    unset($cart['products'][$key]['product_options'][$option['option_id']]);
                    unset($data['product_options'][$option['option_id']]);
                }
            }
        }
        if (isset($cart['products'][$key]['extra']['custom_files'])) {
            foreach ($cart['products'][$key]['extra']['custom_files'] as $option_id => $files) {
                foreach ($files as $file) {
                    $data['extra']['custom_files'][$option_id][] = $file;
                }
                $data['product_options'][$option_id] = md5(serialize($files));
            }
        }
        $product_data[$key] = $data;
    }
    return array($product_data, $cart);
}
function fn_exim_get_product_options($product_id, $lang_code = '')
{
    $pair_delimiter = ':';
    $set_delimiter = '; ';
    $vars_delimiter = ',';
    $result = array();
    $options = fn_get_product_options($product_id, $lang_code);
    if (!empty($options)) {
        foreach ($options as $o) {
            $glob_opt = db_get_field("SELECT option_id FROM ?:product_global_option_links WHERE option_id = ?i AND product_id = ?i", $o['option_id'], $product_id);
            $prefix = '';
            if (!empty($o['company_id'])) {
                $company_name = fn_get_company_name($o['company_id']);
                $prefix = '(' . $company_name . ') ';
            }
            $str = $prefix . "{$o['option_name']}{$pair_delimiter} {$o['option_type']}" . (empty($glob_opt) ? '' : 'G');
            $variants = array();
            if (!empty($o['variants'])) {
                foreach ($o['variants'] as $v) {
                    $variants[] = $v['variant_name'];
                }
                $str .= '[' . implode($vars_delimiter, $variants) . ']';
            }
            $result[] = $str;
        }
    }
    return !empty($result) ? implode($set_delimiter, $result) : '';
}
Ejemplo n.º 7
0
 public function index($id = 0, $params = array())
 {
     $lang_code = $this->safeGet($params, 'lang_code', DEFAULT_LANGUAGE);
     if (empty($id) && empty($params['product_id'])) {
         $status = Response::STATUS_BAD_REQUEST;
         $data['message'] = __('api_required_field', array('[field]' => 'product_id'));
     } else {
         $product_id = $this->safeGet($params, 'product_id', 0);
         if (empty($product_id)) {
             $product_id = db_get_field('SELECT product_id FROM ?:product_options WHERE option_id = ?i', $id);
         }
         $product_data = fn_get_product_data($product_id, $this->auth, $lang_code, '', false, false, false, false, false, false, false);
         if (empty($product_data)) {
             $status = Response::STATUS_NOT_FOUND;
             $data = array();
         } else {
             if (!empty($id)) {
                 $data = fn_get_product_option_data($id, $product_id, $lang_code);
                 $status = Response::STATUS_OK;
             } else {
                 $data = fn_get_product_options($product_id, $lang_code);
                 $status = Response::STATUS_OK;
             }
             if (empty($data)) {
                 $status = Response::STATUS_NOT_FOUND;
             }
         }
     }
     return array('status' => $status, 'data' => $data);
 }
Ejemplo n.º 8
0
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['option_id'])) {
        $p_id = db_get_field("SELECT product_id FROM ?:product_options WHERE option_id = ?i", $_REQUEST['option_id']);
        if (!empty($_REQUEST['product_id']) && empty($p_id)) {
            // we're deleting global option from the product
            db_query("DELETE FROM ?:product_global_option_links WHERE product_id = ?i AND option_id = ?i", $_REQUEST['product_id'], $_REQUEST['option_id']);
        } else {
            fn_delete_product_option($_REQUEST['option_id']);
        }
        if (empty($_REQUEST['product_id']) && empty($p_id)) {
            // we're deleting global option itself
            db_query("DELETE FROM ?:product_global_option_links WHERE option_id = ?i", $_REQUEST['option_id']);
        }
    }
    if (!empty($_REQUEST['product_id'])) {
        $_options = fn_get_product_options($_REQUEST['product_id']);
        if (empty($_options)) {
            $view->display('views/product_options/manage.tpl');
        }
        exit;
    }
    return array(CONTROLLER_STATUS_REDIRECT, "product_options.manage");
} elseif ($mode == 'rebuild_combinations') {
    fn_rebuild_product_options_inventory($_REQUEST['product_id']);
    return array(CONTROLLER_STATUS_OK, "product_options.inventory?product_id={$_REQUEST['product_id']}");
} elseif ($mode == 'delete_combination') {
    if (!empty($_REQUEST['combination_hashe'])) {
        fn_delete_image_pairs($_REQUEST['combination_hashe'], 'product_option');
        db_query("DELETE FROM ?:product_options_inventory WHERE combination_hash = ?i", $_REQUEST['combination_hashe']);
    }
    return array(CONTROLLER_STATUS_REDIRECT, "product_options.inventory?product_id={$_REQUEST['product_id']}");
Ejemplo n.º 9
0
    // Update option
    //
} elseif ($mode == 'update') {
    $product_id = !empty($_REQUEST['product_id']) ? $_REQUEST['product_id'] : 0;
    $o_data = fn_get_product_option_data($_REQUEST['option_id'], $product_id);
    if (fn_allowed_for('ULTIMATE') && !empty($_REQUEST['product_id'])) {
        Registry::get('view')->assign('shared_product', fn_ult_is_shared_product($_REQUEST['product_id']));
        Registry::get('view')->assign('product_company_id', db_get_field('SELECT company_id FROM ?:products WHERE product_id = ?i', $_REQUEST['product_id']));
    }
    if (isset($_REQUEST['object'])) {
        Registry::get('view')->assign('object', $_REQUEST['object']);
    }
    Registry::get('view')->assign('option_data', $o_data);
    Registry::get('view')->assign('option_id', $_REQUEST['option_id']);
}
if (!fn_allowed_for('ULTIMATE:FREE')) {
    //
    // Product options exceptions
    //
    if ($mode == 'exceptions') {
        $exceptions = fn_get_product_exceptions($_REQUEST['product_id']);
        $product_options = fn_get_product_options($_REQUEST['product_id'], DESCR_SL, true);
        $product_data = fn_get_product_data($_REQUEST['product_id'], $auth, DESCR_SL, '', true, true, true, true);
        Registry::get('view')->assign('product_options', $product_options);
        Registry::get('view')->assign('exceptions', $exceptions);
        Registry::get('view')->assign('product_data', $product_data);
    }
}
if (!empty($_REQUEST['product_id'])) {
    Registry::get('view')->assign('product_id', $_REQUEST['product_id']);
}
Ejemplo n.º 10
0
function fn_add_product_options_files($product_data, &$cart, &$auth, $update = false, $location = 'cart')
{
    // Check if products have cusom images
    if (!$update) {
        $uploaded_data = fn_filter_uploaded_data('product_data');
    } else {
        $uploaded_data = fn_filter_uploaded_data('cart_products');
    }
    $dir_path = DIR_CUSTOM_FILES . 'sess_data';
    // Check for the already uploaded files
    if (!empty($product_data['custom_files']['uploaded'])) {
        foreach ($product_data['custom_files']['uploaded'] as $file_id => $file_data) {
            if (file_exists($dir_path . '/' . basename($file_data['path']))) {
                $id = $file_data['product_id'] . $file_data['option_id'] . $file_id;
                $uploaded_data[$id] = array('name' => $file_data['name'], 'path' => $dir_path . '/' . basename($file_data['path']));
                $product_data['custom_files'][$id] = $file_data['product_id'] . '_' . $file_data['option_id'];
            }
        }
    }
    if (!empty($uploaded_data) && !empty($product_data['custom_files'])) {
        $files_data = array();
        foreach ($uploaded_data as $key => $file) {
            $file_info = pathinfo($file['name']);
            $file['extension'] = empty($file_info['extension']) ? '' : $file_info['extension'];
            $file_info = getimagesize($file['path']);
            $file['type'] = $file_info['mime'];
            $file['is_image'] = fn_get_image_extension($file_info['mime']);
            $_data = explode('_', $product_data['custom_files'][$key]);
            $product_id = empty($_data[0]) ? 0 : $_data[0];
            $option_id = empty($_data[1]) ? 0 : $_data[1];
            $file_id = str_replace($option_id . $product_id, '', $key);
            if (empty($file_id)) {
                $files_data[$product_id][$option_id][] = $file;
            } else {
                $files_data[$product_id][$option_id][$file_id] = $file;
            }
        }
        if (!is_dir($dir_path)) {
            if (!fn_mkdir($dir_path)) {
                // Unable to create a directory
                fn_set_notification('E', fn_get_lang_var('error'), str_replace('[directory]', DIR_CUSTOM_FILES, fn_get_lang_var('text_cannot_write_directory')));
            }
        }
    }
    unset($product_data['custom_files']);
    foreach ($product_data as $key => $data) {
        $product_id = !empty($data['product_id']) ? $data['product_id'] : $key;
        // Check if product has cusom images
        if ($update || isset($files_data[$key])) {
            $hash = $key;
        } else {
            $hash = $product_id;
        }
        if (!empty($files_data[$hash]) && is_array($files_data[$hash])) {
            $_options = fn_get_product_options($product_id);
            foreach ($files_data[$hash] as $option_id => $files) {
                foreach ($files as $file_id => $file) {
                    // Check for the allowed extensions
                    if (!empty($_options[$option_id]['allowed_extensions'])) {
                        if (empty($file['extension']) && !empty($_options[$option_id]['allowed_extensions']) || !preg_match("/\\b" . $file['extension'] . "\\b/i", $_options[$option_id]['allowed_extensions'])) {
                            $message = fn_get_lang_var('text_forbidden_uploaded_file_extension');
                            $message = str_replace('[ext]', $file['extension'], $message);
                            $message = str_replace('[exts]', $_options[$option_id]['allowed_extensions'], $message);
                            fn_set_notification('E', fn_get_lang_var('error'), $file['name'] . ': ' . $message);
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    // Check for the max file size
                    if (!empty($_options[$option_id]['max_file_size'])) {
                        if (empty($file['size'])) {
                            $file['size'] = filesize($file['path']);
                        }
                        if ($file['size'] > $_options[$option_id]['max_file_size'] * 1024) {
                            fn_set_notification('E', fn_get_lang_var('error'), str_replace('[size]', $_options[$option_id]['max_file_size'] . ' kb', $file['name'] . ': ' . fn_get_lang_var('text_forbidden_uploaded_file_size')));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    $_file_path = tempnam($dir_path, 'file_');
                    if (!fn_copy($file['path'], $_file_path)) {
                        fn_set_notification('E', fn_get_lang_var('error'), str_replace('[file]', $file['name'], fn_get_lang_var('text_cannot_create_file')));
                        unset($files_data[$hash][$option_id][$file_id]);
                        continue;
                    }
                    $file['path'] = $_file_path;
                    $file['file'] = basename($file['path']);
                    if ($file['is_image']) {
                        $file['thumbnail'] = 'image.custom_image&image=' . $file['file'] . '&type=T';
                        $file['detailed'] = 'image.custom_image&image=' . $file['file'] . '&type=D';
                    }
                    $file['location'] = $location;
                    if ($update) {
                        $cart['products'][$key]['extra']['custom_files'][$option_id][] = $file;
                    } else {
                        $data['extra']['custom_files'][$option_id][] = $file;
                    }
                }
                if ($update) {
                    if (!empty($cart['products'][$key]['product_options'][$option_id])) {
                        $cart['products'][$key]['product_options'][$option_id] = md5(serialize($cart['products'][$key]['extra']['custom_files'][$option_id]));
                    }
                } else {
                    if (!empty($data['extra']['custom_files'][$option_id])) {
                        $data['product_options'][$option_id] = md5(serialize($data['extra']['custom_files'][$option_id]));
                    }
                }
            }
            // Check the required options
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && !$update) {
                        if (empty($data['product_options'][$option['option_id']])) {
                            fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('product_cannot_be_added'));
                            unset($product_data[$key]);
                            return array($product_data, $cart);
                        }
                    }
                }
            }
        } else {
            if (empty($data['extra']['parent'])) {
                $_options = fn_get_product_options($product_id);
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && empty($cart['products'][$hash]['extra']['custom_files'][$option['option_id']]) && empty($data['extra']['custom_files'][$option['option_id']])) {
                        fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('product_cannot_be_added'));
                        unset($product_data[$key]);
                        return array($product_data, $cart);
                    }
                }
            }
        }
        if (isset($cart['products'][$key]['extra']['custom_files'])) {
            foreach ($cart['products'][$key]['extra']['custom_files'] as $option_id => $files) {
                foreach ($files as $file) {
                    $data['extra']['custom_files'][$option_id][] = $file;
                }
                $data['product_options'][$option_id] = md5(serialize($files));
            }
        }
        $product_data[$key] = $data;
    }
    return array($product_data, $cart);
}
Ejemplo n.º 11
0
/**
 * Gets default product options
 *
 * @param integer $product_id Product identifier
 * @param bool $get_all Whether to get all the default options or not
 * @param array $product Product data
 * @return array The resulting array
 */
function fn_get_default_product_options($product_id, $get_all = false, $product = array())
{
    $result = $default = $exceptions = $product_options = array();
    $selectable_option_types = array('S', 'R', 'C');
    /**
     * Get default product options ( at the beginning of fn_get_default_product_options() )
     *
     * @param integer $product_id Product id
     * @param bool $get_all Whether to get all the default options or not
     * @param array $product Product data
     * @param array $selectable_option_types Selectable option types
     */
    fn_set_hook('get_default_product_options_pre', $product_id, $get_all, $product, $selectable_option_types);
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        $exceptions = fn_get_product_exceptions($product_id, true);
        $exceptions_type = empty($product['exceptions_type']) ? db_get_field('SELECT exceptions_type FROM ?:products WHERE product_id = ?i', $product_id) : $product['exceptions_type'];
    }
    $track_with_options = empty($product['tracking']) ? db_get_field("SELECT tracking FROM ?:products WHERE product_id = ?i", $product_id) : $product['tracking'];
    if (!empty($product['product_options'])) {
        //filter out only selectable options
        foreach ($product['product_options'] as $option_id => $option) {
            if (in_array($option['option_type'], $selectable_option_types)) {
                $product_options[$option_id] = $option;
            }
        }
    } else {
        $product_options = fn_get_product_options($product_id, CART_LANGUAGE, true);
    }
    if (!empty($product_options)) {
        foreach ($product_options as $option_id => $option) {
            if (!empty($option['variants'])) {
                $default[$option_id] = key($option['variants']);
                foreach ($option['variants'] as $variant_id => $variant) {
                    $options[$option_id][$variant_id] = true;
                }
            }
        }
    } else {
        return array();
    }
    unset($product_options);
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        if (empty($exceptions)) {
            return $default;
        }
    }
    $inventory_combinations = array();
    if ($track_with_options == 'O') {
        $inventory_combinations = db_get_array("SELECT combination FROM ?:product_options_inventory WHERE product_id = ?i AND amount > 0 AND combination != ''", $product_id);
        if (!empty($inventory_combinations)) {
            $_combinations = array();
            foreach ($inventory_combinations as $_combination) {
                $_combinations[] = fn_get_product_options_by_combination($_combination['combination']);
            }
            $inventory_combinations = $_combinations;
            unset($_combinations);
        }
    }
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        if ($exceptions_type == 'F') {
            // Forbidden combinations
            $_options = array_keys($options);
            $_variants = array_values($options);
            if (!empty($_variants)) {
                foreach ($_variants as $key => $variants) {
                    $_variants[$key] = array_keys($variants);
                }
            }
            list($result) = fn_get_allowed_options_combination($_options, $_variants, '', 0, $exceptions, $inventory_combinations);
        } else {
            // Allowed combinations
            foreach ($exceptions as $exception) {
                $result = array();
                foreach ($exception as $option_id => $variant_id) {
                    if (isset($options[$option_id][$variant_id]) || $variant_id == -1) {
                        $result[$option_id] = $variant_id != -1 ? $variant_id : (isset($options[$option_id]) ? key($options[$option_id]) : '');
                    } else {
                        continue 2;
                    }
                }
                $_opt = array_diff_key($options, $result);
                if (!empty($_opt)) {
                    foreach ($_opt as $option_id => $variants) {
                        $result[$option_id] = key($variants);
                    }
                }
                if (empty($inventory_combinations)) {
                    break;
                } else {
                    foreach ($inventory_combinations as $_icombination) {
                        $_res = array_diff($_icombination, $result);
                        if (empty($_res)) {
                            break 2;
                        }
                    }
                }
            }
        }
    }
    /**
     * Get default product options ( at the end of fn_get_default_product_options() )
     *
     * @param integer $product_id Product id
     * @param bool $get_all Whether to get all the default options or not
     * @param array $product Product data
     * @param array $result The resulting array
     */
    fn_set_hook('get_default_product_options_post', $product_id, $get_all, $product, $result);
    return empty($result) ? $default : $result;
}
Ejemplo n.º 12
0
/**
 * Function checks and changes shared product data
 *
 * @param int $product_id Product ID
 */
function fn_check_and_update_product_sharing($product_id)
{
    $shared = false;
    $new_categories_company_ids = db_get_fields("SELECT DISTINCT c.company_id" . " FROM ?:products_categories pc" . " LEFT JOIN ?:categories c ON c.category_id = pc.category_id" . " WHERE pc.product_id = ?i", $product_id);
    $shared_categories_company_ids = db_get_fields("SELECT DISTINCT company_id FROM ?:ult_product_descriptions WHERE product_id = ?i", $product_id);
    $count = count($new_categories_company_ids);
    $company_id = reset($new_categories_company_ids);
    $product_company_id = db_get_field('SELECT company_id FROM ?:products WHERE product_id = ?i', $product_id);
    if ($count == 1 && $company_id == $product_company_id) {
        // product belongs to one store. It is not shared now
        // check that products.company_id == category.company_id
        /* Do not touch product.company_id.
           if ($company_id != $product_company_id) {
               db_query('UPDATE ?:products SET company_id = ?i WHERE product_id = ?i', $company_id, $product_id);
           }*/
        db_query('DELETE FROM ?:ult_product_descriptions WHERE product_id = ?i', $product_id);
        db_query('DELETE FROM ?:ult_product_prices WHERE product_id = ?i', $product_id);
        $product_options = fn_get_product_options($product_id, DESCR_SL, false, false, false, true);
        $product_options = array_keys($product_options);
        if (!empty($product_options)) {
            db_query('DELETE FROM ?:ult_product_option_variants WHERE option_id IN (?a)', $product_options);
        }
    } else {
        $shared = true;
        $new_company_ids = array_diff($new_categories_company_ids, $shared_categories_company_ids);
        if (!empty($new_company_ids)) {
            $product_options = fn_get_product_options($product_id, DESCR_SL, false, false, false, true);
            $product_options = array_keys($product_options);
        }
        foreach ($new_company_ids as $new_cid) {
            // coping owner data to tables with shared data
            db_query('REPLACE INTO ?:ult_product_descriptions (' . ' product_id, lang_code, company_id, product, shortname, short_description,' . ' full_description, meta_keywords, meta_description, search_words, page_title,' . ' age_warning_message, promo_text)' . ' SELECT' . ' product_id, lang_code, ?i, product, shortname, short_description,' . ' full_description, meta_keywords, meta_description, search_words,' . ' page_title, age_warning_message, promo_text' . ' FROM ?:product_descriptions' . ' WHERE product_id = ?i', $new_cid, $product_id);
            db_query('REPLACE INTO ?:ult_product_prices (' . ' product_id, price, percentage_discount, lower_limit, company_id, usergroup_id)' . ' SELECT product_id, price, percentage_discount, lower_limit, ?i, usergroup_id' . ' FROM ?:product_prices' . ' WHERE product_id = ?i', $new_cid, $product_id);
            if (!empty($product_options)) {
                db_query('REPLACE INTO ?:ult_product_option_variants (' . ' variant_id, option_id, company_id, modifier, modifier_type)' . ' SELECT variant_id, option_id, ?i, modifier, modifier_type' . ' FROM ?:product_option_variants' . ' WHERE option_id IN (?a)', $new_cid, $product_options);
            }
        }
        $deleted_company_ids = array_diff($shared_categories_company_ids, $new_categories_company_ids);
        if (!empty($deleted_company_ids)) {
            // deleting data from shared tables
            db_query('DELETE FROM ?:ult_product_descriptions' . ' WHERE product_id = ?i AND company_id IN (?a)', $product_id, $deleted_company_ids);
            db_query('DELETE FROM ?:ult_product_prices' . ' WHERE product_id = ?i AND company_id IN (?a)', $product_id, $deleted_company_ids);
            if (!isset($product_options)) {
                $product_options = fn_get_product_options($product_id, DESCR_SL, false, false, false, true);
                $product_options = array_keys($product_options);
            }
            if (!empty($product_options)) {
                db_query('DELETE FROM ?:ult_product_option_variants' . ' WHERE option_id IN (?a) AND company_id IN (?a)', $product_options, $deleted_company_ids);
            }
        }
        $global_option_links = db_get_fields("SELECT option_id FROM ?:product_global_option_links WHERE product_id = ?i", $product_id);
        $product_options = array_merge(isset($product_options) ? $product_options : array(), $global_option_links);
        if (!empty($product_options)) {
            foreach ($product_options as $po_id) {
                fn_ult_share_product_option($po_id, $product_id);
            }
        }
    }
    $cids = db_get_fields('SELECT category_id FROM ?:products_categories WHERE product_id = ?i', $product_id);
    fn_update_product_count($cids);
    /**
     * Processed addition/deletion of companies product is shared between
     *
     * @param int     $product_id
     * @param boolean $shared
     * @param array   $shared_categories_company_ids
     * @param array   $new_categories_company_ids
     */
    fn_set_hook('check_and_update_product_sharing', $product_id, $shared, $shared_categories_company_ids, $new_categories_company_ids);
}
Ejemplo n.º 13
0
 $view->assign('product_data', $product_data);
 $view->assign('taxes', $taxes);
 $view->assign('companies', fn_get_short_companies());
 $product_options = fn_get_product_options($_REQUEST['product_id'], DESCR_SL);
 if (!empty($product_options)) {
     $has_inventory = false;
     foreach ($product_options as $p) {
         if ($p['inventory'] == 'Y') {
             $has_inventory = true;
             break;
         }
     }
     $view->assign('has_inventory', $has_inventory);
 }
 $view->assign('product_options', $product_options);
 $view->assign('global_options', fn_get_product_options(0));
 // If the product is electronnicaly distributed, get the assigned files
 $view->assign('product_files', fn_get_product_files($_REQUEST['product_id']));
 // [Page sections]
 Registry::set('navigation.tabs', array('detailed' => array('title' => fn_get_lang_var('general'), 'js' => true), 'images' => array('title' => fn_get_lang_var('images'), 'js' => true), 'categories' => array('title' => fn_get_lang_var('additional_categories'), 'js' => true), 'options' => array('title' => fn_get_lang_var('options'), 'js' => true), 'qty_discounts' => array('title' => fn_get_lang_var('qty_discounts'), 'js' => true), 'files' => array('title' => fn_get_lang_var('files'), 'js' => true), 'blocks' => array('title' => fn_get_lang_var('blocks'), 'js' => true), 'addons' => array('title' => fn_get_lang_var('addons'), 'js' => true), 'vendors' => array('title' => fn_get_lang_var('vendors'), 'js' => true)));
 // [/Page sections]
 // If we have some additional product fields, lets add a tab for them
 if (!empty($product_data['product_features'])) {
     Registry::set('navigation.tabs.features', array('title' => fn_get_lang_var('features'), 'js' => true));
 }
 // [Block manager]
 $block_settings = fn_get_all_blocks('products');
 $view->assign('block_settings', $block_settings);
 list($blocks, $object_id) = fn_get_blocks(array('location' => 'products', 'all' => true, 'product_id' => $_REQUEST['product_id']), false, DESCR_SL);
 list($all_blocks) = fn_get_blocks(array('location' => 'all_pages', 'all' => true, 'block_properties_location' => 'products'), false);
 $blocks = fn_array_merge($blocks, $all_blocks, true);
    function content_55dc81a5ed2a88_04135619($_smarty_tpl)
    {
        if (!is_callable('smarty_function_math')) {
            include '/var/www/html/market/app/lib/vendor/smarty/smarty/libs/plugins/function.math.php';
        }
        if (!is_callable('smarty_function_script')) {
            include '/var/www/html/market/app/functions/smarty_plugins/function.script.php';
        }
        if (!is_callable('smarty_block_hook')) {
            include '/var/www/html/market/app/functions/smarty_plugins/block.hook.php';
        }
        fn_preload_lang_vars(array('add_product', 'position_short', 'name', 'deleted_product', 'no_items', 'editing_defined_products', 'defined_items', 'name', 'quantity', 'options', 'any_option_combinations', 'deleted_product', 'no_items', 'add_products', 'add_products'));
        echo smarty_function_math(array('equation' => "rand()", 'assign' => "rnd"), $_smarty_tpl);
        ?>

<?php 
        $_smarty_tpl->tpl_vars["data_id"] = new Smarty_variable((string) $_smarty_tpl->tpl_vars['data_id']->value . "_" . (string) $_smarty_tpl->tpl_vars['rnd']->value, null, 0);
        $_smarty_tpl->tpl_vars["view_mode"] = new Smarty_variable(($tmp = @$_smarty_tpl->tpl_vars['view_mode']->value) === null || $tmp === '' ? "mixed" : $tmp, null, 0);
        $_smarty_tpl->tpl_vars["start_pos"] = new Smarty_variable(($tmp = @$_smarty_tpl->tpl_vars['start_pos']->value) === null || $tmp === '' ? 0 : $tmp, null, 0);
        echo smarty_function_script(array('src' => "js/tygh/picker.js"), $_smarty_tpl);
        ?>


<?php 
        if ($_smarty_tpl->tpl_vars['item_ids']->value && !is_array($_smarty_tpl->tpl_vars['item_ids']->value) && $_smarty_tpl->tpl_vars['type']->value != "table") {
            ?>
        <?php 
            $_smarty_tpl->tpl_vars["item_ids"] = new Smarty_variable(explode(",", $_smarty_tpl->tpl_vars['item_ids']->value), null, 0);
        }
        ?>

<?php 
        if ($_smarty_tpl->tpl_vars['view_mode']->value != "list") {
            ?>
    <?php 
            if ($_smarty_tpl->tpl_vars['placement']->value == 'right') {
                ?>
        <div class="clearfix">
            <div class="pull-right">
    <?php 
            }
            ?>

    <?php 
            if ($_smarty_tpl->tpl_vars['type']->value != "single") {
                ?>
    <a data-ca-external-click-id="opener_picker_<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
" class="cm-external-click btn <?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['meta']->value, ENT_QUOTES, 'UTF-8');
                ?>
"><i class="icon-plus"></i> <?php 
                echo $_smarty_tpl->__("add_product");
                ?>
</a>
    <?php 
            }
            ?>

    <?php 
            if ($_smarty_tpl->tpl_vars['placement']->value == 'right') {
                ?>
            </div>
        </div>
    <?php 
            }
        }
        ?>

<?php 
        if ($_smarty_tpl->tpl_vars['view_mode']->value != "button") {
            if ($_smarty_tpl->tpl_vars['type']->value == "links") {
                ?>
    <input type="hidden" id="p<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
_ids" name="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['input_name']->value, ENT_QUOTES, 'UTF-8');
                ?>
" value="<?php 
                if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                    echo htmlspecialchars(implode(",", $_smarty_tpl->tpl_vars['item_ids']->value), ENT_QUOTES, 'UTF-8');
                }
                ?>
" />
    <?php 
                $_smarty_tpl->_capture_stack[0][] = array("products_list", null, null);
                ob_start();
                ?>
    <table class="table table-middle">
    <thead>
    <tr>
        <?php 
                if ($_smarty_tpl->tpl_vars['positions']->value) {
                    ?>
<th><?php 
                    echo $_smarty_tpl->__("position_short");
                    ?>
</th><?php 
                }
                ?>
        <th width="100%"><?php 
                echo $_smarty_tpl->__("name");
                ?>
</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
    </tr>
    </thead>
    <tbody id="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
" class="<?php 
                if (!$_smarty_tpl->tpl_vars['item_ids']->value) {
                    ?>
hidden<?php 
                }
                ?>
 cm-picker-product">
    <?php 
                echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('clone' => true, 'product' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "product" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'delete_id' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "delete_id" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'type' => "product", 'position_field' => $_smarty_tpl->tpl_vars['positions']->value, 'position' => "0"), 0);
                ?>

    <?php 
                if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                    ?>
    <?php 
                    $_smarty_tpl->tpl_vars["product"] = new Smarty_Variable();
                    $_smarty_tpl->tpl_vars["product"]->_loop = false;
                    $_from = $_smarty_tpl->tpl_vars['item_ids']->value;
                    if (!is_array($_from) && !is_object($_from)) {
                        settype($_from, 'array');
                    }
                    $_smarty_tpl->tpl_vars["product"]->index = -1;
                    $_smarty_tpl->tpl_vars['smarty']->value['foreach']["items"]['iteration'] = 0;
                    foreach ($_from as $_smarty_tpl->tpl_vars["product"]->key => $_smarty_tpl->tpl_vars["product"]->value) {
                        $_smarty_tpl->tpl_vars["product"]->_loop = true;
                        $_smarty_tpl->tpl_vars["product"]->index++;
                        $_smarty_tpl->tpl_vars["product"]->first = $_smarty_tpl->tpl_vars["product"]->index === 0;
                        $_smarty_tpl->tpl_vars['smarty']->value['foreach']["items"]['first'] = $_smarty_tpl->tpl_vars["product"]->first;
                        $_smarty_tpl->tpl_vars['smarty']->value['foreach']["items"]['iteration']++;
                        ?>
        <?php 
                        echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_id' => $_smarty_tpl->tpl_vars['product']->value, 'product' => ($tmp = @fn_get_product_name($_smarty_tpl->tpl_vars['product']->value)) === null || $tmp === '' ? $_smarty_tpl->__("deleted_product") : $tmp, 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'delete_id' => $_smarty_tpl->tpl_vars['product']->value, 'type' => "product", 'first_item' => $_smarty_tpl->getVariable('smarty')->value['foreach']['items']['first'], 'position_field' => $_smarty_tpl->tpl_vars['positions']->value, 'position' => $_smarty_tpl->getVariable('smarty')->value['foreach']['items']['iteration'] + $_smarty_tpl->tpl_vars['start_pos']->value), 0);
                        ?>

    <?php 
                    }
                    ?>
    <?php 
                }
                ?>
    </tbody>
    <tbody id="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
_no_item"<?php 
                if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                    ?>
 class="hidden"<?php 
                }
                ?>
>
    <tr class="no-items">
        <td colspan="<?php 
                if ($_smarty_tpl->tpl_vars['positions']->value) {
                    ?>
4<?php 
                } else {
                    ?>
3<?php 
                }
                ?>
"><p><?php 
                echo ($tmp = @$_smarty_tpl->tpl_vars['no_item_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("no_items") : $tmp;
                ?>
</p></td>
    </tr>
    </tbody>
    </table>
    <?php 
                list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                if (!empty($_capture_buffer)) {
                    if (isset($_capture_assign)) {
                        $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                    }
                    if (isset($_capture_append)) {
                        $_smarty_tpl->append($_capture_append, ob_get_contents());
                    }
                    Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                } else {
                    $_smarty_tpl->capture_error();
                }
                ?>
    <?php 
                if ($_smarty_tpl->tpl_vars['picker_view']->value) {
                    ?>
        <div class="shift-button">
        <?php 
                    echo $_smarty_tpl->getSubTemplate("common/popupbox.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('id' => "inner_" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'link_text' => count($_smarty_tpl->tpl_vars['item_ids']->value), 'act' => "link", 'content' => Smarty::$_smarty_vars['capture']['products_list'], 'text' => __("editing_defined_products"), 'picker_meta' => "cm-bg-close", 'method' => "GET", 'no_icon_link' => true), 0);
                    echo $_smarty_tpl->__("defined_items");
                    ?>

        </div>
    <?php 
                } else {
                    ?>
        <?php 
                    echo Smarty::$_smarty_vars['capture']['products_list'];
                    ?>

    <?php 
                }
            } elseif ($_smarty_tpl->tpl_vars['type']->value == "table") {
                ?>
    <?php 
                if (!isset($_smarty_tpl->tpl_vars['display']->value)) {
                    ?>
        <?php 
                    $_smarty_tpl->tpl_vars["display"] = new Smarty_variable("options", null, 0);
                    ?>
    <?php 
                }
                ?>
    <table class="table table-middle">
    <thead>
    <tr>
        <th width="80%"><?php 
                echo $_smarty_tpl->__("name");
                ?>
</th>
        <th class="center"><?php 
                echo $_smarty_tpl->__("quantity");
                ?>
</th>
        <?php 
                $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "product_picker:table_header"));
                $_block_repeat = true;
                echo smarty_block_hook(array('name' => "product_picker:table_header"), null, $_smarty_tpl, $_block_repeat);
                while ($_block_repeat) {
                    ob_start();
                    ?>

        <?php 
                    $_block_content = ob_get_clean();
                    $_block_repeat = false;
                    echo smarty_block_hook(array('name' => "product_picker:table_header"), $_block_content, $_smarty_tpl, $_block_repeat);
                }
                array_pop($_smarty_tpl->smarty->_tag_stack);
                ?>

        <th>&nbsp;</th>
    </tr>
    </thead>
    <tbody id="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
" class="<?php 
                if (!$_smarty_tpl->tpl_vars['item_ids']->value) {
                    ?>
hidden <?php 
                }
                ?>
cm-picker<?php 
                if ($_smarty_tpl->tpl_vars['display']->value) {
                    ?>
-options<?php 
                }
                ?>
">
    <?php 
                $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "product_picker:table_rows"));
                $_block_repeat = true;
                echo smarty_block_hook(array('name' => "product_picker:table_rows"), null, $_smarty_tpl, $_block_repeat);
                while ($_block_repeat) {
                    ob_start();
                    ?>

    <?php 
                    if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                        ?>
    <?php 
                        $_smarty_tpl->tpl_vars["product"] = new Smarty_Variable();
                        $_smarty_tpl->tpl_vars["product"]->_loop = false;
                        $_smarty_tpl->tpl_vars["product_id"] = new Smarty_Variable();
                        $_from = $_smarty_tpl->tpl_vars['item_ids']->value;
                        if (!is_array($_from) && !is_object($_from)) {
                            settype($_from, 'array');
                        }
                        foreach ($_from as $_smarty_tpl->tpl_vars["product"]->key => $_smarty_tpl->tpl_vars["product"]->value) {
                            $_smarty_tpl->tpl_vars["product"]->_loop = true;
                            $_smarty_tpl->tpl_vars["product_id"]->value = $_smarty_tpl->tpl_vars["product"]->key;
                            ?>
        <?php 
                            if ($_smarty_tpl->tpl_vars['display']->value) {
                                ?>
            <?php 
                                $_smarty_tpl->_capture_stack[0][] = array("product_options", null, null);
                                ob_start();
                                ?>
                <?php 
                                $_smarty_tpl->tpl_vars["prod_opts"] = new Smarty_variable(fn_get_product_options($_smarty_tpl->tpl_vars['product']->value['product_id']), null, 0);
                                ?>
                <?php 
                                if ($_smarty_tpl->tpl_vars['prod_opts']->value && !$_smarty_tpl->tpl_vars['product']->value['product_options']) {
                                    ?>
                    <span><?php 
                                    echo $_smarty_tpl->__("options");
                                    ?>
: </span>&nbsp;<?php 
                                    echo $_smarty_tpl->__("any_option_combinations");
                                    ?>

                <?php 
                                } elseif ($_smarty_tpl->tpl_vars['product']->value['product_options']) {
                                    ?>
                    <?php 
                                    if ($_smarty_tpl->tpl_vars['product']->value['product_options_value']) {
                                        ?>
                        <?php 
                                        echo $_smarty_tpl->getSubTemplate("common/options_info.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_options' => $_smarty_tpl->tpl_vars['product']->value['product_options_value']), 0);
                                        ?>

                    <?php 
                                    } else {
                                        ?>
                        <?php 
                                        echo $_smarty_tpl->getSubTemplate("common/options_info.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_options' => fn_get_selected_product_options_info($_smarty_tpl->tpl_vars['product']->value['product_options'])), 0);
                                        ?>

                    <?php 
                                    }
                                    ?>
                <?php 
                                }
                                ?>
            <?php 
                                list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                                if (!empty($_capture_buffer)) {
                                    if (isset($_capture_assign)) {
                                        $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                                    }
                                    if (isset($_capture_append)) {
                                        $_smarty_tpl->append($_capture_append, ob_get_contents());
                                    }
                                    Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                                } else {
                                    $_smarty_tpl->capture_error();
                                }
                                ?>
        <?php 
                            }
                            ?>
        <?php 
                            if ($_smarty_tpl->tpl_vars['product']->value['product']) {
                                ?>
            <?php 
                                $_smarty_tpl->tpl_vars["product_name"] = new Smarty_variable($_smarty_tpl->tpl_vars['product']->value['product'], null, 0);
                                ?>
        <?php 
                            } else {
                                ?>
            <?php 
                                $_smarty_tpl->tpl_vars["product_name"] = new Smarty_variable(($tmp = @fn_get_product_name($_smarty_tpl->tpl_vars['product']->value['product_id'])) === null || $tmp === '' ? $_smarty_tpl->__("deleted_product") : $tmp, null, 0);
                                ?>
        <?php 
                            }
                            ?>
        <?php 
                            echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product' => $_smarty_tpl->tpl_vars['product_name']->value, 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'delete_id' => $_smarty_tpl->tpl_vars['product_id']->value, 'input_name' => (string) $_smarty_tpl->tpl_vars['input_name']->value . "[" . (string) $_smarty_tpl->tpl_vars['product_id']->value . "]", 'amount' => $_smarty_tpl->tpl_vars['product']->value['amount'], 'amount_input' => "text", 'type' => "options", 'options' => Smarty::$_smarty_vars['capture']['product_options'], 'options_array' => $_smarty_tpl->tpl_vars['product']->value['product_options'], 'product_id' => $_smarty_tpl->tpl_vars['product']->value['product_id'], 'product_info' => $_smarty_tpl->tpl_vars['product']->value), 0);
                            ?>

    <?php 
                        }
                        ?>
    <?php 
                    }
                    ?>
    <?php 
                    $_block_content = ob_get_clean();
                    $_block_repeat = false;
                    echo smarty_block_hook(array('name' => "product_picker:table_rows"), $_block_content, $_smarty_tpl, $_block_repeat);
                }
                array_pop($_smarty_tpl->smarty->_tag_stack);
                ?>

    <?php 
                echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('clone' => true, 'product' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "product" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'delete_id' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "delete_id" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'input_name' => (string) $_smarty_tpl->tpl_vars['input_name']->value . "[" . (string) $_smarty_tpl->tpl_vars['ldelim']->value . "product_id" . (string) $_smarty_tpl->tpl_vars['rdelim']->value . "]", 'amount' => "1", 'amount_input' => "text", 'type' => "options", 'options' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "options" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'product_id' => ''), 0);
                ?>

    </tbody>
    <tbody id="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
_no_item"<?php 
                if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                    ?>
 class="hidden"<?php 
                }
                ?>
>
    <tr class="no-items">
        <td colspan="<?php 
                echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['colspan']->value) === null || $tmp === '' ? "3" : $tmp, ENT_QUOTES, 'UTF-8');
                ?>
"><p><?php 
                echo ($tmp = @$_smarty_tpl->tpl_vars['no_item_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("no_items") : $tmp;
                ?>
</p></td>
    </tr>
    </tbody>
    </table>
<?php 
            } elseif ($_smarty_tpl->tpl_vars['type']->value == "single") {
                ?>
<div class="cm-display-radio" id="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
">
    <input id="<?php 
                if ($_smarty_tpl->tpl_vars['input_id']->value) {
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['input_id']->value, ENT_QUOTES, 'UTF-8');
                } else {
                    ?>
c<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                    ?>
_ids<?php 
                }
                ?>
" type="hidden" class="cm-picker-value" name="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['input_name']->value, ENT_QUOTES, 'UTF-8');
                ?>
" value="<?php 
                if (is_array($_smarty_tpl->tpl_vars['item_ids']->value)) {
                    echo htmlspecialchars(implode(",", $_smarty_tpl->tpl_vars['item_ids']->value), ENT_QUOTES, 'UTF-8');
                }
                ?>
" />
    <div class="input-append choose-input">
        <?php 
                echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_id' => '', 'holder' => $_smarty_tpl->tpl_vars['data_id']->value, 'hide_input' => $_smarty_tpl->tpl_vars['hide_input']->value, 'input_name' => $_smarty_tpl->tpl_vars['input_name']->value, 'hide_link' => $_smarty_tpl->tpl_vars['hide_link']->value, 'hide_delete_button' => $_smarty_tpl->tpl_vars['hide_delete_button']->value, 'type' => "single"), 0);
                ?>

        <?php 
                echo Smarty::$_smarty_vars['capture']['add_buttons'];
                ?>

    </div>
</div>
<?php 
            }
        }
        if ($_smarty_tpl->tpl_vars['view_mode']->value != "list") {
            ?>
    <div class="hidden">
        <?php 
            if ($_smarty_tpl->tpl_vars['extra_var']->value) {
                ?>
            <?php 
                $_smarty_tpl->tpl_vars["extra_var"] = new Smarty_variable(rawurlencode($_smarty_tpl->tpl_vars['extra_var']->value), null, 0);
                ?>
        <?php 
            }
            ?>
        <?php 
            if (!$_smarty_tpl->tpl_vars['no_container']->value) {
                ?>
<div class="buttons-container"><?php 
            }
            if ($_smarty_tpl->tpl_vars['picker_view']->value) {
                ?>
[<?php 
            }
            ?>
            <?php 
            echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_id' => "opener_picker_" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_href' => fn_url("products.picker?display=" . (string) $_smarty_tpl->tpl_vars['display']->value . "&company_id=" . (string) $_smarty_tpl->tpl_vars['company_id']->value . "&company_ids=" . (string) $_smarty_tpl->tpl_vars['company_ids']->value . "&picker_for=" . (string) $_smarty_tpl->tpl_vars['picker_for']->value . "&extra=" . (string) $_smarty_tpl->tpl_vars['extra_var']->value . "&checkbox_name=" . (string) $_smarty_tpl->tpl_vars['checkbox_name']->value . "&aoc=" . (string) $_smarty_tpl->tpl_vars['aoc']->value . "&data_id=" . (string) $_smarty_tpl->tpl_vars['data_id']->value), 'but_text' => ($tmp = @$_smarty_tpl->tpl_vars['but_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("add_products") : $tmp, 'but_role' => "add", 'but_target_id' => "content_" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_meta' => "cm-dialog-opener"), 0);
            ?>

        <?php 
            if ($_smarty_tpl->tpl_vars['picker_view']->value) {
                ?>
]<?php 
            }
            if (!$_smarty_tpl->tpl_vars['no_container']->value) {
                ?>
</div><?php 
            }
            ?>
        <div class="hidden" id="content_<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
            ?>
" title="<?php 
            echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['but_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("add_products") : $tmp, ENT_QUOTES, 'UTF-8');
            ?>
">
        </div>
    </div>
<?php 
        }
    }
Ejemplo n.º 15
0
/**
 * Checks if all selected product options are available now
 *
 * @param array $product Product data
 * @return bool true if all options are available, false otherwise
 */
function fn_is_allowed_options($product)
{
    if (empty($product['product_options'])) {
        return true;
    }
    $options = fn_get_product_options($product['product_id']);
    foreach ($product['product_options'] as $option_id => $variant_id) {
        if (empty($variant_id)) {
            // Forbidden combination in action
            continue;
        }
        if (!isset($options[$option_id]) || !empty($options[$option_id]['variants']) && !isset($options[$option_id]['variants'][$variant_id])) {
            return false;
        }
    }
    return true;
}
Ejemplo n.º 16
0
    $data = isset($product_data) ? $product_data : $cart_products;
    fn_set_hook('after_options_calculation', $mode, $data);
    Registry::get('view')->display($display_tpl);
    exit;
}
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);
Ejemplo n.º 17
0
function fn_exim_get_product_options($product_id, $lang_code = '', $features_delimiter = '///')
{
    $pair_delimiter = ':';
    $set_delimiter = '; ';
    $vars_delimiter = ',';
    $export_fields = fn_exim_get_option_attrs();
    $result = array();
    $options = fn_get_product_options($product_id, $lang_code);
    if (!empty($options)) {
        foreach ($options as $o) {
            $glob_opt = db_get_field("SELECT option_id FROM ?:product_global_option_links WHERE option_id = ?i AND product_id = ?i", $o['option_id'], $product_id);
            $prefix = '';
            if (!empty($o['company_id'])) {
                $company_name = fn_get_company_name($o['company_id']);
                $prefix = '(' . $company_name . ') ';
            }
            $str = $prefix . "{$o['option_name']}{$pair_delimiter} {$o['option_type']}" . (empty($glob_opt) ? '' : 'G');
            $variants = array();
            if (!empty($o['variants'])) {
                foreach ($o['variants'] as $v) {
                    $variant = $v['variant_name'];
                    if (floatval($v['modifier']) != 0) {
                        $variant .= $features_delimiter . 'modifier=' . $v['modifier'];
                        $variant .= $features_delimiter . 'modifier_type=' . $v['modifier_type'];
                    }
                    if (floatval($v['weight_modifier']) != 0) {
                        $variant .= $features_delimiter . 'weight_modifier=' . $v['weight_modifier'];
                        $variant .= $features_delimiter . 'weight_modifier_type=' . $v['weight_modifier_type'];
                    }
                    if (!empty($v['image_pair']['image_id'])) {
                        $variant .= $features_delimiter . 'image=' . fn_export_image($v['image_pair']['image_id'], 'variant_image', '', false);
                    }
                    fn_set_hook('exim_product_variant', $v, $variant);
                    $variants[] = $variant;
                }
                $str .= '[' . implode($vars_delimiter, str_replace($vars_delimiter, '\\\\' . $vars_delimiter, $variants)) . ']';
                fn_set_hook('exim_product_option', $o, $str);
            }
            foreach ($export_fields as $field) {
                if (!empty($o[$field])) {
                    $str .= $features_delimiter . $field . '=' . str_replace(array('[', ']'), array('', ''), $o[$field]);
                }
            }
            $result[] = $str;
        }
    }
    return !empty($result) ? implode($set_delimiter, $result) : '';
}
Ejemplo n.º 18
0
 /**
  * Load options and combinations
  */
 public function loadOptions()
 {
     $options = fn_get_product_options($this->id, CART_LANGUAGE, true, true);
     $original_option_variants = $product_option_variants = array();
     foreach ($options as $item) {
         $option = new ProductOption($item['option_name']);
         foreach ($item['variants'] as $variant) {
             if (!empty($variant['image_pair']['icon']['http_image_path'])) {
                 $image_path = $variant['image_pair']['icon']['http_image_path'];
             } else {
                 $image_path = Registry::get('config.http_location') . '/images/no_image.png';
             }
             $this->setPicture($image_path);
             $option_variant = new ProductOptionVariant($option, $variant['variant_name'], $image_path);
             $option->setVariant($option_variant);
             $product_option_variants[$item['option_id']][$variant['variant_id']] = $option_variant;
             $original_option_variants[$item['option_id']][$variant['variant_id']] = $variant;
         }
         $this->options[$option->getId()] = $option;
     }
     list($inventory) = fn_get_product_options_inventory(array('product_id' => $this->id));
     foreach ($inventory as $combination) {
         $variants = array();
         $price = $this->base_price;
         if ($this->tracking === ProductTracking::TRACK_WITH_OPTIONS) {
             $amount = $combination['amount'];
         } else {
             $amount = $this->amount;
         }
         foreach ($combination['combination'] as $option_id => $variant_id) {
             if (isset($product_option_variants[$option_id][$variant_id])) {
                 $variants[] = $product_option_variants[$option_id][$variant_id];
                 $variant = $original_option_variants[$option_id][$variant_id];
                 if ($variant['modifier_type'] == 'A') {
                     $price += $variant['modifier'];
                 } else {
                     $price = $price + $price * $variant['modifier'] / 100;
                 }
             }
         }
         if (!empty($variants)) {
             $product_variation = new ProductVariation($price, $amount, $variants);
             $this->combinations[$product_variation->getId()] = $product_variation;
         }
     }
 }
    function content_55d42e47dff943_86175395($_smarty_tpl)
    {
        if (!is_callable('smarty_function_script')) {
            include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/function.script.php';
        }
        if (!is_callable('smarty_function_set_id')) {
            include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/function.set_id.php';
        }
        fn_preload_lang_vars(array('no_items', 'name', 'quantity', 'options', 'any_option_combinations', 'deleted_product', 'add_products', 'add_products', 'no_items', 'name', 'quantity', 'options', 'any_option_combinations', 'deleted_product', 'add_products', 'add_products'));
        if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design'] == "Y" && @constant('AREA') == "C") {
            $_smarty_tpl->_capture_stack[0][] = array("template_content", null, null);
            ob_start();
            $_smarty_tpl->tpl_vars["view_mode"] = new Smarty_variable(($tmp = @$_smarty_tpl->tpl_vars['view_mode']->value) === null || $tmp === '' ? "mixed" : $tmp, null, 0);
            if (!$_smarty_tpl->tpl_vars['display']->value) {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["display"] = new Smarty_variable("options", null, 0);
            }
            ?>

<?php 
            echo smarty_function_script(array('src' => "js/tygh/picker.js"), $_smarty_tpl);
            ?>


<?php 
            if ($_smarty_tpl->tpl_vars['view_mode']->value != "button") {
                if ($_smarty_tpl->tpl_vars['type']->value == "table") {
                    ?>
    <p id="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                    ?>
_no_item" class="ty-no-items<?php 
                    if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                        ?>
 hidden<?php 
                    }
                    ?>
"><?php 
                    echo ($tmp = @$_smarty_tpl->tpl_vars['no_item_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("no_items") : $tmp;
                    ?>
</p>

    <table id="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                    ?>
" class="ty-table<?php 
                    if (!$_smarty_tpl->tpl_vars['item_ids']->value) {
                        ?>
 hidden<?php 
                    }
                    ?>
 cm-picker-options">
    <thead>
        <tr>
            <th><?php 
                    echo $_smarty_tpl->__("name");
                    ?>
</th>
            <th><?php 
                    echo $_smarty_tpl->__("quantity");
                    ?>
</th>
        </tr>
    </thead>
    <?php 
                    echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('clone' => true, 'options' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "options" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'product' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "product" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'delete_id' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "delete_id" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'amount' => 1, 'amount_input' => "text", 'input_name' => (string) $_smarty_tpl->tpl_vars['input_name']->value . "[" . (string) $_smarty_tpl->tpl_vars['ldelim']->value . "product_id" . (string) $_smarty_tpl->tpl_vars['rdelim']->value . "]"), 0);
                    ?>

    <?php 
                    if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                        ?>
        <?php 
                        $_smarty_tpl->tpl_vars["product"] = new Smarty_Variable();
                        $_smarty_tpl->tpl_vars["product"]->_loop = false;
                        $_smarty_tpl->tpl_vars["product_id"] = new Smarty_Variable();
                        $_from = $_smarty_tpl->tpl_vars['item_ids']->value;
                        if (!is_array($_from) && !is_object($_from)) {
                            settype($_from, 'array');
                        }
                        foreach ($_from as $_smarty_tpl->tpl_vars["product"]->key => $_smarty_tpl->tpl_vars["product"]->value) {
                            $_smarty_tpl->tpl_vars["product"]->_loop = true;
                            $_smarty_tpl->tpl_vars["product_id"]->value = $_smarty_tpl->tpl_vars["product"]->key;
                            ?>
            <?php 
                            $_smarty_tpl->_capture_stack[0][] = array("product_options", null, null);
                            ob_start();
                            ?>
                <?php 
                            $_smarty_tpl->tpl_vars["prod_opts"] = new Smarty_variable(fn_get_product_options($_smarty_tpl->tpl_vars['product']->value['product_id']), null, 0);
                            ?>
                <?php 
                            if ($_smarty_tpl->tpl_vars['prod_opts']->value && !$_smarty_tpl->tpl_vars['product']->value['product_options']) {
                                ?>
                    <strong><?php 
                                echo $_smarty_tpl->__("options");
                                ?>
: </strong>&nbsp;<?php 
                                echo $_smarty_tpl->__("any_option_combinations");
                                ?>

                <?php 
                            } else {
                                ?>
                    <?php 
                                if ($_smarty_tpl->tpl_vars['product']->value['product_options_value']) {
                                    ?>
                        <?php 
                                    echo $_smarty_tpl->getSubTemplate("common/options_info.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_options' => $_smarty_tpl->tpl_vars['product']->value['product_options_value']), 0);
                                    ?>

                    <?php 
                                } else {
                                    ?>
                        <?php 
                                    echo $_smarty_tpl->getSubTemplate("common/options_info.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_options' => fn_get_selected_product_options_info($_smarty_tpl->tpl_vars['product']->value['product_options'])), 0);
                                    ?>

                    <?php 
                                }
                                ?>
                <?php 
                            }
                            ?>
            <?php 
                            list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                            if (!empty($_capture_buffer)) {
                                if (isset($_capture_assign)) {
                                    $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                                }
                                if (isset($_capture_append)) {
                                    $_smarty_tpl->append($_capture_append, ob_get_contents());
                                }
                                Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                            } else {
                                $_smarty_tpl->capture_error();
                            }
                            ?>
            <?php 
                            if ($_smarty_tpl->tpl_vars['product']->value['product']) {
                                ?>
                <?php 
                                $_smarty_tpl->tpl_vars["product_name"] = new Smarty_variable($_smarty_tpl->tpl_vars['product']->value['product'], null, 0);
                                ?>
            <?php 
                            } else {
                                ?>
                <?php 
                                $_smarty_tpl->tpl_vars["product_name"] = new Smarty_variable(($tmp = @htmlspecialchars(fn_get_product_name($_smarty_tpl->tpl_vars['product']->value['product_id']), ENT_QUOTES, 'UTF-8', true)) === null || $tmp === '' ? $_smarty_tpl->__("deleted_product") : $tmp, null, 0);
                                ?>
            <?php 
                            }
                            ?>
            <?php 
                            echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('options' => Smarty::$_smarty_vars['capture']['product_options'], 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'product' => $_smarty_tpl->tpl_vars['product_name']->value, 'delete_id' => $_smarty_tpl->tpl_vars['product_id']->value, 'product_id' => $_smarty_tpl->tpl_vars['product']->value['product_id'], 'amount' => $_smarty_tpl->tpl_vars['product']->value['amount'], 'amount_input' => "text", 'input_name' => (string) $_smarty_tpl->tpl_vars['input_name']->value . "[" . (string) $_smarty_tpl->tpl_vars['product']->value['product_id'] . "]", 'options_array' => $_smarty_tpl->tpl_vars['product']->value['product_options']), 0);
                            ?>

        <?php 
                        }
                        ?>
    <?php 
                    }
                    ?>
    </table>
<?php 
                }
            }
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['view_mode']->value != "list") {
                ?>

    <?php 
                if ($_smarty_tpl->tpl_vars['extra_var']->value) {
                    ?>
        <?php 
                    $_smarty_tpl->tpl_vars["extra_var"] = new Smarty_variable(rawurlencode($_smarty_tpl->tpl_vars['extra_var']->value), null, 0);
                    ?>
    <?php 
                }
                ?>

    <?php 
                if (!$_smarty_tpl->tpl_vars['no_container']->value) {
                    ?>
<div class="buttons-container picker"><?php 
                }
                if ($_smarty_tpl->tpl_vars['picker_view']->value) {
                    ?>
[<?php 
                }
                ?>
        <div class="ty-mt-m">
            <?php 
                echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_id' => "opener_picker_" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_href' => "products.picker?display=" . (string) $_smarty_tpl->tpl_vars['display']->value . "&picker_for=" . (string) $_smarty_tpl->tpl_vars['picker_for']->value . "&extra=" . (string) $_smarty_tpl->tpl_vars['extra_var']->value . "&checkbox_name=" . (string) $_smarty_tpl->tpl_vars['checkbox_name']->value . "&aoc=" . (string) $_smarty_tpl->tpl_vars['aoc']->value . "&data_id=" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_text' => ($tmp = @$_smarty_tpl->tpl_vars['but_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("add_products") : $tmp, 'but_role' => ($tmp = @$_smarty_tpl->tpl_vars['but_role']->value) === null || $tmp === '' ? "add" : $tmp, 'but_target_id' => "content_" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_meta' => "ty-btn__secondary cm-dialog-opener", 'but_rel' => "nofollow", 'but_icon' => "product-picker-icon ty-icon-plus"), 0);
                ?>

    <?php 
                if ($_smarty_tpl->tpl_vars['picker_view']->value) {
                    ?>
]<?php 
                }
                if (!$_smarty_tpl->tpl_vars['no_container']->value) {
                    ?>
</div><?php 
                }
                ?>
    </div>

    <div class="hidden" id="content_<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
" title="<?php 
                echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['but_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("add_products") : $tmp, ENT_QUOTES, 'UTF-8');
                ?>
">
    </div>

<?php 
            }
            list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
            if (!empty($_capture_buffer)) {
                if (isset($_capture_assign)) {
                    $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                }
                if (isset($_capture_append)) {
                    $_smarty_tpl->append($_capture_append, ob_get_contents());
                }
                Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
            } else {
                $_smarty_tpl->capture_error();
            }
            if (trim(Smarty::$_smarty_vars['capture']['template_content'])) {
                if ($_smarty_tpl->tpl_vars['auth']->value['area'] == "A") {
                    ?>
<span class="cm-template-box template-box" data-ca-te-template="pickers/products/picker.tpl" id="<?php 
                    echo smarty_function_set_id(array('name' => "pickers/products/picker.tpl"), $_smarty_tpl);
                    ?>
"><div class="cm-template-icon icon-edit ty-icon-edit hidden"></div><?php 
                    echo Smarty::$_smarty_vars['capture']['template_content'];
                    ?>
<!--[/tpl_id]--></span><?php 
                } else {
                    echo Smarty::$_smarty_vars['capture']['template_content'];
                }
            }
        } else {
            $_smarty_tpl->tpl_vars["view_mode"] = new Smarty_variable(($tmp = @$_smarty_tpl->tpl_vars['view_mode']->value) === null || $tmp === '' ? "mixed" : $tmp, null, 0);
            if (!$_smarty_tpl->tpl_vars['display']->value) {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["display"] = new Smarty_variable("options", null, 0);
            }
            ?>

<?php 
            echo smarty_function_script(array('src' => "js/tygh/picker.js"), $_smarty_tpl);
            ?>


<?php 
            if ($_smarty_tpl->tpl_vars['view_mode']->value != "button") {
                if ($_smarty_tpl->tpl_vars['type']->value == "table") {
                    ?>
    <p id="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                    ?>
_no_item" class="ty-no-items<?php 
                    if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                        ?>
 hidden<?php 
                    }
                    ?>
"><?php 
                    echo ($tmp = @$_smarty_tpl->tpl_vars['no_item_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("no_items") : $tmp;
                    ?>
</p>

    <table id="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                    ?>
" class="ty-table<?php 
                    if (!$_smarty_tpl->tpl_vars['item_ids']->value) {
                        ?>
 hidden<?php 
                    }
                    ?>
 cm-picker-options">
    <thead>
        <tr>
            <th><?php 
                    echo $_smarty_tpl->__("name");
                    ?>
</th>
            <th><?php 
                    echo $_smarty_tpl->__("quantity");
                    ?>
</th>
        </tr>
    </thead>
    <?php 
                    echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('clone' => true, 'options' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "options" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'product' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "product" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'delete_id' => (string) $_smarty_tpl->tpl_vars['ldelim']->value . "delete_id" . (string) $_smarty_tpl->tpl_vars['rdelim']->value, 'amount' => 1, 'amount_input' => "text", 'input_name' => (string) $_smarty_tpl->tpl_vars['input_name']->value . "[" . (string) $_smarty_tpl->tpl_vars['ldelim']->value . "product_id" . (string) $_smarty_tpl->tpl_vars['rdelim']->value . "]"), 0);
                    ?>

    <?php 
                    if ($_smarty_tpl->tpl_vars['item_ids']->value) {
                        ?>
        <?php 
                        $_smarty_tpl->tpl_vars["product"] = new Smarty_Variable();
                        $_smarty_tpl->tpl_vars["product"]->_loop = false;
                        $_smarty_tpl->tpl_vars["product_id"] = new Smarty_Variable();
                        $_from = $_smarty_tpl->tpl_vars['item_ids']->value;
                        if (!is_array($_from) && !is_object($_from)) {
                            settype($_from, 'array');
                        }
                        foreach ($_from as $_smarty_tpl->tpl_vars["product"]->key => $_smarty_tpl->tpl_vars["product"]->value) {
                            $_smarty_tpl->tpl_vars["product"]->_loop = true;
                            $_smarty_tpl->tpl_vars["product_id"]->value = $_smarty_tpl->tpl_vars["product"]->key;
                            ?>
            <?php 
                            $_smarty_tpl->_capture_stack[0][] = array("product_options", null, null);
                            ob_start();
                            ?>
                <?php 
                            $_smarty_tpl->tpl_vars["prod_opts"] = new Smarty_variable(fn_get_product_options($_smarty_tpl->tpl_vars['product']->value['product_id']), null, 0);
                            ?>
                <?php 
                            if ($_smarty_tpl->tpl_vars['prod_opts']->value && !$_smarty_tpl->tpl_vars['product']->value['product_options']) {
                                ?>
                    <strong><?php 
                                echo $_smarty_tpl->__("options");
                                ?>
: </strong>&nbsp;<?php 
                                echo $_smarty_tpl->__("any_option_combinations");
                                ?>

                <?php 
                            } else {
                                ?>
                    <?php 
                                if ($_smarty_tpl->tpl_vars['product']->value['product_options_value']) {
                                    ?>
                        <?php 
                                    echo $_smarty_tpl->getSubTemplate("common/options_info.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_options' => $_smarty_tpl->tpl_vars['product']->value['product_options_value']), 0);
                                    ?>

                    <?php 
                                } else {
                                    ?>
                        <?php 
                                    echo $_smarty_tpl->getSubTemplate("common/options_info.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('product_options' => fn_get_selected_product_options_info($_smarty_tpl->tpl_vars['product']->value['product_options'])), 0);
                                    ?>

                    <?php 
                                }
                                ?>
                <?php 
                            }
                            ?>
            <?php 
                            list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                            if (!empty($_capture_buffer)) {
                                if (isset($_capture_assign)) {
                                    $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                                }
                                if (isset($_capture_append)) {
                                    $_smarty_tpl->append($_capture_append, ob_get_contents());
                                }
                                Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                            } else {
                                $_smarty_tpl->capture_error();
                            }
                            ?>
            <?php 
                            if ($_smarty_tpl->tpl_vars['product']->value['product']) {
                                ?>
                <?php 
                                $_smarty_tpl->tpl_vars["product_name"] = new Smarty_variable($_smarty_tpl->tpl_vars['product']->value['product'], null, 0);
                                ?>
            <?php 
                            } else {
                                ?>
                <?php 
                                $_smarty_tpl->tpl_vars["product_name"] = new Smarty_variable(($tmp = @htmlspecialchars(fn_get_product_name($_smarty_tpl->tpl_vars['product']->value['product_id']), ENT_QUOTES, 'UTF-8', true)) === null || $tmp === '' ? $_smarty_tpl->__("deleted_product") : $tmp, null, 0);
                                ?>
            <?php 
                            }
                            ?>
            <?php 
                            echo $_smarty_tpl->getSubTemplate("pickers/products/js.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('options' => Smarty::$_smarty_vars['capture']['product_options'], 'root_id' => $_smarty_tpl->tpl_vars['data_id']->value, 'product' => $_smarty_tpl->tpl_vars['product_name']->value, 'delete_id' => $_smarty_tpl->tpl_vars['product_id']->value, 'product_id' => $_smarty_tpl->tpl_vars['product']->value['product_id'], 'amount' => $_smarty_tpl->tpl_vars['product']->value['amount'], 'amount_input' => "text", 'input_name' => (string) $_smarty_tpl->tpl_vars['input_name']->value . "[" . (string) $_smarty_tpl->tpl_vars['product']->value['product_id'] . "]", 'options_array' => $_smarty_tpl->tpl_vars['product']->value['product_options']), 0);
                            ?>

        <?php 
                        }
                        ?>
    <?php 
                    }
                    ?>
    </table>
<?php 
                }
            }
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['view_mode']->value != "list") {
                ?>

    <?php 
                if ($_smarty_tpl->tpl_vars['extra_var']->value) {
                    ?>
        <?php 
                    $_smarty_tpl->tpl_vars["extra_var"] = new Smarty_variable(rawurlencode($_smarty_tpl->tpl_vars['extra_var']->value), null, 0);
                    ?>
    <?php 
                }
                ?>

    <?php 
                if (!$_smarty_tpl->tpl_vars['no_container']->value) {
                    ?>
<div class="buttons-container picker"><?php 
                }
                if ($_smarty_tpl->tpl_vars['picker_view']->value) {
                    ?>
[<?php 
                }
                ?>
        <div class="ty-mt-m">
            <?php 
                echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_id' => "opener_picker_" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_href' => "products.picker?display=" . (string) $_smarty_tpl->tpl_vars['display']->value . "&picker_for=" . (string) $_smarty_tpl->tpl_vars['picker_for']->value . "&extra=" . (string) $_smarty_tpl->tpl_vars['extra_var']->value . "&checkbox_name=" . (string) $_smarty_tpl->tpl_vars['checkbox_name']->value . "&aoc=" . (string) $_smarty_tpl->tpl_vars['aoc']->value . "&data_id=" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_text' => ($tmp = @$_smarty_tpl->tpl_vars['but_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("add_products") : $tmp, 'but_role' => ($tmp = @$_smarty_tpl->tpl_vars['but_role']->value) === null || $tmp === '' ? "add" : $tmp, 'but_target_id' => "content_" . (string) $_smarty_tpl->tpl_vars['data_id']->value, 'but_meta' => "ty-btn__secondary cm-dialog-opener", 'but_rel' => "nofollow", 'but_icon' => "product-picker-icon ty-icon-plus"), 0);
                ?>

    <?php 
                if ($_smarty_tpl->tpl_vars['picker_view']->value) {
                    ?>
]<?php 
                }
                if (!$_smarty_tpl->tpl_vars['no_container']->value) {
                    ?>
</div><?php 
                }
                ?>
    </div>

    <div class="hidden" id="content_<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['data_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
" title="<?php 
                echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['but_text']->value) === null || $tmp === '' ? $_smarty_tpl->__("add_products") : $tmp, ENT_QUOTES, 'UTF-8');
                ?>
">
    </div>

<?php 
            }
        }
    }
Ejemplo n.º 20
0
function fn_get_default_product_options($product_id, $get_all = false)
{
    $result = $default = $exceptions = array();
    $exceptions = fn_get_product_exceptions($product_id, true);
    $exceptions_type = db_get_field('SELECT exceptions_type FROM ?:products WHERE product_id = ?i', $product_id);
    $track_with_options = db_get_field("SELECT tracking FROM ?:products WHERE product_id = ?i", $product_id);
    $product_options = fn_get_product_options($product_id, CART_LANGUAGE, true);
    if (!empty($product_options)) {
        foreach ($product_options as $option_id => $option) {
            if (!empty($option['variants'])) {
                $default[$option_id] = key($option['variants']);
                foreach ($option['variants'] as $variant_id => $variant) {
                    $options[$option_id][$variant_id] = true;
                }
            }
        }
    } else {
        return array();
    }
    unset($product_options);
    if (empty($exceptions)) {
        if ($track_with_options == 'O') {
            $combination = db_get_field("SELECT combination FROM ?:product_options_inventory WHERE product_id = ?i AND amount > 0 AND combination != '' LIMIT 1", $product_id);
            if (!empty($combination)) {
                $result = fn_get_product_options_by_combination($combination);
            }
        }
        if (empty($result)) {
            foreach ((array) $options as $option_id => $variants) {
                $result[$option_id] = key($variants);
            }
        }
        return $result;
    }
    $inventory_combinations = array();
    if ($track_with_options == 'O') {
        $inventory_combinations = db_get_array("SELECT combination FROM ?:product_options_inventory WHERE product_id = ?i AND amount > 0 AND combination != ''", $product_id);
        if (!empty($inventory_combinations)) {
            $_combinations = array();
            foreach ($inventory_combinations as $_combination) {
                $_combinations[] = fn_get_product_options_by_combination($_combination['combination']);
            }
            $inventory_combinations = $_combinations;
            unset($_combinations);
        }
    }
    if ($exceptions_type == 'F') {
        // Forbidden combinations
        $_options = array_keys($options);
        $_variants = array_values($options);
        if (!empty($_variants)) {
            foreach ($_variants as $key => $variants) {
                $_variants[$key] = array_keys($variants);
            }
        }
        $combinations = fn_build_options_combinations($_options, $_variants, '', 0);
        foreach ($combinations as $combination) {
            $allowed = true;
            foreach ($exceptions as $exception) {
                $res = array_diff($exception, $combination);
                if (empty($res)) {
                    $allowed = false;
                    break;
                } else {
                    foreach ($res as $option_id => $variant_id) {
                        if ($variant_id == -1) {
                            unset($res[$option_id]);
                        }
                    }
                    if (empty($res)) {
                        $allowed = false;
                        break;
                    }
                }
            }
            if ($allowed) {
                $result = $combination;
                if (empty($inventory_combinations)) {
                    break;
                } else {
                    foreach ($inventory_combinations as $_icombination) {
                        $_res = array_diff($_icombination, $combination);
                        if (empty($_res)) {
                            break 2;
                        }
                    }
                }
            }
        }
    } else {
        // Allowed combinations
        foreach ($exceptions as $exception) {
            $result = array();
            foreach ($exception as $option_id => $variant_id) {
                if (isset($options[$option_id][$variant_id]) || $variant_id == -1) {
                    $result[$option_id] = $variant_id != -1 ? $variant_id : (isset($options[$option_id]) ? key($options[$option_id]) : '');
                } else {
                    continue 2;
                }
            }
            $_opt = array_diff_key($options, $result);
            if (!empty($_opt)) {
                foreach ($_opt as $option_id => $variants) {
                    $result[$option_id] = key($variants);
                }
            }
            if (empty($inventory_combinations)) {
                break;
            } else {
                foreach ($inventory_combinations as $_icombination) {
                    $_res = array_diff($_icombination, $result);
                    if (empty($_res)) {
                        break 2;
                    }
                }
            }
        }
    }
    return empty($result) ? $default : $result;
}