Exemple #1
0
function fn_required_products_get_product_data_more(&$product, &$auth)
{
    if (!empty($product['product_id'])) {
        list($requered) = fn_get_products(array('for_required_product' => $product['product_id'], 'type' => 'extended'));
        if (count($requered)) {
            $product['have_required'] = 'Y';
            $ids = array();
            foreach ($requered as $entry) {
                $ids[] = $entry['product_id'];
            }
            $have = fn_required_products_get_existent($auth, $ids, false);
            $product['required_products'] = array();
            foreach ($requered as $entry) {
                $id = $entry['product_id'];
                fn_gather_additional_product_data($entry, true, true, true, true, true);
                $product['required_products'][$id] = $entry;
                $product['required_products'][$id]['bought'] = $have && in_array($id, $have) ? 'Y' : 'N';
            }
            if (!empty($have) && count($have) >= count($ids)) {
                $product['can_add_to_cart'] = 'Y';
            } else {
                $product['can_add_to_cart'] = 'N';
            }
        } else {
            $product['have_required'] = 'N';
        }
    }
}
Exemple #2
0
 // Get full data for current category
 $category_data = fn_get_category_data($_REQUEST['category_id'], CART_LANGUAGE, '*');
 if (!empty($category_data['meta_description']) || !empty($category_data['meta_keywords'])) {
     $view->assign('meta_description', $category_data['meta_description']);
     $view->assign('meta_keywords', $category_data['meta_keywords']);
 }
 $params = $_REQUEST;
 $params['cid'] = $_REQUEST['category_id'];
 $params['type'] = 'extended';
 if (Registry::get('settings.General.show_products_from_subcategories') == 'Y') {
     $params['subcats'] = 'Y';
 }
 list($products, $search) = fn_get_products($params, Registry::get('settings.Appearance.products_per_page'));
 if (!empty($products)) {
     foreach ($products as $k => $v) {
         fn_gather_additional_product_data($products[$k], true, true, true, true, true);
     }
 }
 $selected_layout = fn_get_products_layout($_REQUEST);
 $view->assign('products', $products);
 $view->assign('search', $search);
 $view->assign('selected_layout', $selected_layout);
 $view->assign('category_data', $category_data);
 // If page title for this category is exist than assign it to template
 if (!empty($category_data['page_title'])) {
     $view->assign('page_title', $category_data['page_title']);
 }
 fn_define('FILTER_CUSTOM_ADVANCED', true);
 // this constant means that extended filtering should be stayed on the same page
 if (!empty($_REQUEST['advanced_filter']) && $_REQUEST['advanced_filter'] == 'Y') {
     list($filters) = fn_get_filters_products_count($_REQUEST);
Exemple #3
0
function fn_twg_get_api_product_data($product_id, $lang_code = CART_LANGUAGE)
{
    $auth =& $_SESSION['auth'];
    $get_features = $get_discounts = $get_options = AREA == 'C';
    $product = fn_get_product_data($product_id, $auth, $lang_code, '', true, true, true, $get_discounts, false, $get_features, null, true);
    if (empty($product)) {
        return array();
    }
    $product['main_product_code'] = $product['product_code'];
    fn_gather_additional_product_data($product, true, true, $get_options, $get_discounts);
    // Delete empty product feature groups
    if ($get_features && !empty($product['product_features'])) {
        foreach ($product['product_features'] as $feature_id => $feature) {
            if ($feature['feature_type'] == 'G' and empty($feature['subfeatures'])) {
                unset($product['product_features'][$feature_id]);
            }
        }
    }
    $product['product_options'] = array();
    $product_options = fn_twg_api_get_product_options($product);
    if (!empty($product['combination'])) {
        $selected_options = fn_get_product_options_by_combination($product['combination']);
        $product['product_options'] = !empty($selected_options) ? fn_get_selected_product_options($product['product_id'], $selected_options, $lang_code) : $product_options[$product_id];
    }
    $product['product_options'] = $product_options;
    foreach ($product['product_options'] as $key1 => $val1) {
        $option_descriptions = db_get_row("SELECT option_name, option_text, description, comment\n             FROM ?:product_options_descriptions\n             WHERE option_id = ?i AND lang_code = ?s", $val1['option_id'], $lang_code);
        foreach ($option_descriptions as $key2 => $val2) {
            $product['product_options'][$key1][$key2] = $val2;
        }
        $val1['variants'] = isset($val1['variants']) ? $val1['variants'] : array();
        foreach (array_keys($val1['variants']) as $vid) {
            if ($val1['option_type'] == 'C') {
                $product['product_options'][$key1]['variants'][$vid]['variant_name'] = empty($val1['position']) ? __('no', $lang_code) : __('yes', $lang_code);
            } elseif ($val1['option_type'] == 'S' || $val1['option_type'] == 'R') {
                $variant_description = db_get_field("SELECT variant_name\n                     FROM ?:product_option_variants_descriptions\n                     WHERE variant_id = ?i AND lang_code = ?s", $vid, $lang_code);
                $product['product_options'][$key1]['variants'][$vid]['variant_name'] = $variant_description;
            }
        }
    }
    $product['category_id'] = $product['main_category'];
    $product['images'] = array();
    $images_config = TwigmoSettings::get('images');
    $image_params = $images_config['big'];
    if (!empty($product['main_pair'])) {
        $product['icon'] = TwigmoImage::getApiImageData($product['main_pair'], 'product', 'icon', $images_config['prewiew']);
        $product['images'][] = TwigmoImage::getApiImageData($product['main_pair'], 'product', 'detailed', $image_params);
    }
    foreach ($product['image_pairs'] as $v) {
        $product['images'][] = TwigmoImage::getApiImageData($v, 'product', 'detailed', $image_params);
    }
    $product['category'] = db_get_field("SELECT category FROM ?:category_descriptions WHERE category_id = ?i AND lang_code = ?s", $product['main_category'], $lang_code);
    $product['product_options_exceptions'] = fn_twg_get_api_product_options_exceptions($product_id);
    $product['product_options_inventory'] = fn_twg_get_api_product_options_inventory($product_id, $lang_code);
    $_product = Api::getAsApiObject('products', $product);
    $_product['avail_since_formated'] = strftime(Registry::get('settings.Appearance.date_format'), $_product['avail_since']);
    $_product['TIME'] = TIME;
    if (AREA == 'C') {
        $_product['tabs'] = fn_twg_get_product_tabs(array('product_id' => $product_id, 'descr_sl' => DESCR_SL));
    }
    $_product['default_image'] = fn_get_image_pairs($product_id, 'product', 'M', true, true);
    if (!empty($product['points_info'])) {
        $_product['points_info'] = $product['points_info'];
    }
    return $_product;
}
function fn_get_product_data_for_compare($product_ids, $action)
{
    $auth =& $_SESSION['auth'];
    $comparison_data = array('product_features' => array(0 => array()));
    $tmp = array();
    foreach ($product_ids as $product_id) {
        $product_data = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', false, true, false, false);
        fn_gather_additional_product_data($product_data, false, false, false, true, false);
        if (!empty($product_data['product_features'])) {
            foreach ($product_data['product_features'] as $k => $v) {
                if ($v['feature_type'] == 'G' && empty($v['subfeatures'])) {
                    continue;
                }
                $_features = $v['feature_type'] == 'G' ? $v['subfeatures'] : array($k => $v);
                $group_id = $v['feature_type'] == 'G' ? $k : 0;
                $comparison_data['feature_groups'][$k] = $v['description'];
                foreach ($_features as $_k => $_v) {
                    if (in_array($_k, $_SESSION['excluded_features'])) {
                        if (empty($comparison_data['hidden_features'][$_k])) {
                            $comparison_data['hidden_features'][$_k] = $_v['description'];
                        }
                        continue;
                    }
                    if (empty($comparison_data['product_features'][$group_id][$_k])) {
                        $comparison_data['product_features'][$group_id][$_k] = $_v['description'];
                    }
                }
            }
        }
        $comparison_data['products'][] = $product_data;
        unset($product_data);
    }
    if ($action != 'show_all' && !empty($comparison_data['product_features'])) {
        $value = '';
        foreach ($comparison_data['product_features'] as $group_id => $v) {
            foreach ($v as $feature_id => $_v) {
                unset($value);
                $c = $action == 'similar_only' ? true : false;
                foreach ($comparison_data['products'] as $product) {
                    $features = !empty($group_id) && isset($product['product_features'][$group_id]) ? $product['product_features'][$group_id]['subfeatures'] : $product['product_features'];
                    if (empty($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                    if (!isset($value)) {
                        $value = fn_get_feature_selected_value($features[$feature_id]);
                        continue;
                    } elseif ($value != fn_get_feature_selected_value($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                }
                if ($c == false) {
                    unset($comparison_data['product_features'][$group_id][$feature_id]);
                }
            }
        }
    }
    return $comparison_data;
}
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
//
// $Id: products.pre.php 10229 2010-07-27 14:21:39Z 2tl $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'options') {
        if (!empty($_REQUEST['event_products']) && !empty($_REQUEST['appearance']['events'])) {
            $event_data['products'] = db_get_hash_array("SELECT * FROM ?:giftreg_event_products LEFT JOIN ?:product_descriptions ON ?:product_descriptions.product_id = ?:giftreg_event_products.product_id AND ?:product_descriptions.lang_code = ?s WHERE event_id = ?i", 'item_id', CART_LANGUAGE, $_REQUEST['appearance']['event_id']);
            foreach ($event_data['products'] as $k => $v) {
                $event_data['products'][$k]['extra'] = $event_data['products'][$k]['selected_options'] = @$_REQUEST['event_products'][$k]['product_options'];
                $product_options = $event_data['products'][$k]['extra'];
                $event_data['products'][$k]['product_options'] = fn_get_selected_product_options($v['product_id'], $product_options, CART_LANGUAGE);
                $event_data['products'][$k]['original_price'] = $event_data['products'][$k]['price'] = fn_get_product_price($v['product_id'], 1, $auth);
                $event_data['products'][$k]['avail_amount'] = $v['amount'] - $v['ordered_amount'];
                fn_gather_additional_product_data($event_data['products'][$k], true, false, true, true);
            }
            $view->assign('event_id', $_REQUEST['appearance']['event_id']);
            $view->assign('event_data', $event_data);
            $view->display('addons/gift_registry/views/events/components/event_products.tpl');
            exit;
        }
    }
}
Exemple #6
0
function fn_specific_development_products_from_current_category($category_id)
{
    if (!$category_id) {
        return array();
    }
    $params = array('sl' => 'EN', 'type' => 'extended', 'cid' => $category_id);
    if (!empty($_REQUEST['sl'])) {
        $params['sl'] = $_REQUEST['sl'];
    }
    list($products) = fn_get_products($params);
    if (!empty($products)) {
        foreach ($products as $k => $v) {
            fn_gather_additional_product_data($products[$k], false, true, false, false, true);
        }
    }
    fn_specific_development_view_category($products);
    return $products;
}
function fn_get_product_data_for_compare($product_ids, $action)
{
    $auth =& $_SESSION['auth'];
    $comparison_data = array('product_features' => array(0 => array()));
    $tmp = array();
    foreach ($product_ids as $product_id) {
        $inventory_product_ids = array();
        $product_data = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', false, true, false, false);
        fn_gather_additional_product_data($product_data, false, false, false, true, false);
        if (!empty($product_data['product_features'])) {
            foreach ($product_data['product_features'] as $k => $v) {
                if ($v['feature_type'] == 'G' && empty($v['subfeatures'])) {
                    continue;
                }
                $_features = $v['feature_type'] == 'G' ? $v['subfeatures'] : array($k => $v);
                $group_id = $v['feature_type'] == 'G' ? $k : 0;
                $comparison_data['feature_groups'][$k] = $v['description'];
                foreach ($_features as $_k => $_v) {
                    if (in_array($_k, $_SESSION['excluded_features'])) {
                        if (empty($comparison_data['hidden_features'][$_k])) {
                            $comparison_data['hidden_features'][$_k] = $_v['description'];
                        }
                        continue;
                    }
                    if (!empty($_v['full_description'])) {
                        $comparison_data['product_features_full_description'][$_k] = $_v['full_description'];
                    }
                    if (empty($comparison_data['product_features'][$group_id][$_k])) {
                        $comparison_data['product_features'][$group_id][$_k] = $_v['description'];
                    }
                }
            }
        }
        $inventory_product_ids = db_get_row("SELECT MIN(b.price ) AS min_price, MAX(b.price ) AS max_price FROM ?:products as a JOIN ?:product_options_inventory_prices as b ON a.product_id=b.product_id WHERE a.product_id = ?i GROUP BY a.product_id", $product_id);
        if ($inventory_product_ids && count($inventory_product_ids) > 0) {
            $product_data['price_range'] = $inventory_product_ids;
        }
        $comparison_data['products'][] = $product_data;
        unset($product_data);
    }
    if ($action != 'show_all' && !empty($comparison_data['product_features'])) {
        $value = '';
        foreach ($comparison_data['product_features'] as $group_id => $v) {
            foreach ($v as $feature_id => $_v) {
                unset($value);
                $c = $action == 'similar_only' ? true : false;
                foreach ($comparison_data['products'] as $product) {
                    $features = !empty($group_id) && isset($product['product_features'][$group_id]) ? $product['product_features'][$group_id]['subfeatures'] : $product['product_features'];
                    if (empty($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                    if (!isset($value)) {
                        $value = fn_get_feature_selected_value($features[$feature_id]);
                        continue;
                    } elseif ($value != fn_get_feature_selected_value($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                }
                if ($c == false) {
                    unset($comparison_data['product_features'][$group_id][$feature_id]);
                }
            }
        }
    }
    return $comparison_data;
}
Exemple #8
0
function fn_get_price_by_selected_options($product_id, $product_data = array(), $selected_options = array())
{
    if (empty($product_data)) {
        $product = fn_get_product_data($product_id, $_SESSION['auth'], CART_LANGUAGE, '', true, true, true, true, $auth['area'] == 'A' && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'preview');
    } else {
        $product = $product_data;
        $product_id = $product_data['product_id'];
    }
    $params = array('get_icon' => false, 'get_detailed' => false, 'get_options' => true, 'get_discounts' => true, 'get_features' => false);
    if (empty($selected_options)) {
        fn_gather_additional_product_data($product, $params['get_icon'], $params['get_detailed'], $params['get_options'], $params['get_discounts'], $params['get_features']);
        $selectedOptions = $product['selected_options'];
        //var_dump($product['product_options']);
        if ($_REQUEST['product_data'][$product_id]['product_options']) {
            $requestedSelectedOption = array();
            foreach ($_REQUEST['product_data'][$product_id]['product_options'] as $selectedOptionId => $selectedOptionVariantId) {
                if (intval($selectedOptionVariantId) > 0) {
                    $requestedSelectedOption[$selectedOptionId] = $selectedOptionVariantId;
                }
            }
            $selectedOptions = $requestedSelectedOption;
            $productArrayOtionsVariants = fn_get_options_variants_by_option_variant_id($product_id, $_REQUEST['product_data'][$product_id]['product_options']);
            foreach ($productArrayOtionsVariants as $optionId => $productOptionVariants) {
                if (!in_array($selectedOptions[$optionId], $productOptionVariants)) {
                    $selectedOptions[$optionId] = $productOptionVariants[0];
                }
            }
        }
        $wishlistOptionsVariantsSelected = array();
        if (isset($_REQUEST['wishlist_id'])) {
            $conditionWishListSql = db_quote(' ?:user_session_products.product_id = ?i AND ?:user_session_products.item_id=?i', $product_id, $_REQUEST['wishlist_id']);
            $optsVariantsWishListSerialized = db_get_field("SELECT ?:user_session_products.extra FROM ?:user_session_products WHERE " . $conditionWishListSql . " LIMIT 1");
            $optsVariantsWishListUnSerialized = unserialize($optsVariantsWishListSerialized);
            $wishlistOptionsVariantsSelected = $optsVariantsWishListUnSerialized['product_options'];
        }
        $selected_options = $selectedOptions;
        if (!empty($wishlistOptionsVariantsSelected)) {
            $selected_options = $wishlistOptionsVariantsSelected;
        }
    }
    $new_formula = fn_calculate_price($product_id, $product['product_options'], $selected_options, $putted_fields, true);
    $price = fn_calc_opz(fn_to_opz($new_formula));
    //var_dump($new_formula);echo"<br/>";
    //var_dump($product_id);echo" ----->>>>> ";var_dump($price);echo"<br/>-------<br/>";
    if ($price < $product['min_price_calc']) {
        $price = $product['min_price_calc'];
    }
    return $price;
}
Exemple #9
0
 /**
  * Construct
  * @param int|array $product Product id or array of product data
  * ```php
  * array(
  *  'product_id' => int,
  *  'ebay_template_id' => int,
  *  ...
  * )
  * ```
  * @param string|array $relations Default * - all relations load
  * array(
  *   'additional',
  *   'options',
  *   'external'
  * );
  */
 public function __construct($product, $relations = '*')
 {
     if (!is_array($product)) {
         $product_id = (int) $product;
         $auth = \Tygh::$app['session']['auth'];
         $product = fn_get_product_data($product_id, $auth, CART_LANGUAGE);
         if ($relations === '*' || in_array('additional', $relations)) {
             fn_gather_additional_product_data($product, true, true);
         }
     }
     if (!empty($product)) {
         $this->init($product);
         if ($relations === '*' || in_array('external', $relations)) {
             $this->loadExternalData();
         }
         if ($relations === '*' || in_array('options', $relations)) {
             $this->loadOptions();
         }
     }
 }
function fn_add_product_to_cart_old($product_data, &$cart, &$auth, $update = false)
{
    $ids = array();
    if (!empty($product_data) && is_array($product_data)) {
        if (!defined('GET_OPTIONS')) {
            list($product_data, $cart) = fn_add_product_options_files($product_data, $cart, $auth, $update);
        }
        fn_set_hook('pre_add_to_cart', $product_data, $cart, $auth, $update);
        //var_dump($product_data);die();
        foreach ($product_data as $key => $data) {
            if (empty($key)) {
                continue;
            }
            if (empty($data['amount'])) {
                continue;
            }
            $data['stored_price'] = !empty($data['stored_price']) && AREA != 'C' ? $data['stored_price'] : 'N';
            if (empty($data['extra'])) {
                $data['extra'] = array();
            }
            $product_id = !empty($data['product_id']) ? intval($data['product_id']) : intval($key);
            if (!fn_check_add_product_to_cart($cart, $data, $product_id)) {
                continue;
            }
            // Check if product options exist
            if (!isset($data['product_options'])) {
                $data['product_options'] = fn_get_default_product_options($product_id);
            }
            // Generate cart id
            $data['extra']['product_options'] = $data['product_options'];
            $_id = fn_generate_cart_id($product_id, $data['extra'], false);
            if (isset($ids[$_id]) && $key == $_id) {
                continue;
            }
            if (isset($data['extra']['exclude_from_calculate']) && $data['extra']['exclude_from_calculate']) {
                if (!empty($cart['products'][$key]) && !empty($cart['products'][$key]['extra']['aoc'])) {
                    $cart['saved_product_options'][$cart['products'][$key]['extra']['saved_options_key']] = $data['product_options'];
                }
                if (isset($cart['deleted_exclude_products'][$data['extra']['exclude_from_calculate']][$_id])) {
                    continue;
                }
            }
            $amount = fn_normalize_amount(@$data['amount']);
            if (!isset($data['extra']['exclude_from_calculate']) || isset($data['extra']['exclude_from_calculate']) && !$data['extra']['exclude_from_calculate']) {
                if ($data['stored_price'] != 'Y') {
                    $allow_add = true;
                    // Check if the product price with options modifiers equals to zero
                    $price = fn_get_product_price($product_id, $amount, $auth);
                    $zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $product_id);
                    if (!floatval($price) && $zero_price_action == 'A') {
                        if (isset($cart['products'][$key]['custom_user_price'])) {
                            $price = $cart['products'][$key]['custom_user_price'];
                        } else {
                            $custom_user_price = empty($data['price']) ? 0 : $data['price'];
                        }
                    }
                    if ($data['extra']['price_calc']['total_price_calc']) {
                        $productTest = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', true, true, true, true, fn_is_preview_action($auth, $_REQUEST));
                        $productTest['extra']['product_options'] = $data['extra']['product_options'];
                        fn_gather_additional_product_data($productTest, true, true);
                        $price = $productTest['price'];
                    } else {
                        $price = fn_apply_options_modifiers($data['product_options'], $price, 'P', array(), array('product_data' => $data));
                    }
                    if (!floatval($price)) {
                        $data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
                        if (($zero_price_action == 'R' || $zero_price_action == 'A' && floatval($data['price']) < 0) && AREA == 'C') {
                            if ($zero_price_action == 'A') {
                                fn_set_notification('E', __('error'), __('incorrect_price_warning'));
                            }
                            $allow_add = false;
                        }
                        //
                        $price = empty($data['price']) ? 0 : $data['price'];
                    }
                    /**
                     * Recalculates price and checks if product can be added with the current price
                     *
                     * @param array $data Adding product data
                     * @param float $price Calculated product price
                     * @param boolean $allow_add Flag that determines if product can be added to cart
                     */
                    fn_set_hook('add_product_to_cart_check_price', $data, $price, $allow_add);
                    if (!$allow_add) {
                        continue;
                    }
                } else {
                    if (!$price) {
                        $price = fn_get_product_price($product_id, $amount, $auth);
                    }
                    $price = empty($data['price']) ? 0 : $data['price'];
                }
            } else {
                $price = 0;
            }
            //var_dump($price);echo"<br/><br/>";
            $_data = db_get_row('SELECT is_edp, options_type, tracking, unlimited_download FROM ?:products WHERE product_id = ?i', $product_id);
            if (isset($_data['is_edp'])) {
                $data['is_edp'] = $_data['is_edp'];
            } elseif (!isset($data['is_edp'])) {
                $data['is_edp'] = 0;
            }
            if (isset($_data['options_type'])) {
                $data['options_type'] = $_data['options_type'];
            }
            if (isset($_data['tracking'])) {
                $data['tracking'] = $_data['tracking'];
            }
            if (isset($_data['unlimited_download'])) {
                $data['extra']['unlimited_download'] = $_data['unlimited_download'];
            }
            // Check the sequential options
            if (!empty($data['tracking']) && $data['tracking'] == 'O' && $data['options_type'] == 'S') {
                $inventory_options = db_get_fields("SELECT a.option_id FROM ?:product_options as a LEFT JOIN ?:product_global_option_links as c ON c.option_id = a.option_id WHERE (a.product_id = ?i OR c.product_id = ?i) AND a.status = 'A' AND a.inventory = 'Y'", $product_id, $product_id);
                $sequential_completed = true;
                if (!empty($inventory_options)) {
                    foreach ($inventory_options as $option_id) {
                        if (!isset($data['product_options'][$option_id]) || empty($data['product_options'][$option_id])) {
                            $sequential_completed = false;
                            break;
                        }
                    }
                }
                if (!$sequential_completed) {
                    fn_set_notification('E', __('error'), __('select_all_product_options'));
                    // Even if customer tried to add the product from the catalog page, we will redirect he/she to the detailed product page to give an ability to complete a purchase
                    $redirect_url = fn_url('products.view?product_id=' . $product_id . '&combination=' . fn_get_options_combination($data['product_options']));
                    $_REQUEST['redirect_url'] = $redirect_url;
                    //FIXME: Very very very BAD style to use the global variables in the functions!!!
                    return false;
                }
            }
            if (!isset($cart['products'][$_id])) {
                // If product doesn't exists in the cart
                $amount = empty($data['original_amount']) ? fn_check_amount_in_stock($product_id, $amount, $data['product_options'], $_id, $data['is_edp'], 0, $cart, $update == true ? $key : 0) : $data['original_amount'];
                if ($amount === false) {
                    continue;
                }
                $cart['products'][$_id]['product_id'] = $product_id;
                $cart['products'][$_id]['product_code'] = fn_get_product_code($product_id, $data['product_options']);
                $cart['products'][$_id]['product'] = fn_get_product_name($product_id);
                //                if (isset($data['extra']['exclude_from_calculate']) && !$data['extra']['exclude_from_calculate']) {
                //                    $cart['products'][$_id]['amount'] = 0;
                //                }else
                $cart['products'][$_id]['amount'] = $amount;
                $cart['products'][$_id]['product_options'] = $data['product_options'];
                $cart['products'][$_id]['price'] = $price;
                // Collect product's options and variants name
                $ls_minicart_options = fn_ls_get_minicart_options($data['product_options']);
                $cart['products'][$_id]['ls_minicart_options'] = $ls_minicart_options;
                if (!empty($zero_price_action) && $zero_price_action == 'A') {
                    if (isset($custom_user_price)) {
                        $cart['products'][$_id]['custom_user_price'] = $custom_user_price;
                    } elseif (isset($cart['products'][$key]['custom_user_price'])) {
                        $cart['products'][$_id]['custom_user_price'] = $cart['products'][$key]['custom_user_price'];
                    }
                }
                $cart['products'][$_id]['stored_price'] = $data['stored_price'];
                // add image for minicart
                $cart['products'][$_id]['main_pair'] = fn_get_cart_product_icon($product_id, $data);
                fn_define_original_amount($product_id, $_id, $cart['products'][$_id], $data);
                if ($update == true && $key != $_id) {
                    fn_delete_cart_product($cart, $key, false);
                }
            } else {
                // If product is already exist in the cart
                $_initial_amount = empty($cart['products'][$_id]['original_amount']) ? $cart['products'][$_id]['amount'] : $cart['products'][$_id]['original_amount'];
                // If ID changed (options were changed), summ the total amount of old and new products
                if ($update == true && $key != $_id) {
                    $amount += $_initial_amount;
                    fn_delete_cart_product($cart, $key, false);
                }
                if ($data['extra']['price_calc']['total_price_calc']) {
                    $productTest = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', true, true, true, true, fn_is_preview_action($auth, $_REQUEST));
                    $productTest['extra']['product_options'] = $data['extra']['product_options'];
                    fn_gather_additional_product_data($productTest, true, true);
                    $cart['products'][$_id]['price'] = $productTest['price'];
                }
                $cart['products'][$_id]['amount'] = fn_check_amount_in_stock($product_id, ($update == true ? 0 : $_initial_amount) + $amount, $data['product_options'], $_id, !empty($data['is_edp']) && $data['is_edp'] == 'Y' ? 'Y' : 'N', 0, $cart, $update == true ? $key : 0);
            }
            $cart['products'][$_id]['extra'] = empty($data['extra']) ? array() : $data['extra'];
            $cart['products'][$_id]['stored_discount'] = @$data['stored_discount'];
            if (defined('ORDER_MANAGEMENT')) {
                $cart['products'][$_id]['discount'] = @$data['discount'];
            }
            // Increase product popularity
            if (empty($_SESSION['products_popularity']['added'][$product_id])) {
                $_data = array('product_id' => $product_id, 'added' => 1, 'total' => POPULARITY_ADD_TO_CART);
                db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE added = added + 1, total = total + ?i", $_data, POPULARITY_ADD_TO_CART);
                $_SESSION['products_popularity']['added'][$product_id] = true;
            }
            $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $product_id);
            $cart['products'][$_id]['company_id'] = $company_id;
            if (!empty($data['saved_object_id'])) {
                $cart['products'][$_id]['object_id'] = $data['saved_object_id'];
            }
            fn_set_hook('add_to_cart', $cart, $product_id, $_id);
            if ($data['extra']['price_calc']['total_price_calc']) {
                foreach ($cart['product_groups'] as $key_product_groups => $product_groups) {
                    $cart['product_groups'][$key_product_groups]['products'][$_id]['price'] = $cart['products'][$_id]['price'];
                    $cart['product_groups'][$key_product_groups]['products'][$_id]['extra']['price_calc']['total_price_calc'] = $cart['products'][$_id]['price'];
                }
            }
            //$ids[$_id] = $product_id;
        }
        /**
         * Change product data after adding product to cart
         *
         * @param array $product_data Product data
         * @param array $cart Cart data
         * @param array $auth Auth data
         * @param bool $update Flag the determains if cart data are updated
         */
        fn_set_hook('post_add_to_cart', $product_data, $cart, $auth, $update);
        $cart['recalculate'] = true;
        if (!empty($cart['chosen_shipping'])) {
            $cart['calculate_shipping'] = true;
            unset($cart['product_groups']);
        }
        return $ids;
    } else {
        return false;
    }
}
*                                                                          *
*    Copyright (c) 2009 Simbirsk Technologies Ltd. All rights reserved.    *
*                                                                          *
* This  is  commercial  software,  only  users  who have purchased a valid *
* license  and  accept  to the terms of the  License Agreement can install *
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
//
// $Id: products.post.php 7502 2009-05-19 14:54:59Z zeke $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    return;
}
//
// View product details
//
if ($mode == 'add' && Registry::get('addons.tags.tags_for_products') == 'Y') {
    Registry::set('navigation.tabs.tags', array('title' => fn_get_lang_var('tags'), 'js' => true));
} elseif ($mode == 'update' && Registry::get('addons.tags.tags_for_products') == 'Y') {
    Registry::set('navigation.tabs.tags', array('title' => fn_get_lang_var('tags'), 'js' => true));
    $product_data = $view->get_var('product_data');
    fn_gather_additional_product_data($product_data, false, false, false, false, false);
    $view->assign('product_data', $product_data);
}
Exemple #12
0
function fn_ebay_update_product_post($product_data, $product_id, $lang_code, $create)
{
    if (empty($product_id)) {
        return false;
    }
    $auth = $_SESSION['auth'];
    $product_data = fn_get_product_data($product_id, $auth, CART_LANGUAGE);
    fn_gather_additional_product_data($product_data, true, true);
    if ($product_data['override'] == "Y") {
        $title = substr(strip_tags($product_data['ebay_title']), 0, 80);
        $description = !empty($product_data['ebay_description']) ? $product_data['ebay_description'] : $product_data['full_description'];
    } else {
        $title = substr(strip_tags($product_data['product']), 0, 80);
        $description = $product_data['full_description'];
    }
    $hash_data = array('price' => fn_format_price($product_data['price']), 'title' => $title, 'description' => $description, 'product_features' => serialize($product_data['product_features']));
    $product_hash = fn_crc32(implode('_', $hash_data));
    db_query('UPDATE ?:products SET product_hash = ?s WHERE product_id = ?i', $product_hash, $product_id);
    return true;
}
Exemple #13
0
function fn_gather_additional_product_data_for_search(&$product)
{
    fn_gather_additional_product_data($product, true, true);
}
/**
 * Fills sequential options with default values. Necessary for cart total calculation
 *
 * @param array $item Cart item
 * @param int $changed_option Changed option identifier
 * @return array New options list
 */
function fn_fill_sequential_options($item, $changed_option)
{
    $params['pid'] = $item['product_id'];
    list($product) = fn_get_products($params);
    $product = reset($product);
    $product['changed_option'] = $changed_option;
    $product['selected_options'] = $item['product_options'];
    fn_gather_additional_product_data($product, false, false, true, false, false);
    if (count($item['product_options']) != count($product['selected_options'])) {
        foreach ($item['product_options'] as $option_id => $variant_id) {
            if (isset($product['selected_options'][$option_id]) || in_array($product['product_options'][$option_id]['option_type'], array('I', 'T', 'F'))) {
                continue;
            }
            if (!empty($product['product_options'][$option_id]['variants'])) {
                reset($product['product_options'][$option_id]['variants']);
                $variant_id = key($product['product_options'][$option_id]['variants']);
            } else {
                $variant_id = '';
            }
            $product['selected_options'][$option_id] = $variant_id;
            $product['changed_option'] = $option_id;
            fn_gather_additional_product_data($product, false, false, true, false, false);
        }
    }
    return $product['selected_options'];
}
Exemple #15
0
 if (!empty($_SESSION['shipping_rates'])) {
     define('CACHED_SHIPPING_RATES', true);
 }
 list($cart_products, $_SESSION['shipping_rates']) = fn_calculate_cart_content($cart, $auth, 'E', true, Registry::get('settings.General.one_page_checkout') == 'Y' ? 'F' : 'I');
 // we need this for promotions only actually...
 $profile_fields = fn_get_profile_fields('O');
 if (empty($cart['payment_id']) && floatval($cart['total']) || !fn_allow_place_order($cart)) {
     return array(CONTROLLER_STATUS_REDIRECT, "checkout.checkout");
 }
 fn_checkout_summary($cart);
 fn_get_default_credit_card($cart, empty($cart['user_data']) ? array() : $cart['user_data']);
 $view->assign('shipping_rates', $_SESSION['shipping_rates']);
 if (defined('AJAX_REQUEST')) {
     if (!empty($cart_products)) {
         foreach ($cart_products as $k => $v) {
             fn_gather_additional_product_data($cart_products[$k], true, false, true, false);
         }
     }
     $view->assign('cart', $cart);
     $view->assign('cart_products', array_reverse($cart_products, true));
     $view->assign('location', 'checkout');
     $view->assign('profile_fields', $profile_fields);
     $view->assign('use_ajax', true);
     if (Registry::get('settings.General.one_page_checkout') == 'Y') {
         $view->assign('edit_step', 'step_four');
         $view->display('views/checkout/components/checkout_steps.tpl');
         $view->display('views/checkout/components/cart_items.tpl');
     } else {
         $view->display('views/checkout/checkout.tpl');
     }
     $view->display('views/checkout/components/checkout_totals.tpl');
Exemple #16
0
function fn_buy_together_calculate($items, $auth = array())
{
    $total_price = 0;
    $product = fn_get_product_data($items['product_id'], $auth, CART_LANGUAGE, '', true, true, true, true);
    fn_gather_additional_product_data($product, true, true);
    $total_price += $product['price'] * $product['min_qty'];
    foreach ($items['item_data']['products'] as $hash => $product) {
        if (!is_integer($hash)) {
            continue;
        }
        $_product = fn_get_product_data($product['product_id'], $auth, CART_LANGUAGE, '', true, true, true, true);
        fn_gather_additional_product_data($_product, true, true);
        $price = $_product['price'] * $product['amount'];
        if (!empty($product['product_options'])) {
            $options = fn_get_selected_product_options_info($product['product_options'], DESCR_SL);
            if (!empty($options)) {
                foreach ($options as $option) {
                    if ($option['modifier_type'] == 'A') {
                        $price += $option['modifier'] * $product['amount'];
                    } else {
                        $price += ($_product['price'] + $_product['price'] * $option['modifier'] / 100) * $product['amount'];
                    }
                }
            }
        }
        $total_price += $price;
    }
    $discounted_price = $total_price;
    switch ($items['discount_type']) {
        case 'to_fixed':
            $discounted_price = $items['discount_value'];
            $discount = $total_price - $items['discount_value'];
            break;
        case 'by_fixed':
            $discounted_price -= $items['discount_value'];
            $discount = $items['discount_value'];
            break;
        case 'to_percentage':
            $discounted_price = $discounted_price / 100 * $items['discount_value'];
            $discount = $total_price - $total_price / 100 * $items['discount_value'];
            break;
        case 'by_percentage':
            $discounted_price = $discounted_price - $discounted_price / 100 * $items['discount_value'];
            $discount = $total_price / 100 * $items['discount_value'];
            break;
    }
    if ($discounted_price < 0) {
        $discounted_price = 0;
    }
    if ($discount < 0 || $discount > $total_price) {
        $discount = $total_price;
    }
    return array(fn_format_price($total_price), fn_format_price($discount), fn_format_price($discounted_price));
}
Exemple #17
0
function fn_qwintry_fn_form_cart($order_info)
{
    fn_clear_cart($cart, true);
    $customer_auth = fn_fill_auth();
    fn_form_cart($order_info['order_id'], $cart, $customer_auth, array());
    list($cart_products, ) = fn_calculate_cart_content($cart, $customer_auth, 'E', false, 'F', false);
    if (!empty($cart_products)) {
        foreach ($cart_products as $k => $v) {
            fn_gather_additional_product_data($cart_products[$k], false, false, true, false);
        }
    }
    $cart['products'] = $cart_products;
    return $cart;
}
Exemple #18
0
 $total = ITEMS_PER_PAGE;
 $fill = true;
 $params = $_REQUEST;
 $params['type'] = 'extended';
 $params['subcats'] = 'N';
 $params['sort_by'] = $price_schema['fields'][Registry::get('addons.price_list.price_list_sorting')]['sort_by'];
 $params['page'] = $page;
 while (ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) {
     list($products, , $total) = fn_get_products($params, ITEMS_PER_PAGE);
     $params['page']++;
     // Write products information
     foreach ($products as $product) {
         if (Registry::get('addons.price_list.include_options') == 'Y') {
             fn_gather_additional_product_data($product, true, false, true, true, true);
         } else {
             fn_gather_additional_product_data($product, true, false, false, true, true);
         }
         if (Registry::get('addons.price_list.include_options') == 'Y' && $product['has_options']) {
             $product = fn_price_list_get_combination($product);
             foreach ($product['combinations'] as $c_id => $c_value) {
                 $product['price'] = $product['combination_prices'][$c_id];
                 $product['weight'] = $product['combination_weight'][$c_id];
                 $product['amount'] = $product['combination_amount'][$c_id];
                 $product['product_code'] = $product['combination_code'][$c_id];
                 foreach ($selected_fields as $field_name => $active) {
                     if ($field_name == 'image') {
                         continue;
                     } elseif ($field_name == 'product') {
                         $options = array();
                         foreach ($c_value as $option_id => $variant_id) {
                             $options[] = $product['product_options'][$option_id]['option_name'] . ': ' . $product['product_options'][$option_id]['variants'][$variant_id]['variant_name'];
function fn_get_product_data_for_compare($product_ids, $action)
{
    $auth =& Tygh::$app['session']['auth'];
    $comparison_data = array('product_features' => array(0 => array()));
    $tmp = array();
    foreach ($product_ids as $product_id) {
        $product_data = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', false, true, false, false, false, false);
        list($product_data['product_features']) = fn_get_product_features(array('product_id' => $product_id, 'product_company_id' => !empty($product_data['company_id']) ? $product_data['company_id'] : 0, 'statuses' => array('A'), 'variants' => true, 'plain' => false, 'existent_only' => true, 'variants_selected_only' => true), 0);
        fn_gather_additional_product_data($product_data, false, false, false, true, false);
        if (!empty($product_data['product_features'])) {
            foreach ($product_data['product_features'] as $k => $v) {
                if ($v['display_on_product'] === 'N' && $v['display_on_catalog'] == 'N' && $v['display_on_header'] == 'N') {
                    continue;
                }
                if ($v['feature_type'] == ProductFeatures::GROUP && empty($v['subfeatures'])) {
                    continue;
                }
                $_features = $v['feature_type'] == ProductFeatures::GROUP ? $v['subfeatures'] : array($k => $v);
                $group_id = $v['feature_type'] == ProductFeatures::GROUP ? $k : 0;
                $comparison_data['feature_groups'][$k] = $v['description'];
                foreach ($_features as $_k => $_v) {
                    if (in_array($_k, Tygh::$app['session']['excluded_features'])) {
                        if (empty($comparison_data['hidden_features'][$_k])) {
                            $comparison_data['hidden_features'][$_k] = $_v['description'];
                        }
                        continue;
                    }
                    if (empty($comparison_data['product_features'][$group_id][$_k])) {
                        $comparison_data['product_features'][$group_id][$_k] = $_v['description'];
                    }
                }
            }
        }
        $comparison_data['products'][] = $product_data;
        unset($product_data);
    }
    if ($action != 'show_all' && !empty($comparison_data['product_features'])) {
        $value = '';
        foreach ($comparison_data['product_features'] as $group_id => $v) {
            foreach ($v as $feature_id => $_v) {
                unset($value);
                $c = $action == 'similar_only' ? true : false;
                foreach ($comparison_data['products'] as $product) {
                    $features = !empty($group_id) && isset($product['product_features'][$group_id]['subfeatures']) ? $product['product_features'][$group_id]['subfeatures'] : $product['product_features'];
                    if (empty($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                    if (!isset($value)) {
                        $value = fn_get_feature_selected_value($features[$feature_id]);
                        continue;
                    } elseif ($value != fn_get_feature_selected_value($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                }
                if ($c == false) {
                    unset($comparison_data['product_features'][$group_id][$feature_id]);
                }
            }
        }
    }
    return $comparison_data;
}