コード例 #1
1
ファイル: func.php プロジェクト: OneataBogdan/lead_coriolan
function fn_calculate_price($product_id, $product_options, $selected_options, $putted_fields, $default_params = false)
{
    $fields = fn_get_fields($product_id);
    $formula = db_get_field('SELECT formula FROM ?:ppc_formula WHERE product_id = ?i', $product_id);
    if (!empty($fields)) {
        if ($default_params === true) {
            foreach ($fields as $k1 => $v1) {
                $putted_fields[$v1['name']] = $v1['default_value'];
            }
        }
        foreach ($fields as $k1 => $v1) {
            $formula = str_replace('[val_' . $v1['position'] . ']', '[' . $putted_fields[$v1['name']] . ']', $formula);
            if ($v1['additional'] > 0) {
                if ($default_params === true) {
                    $formula = str_replace('[addval_' . $v1['position'] . ']', '[' . 0 . ']', $formula);
                } else {
                    $formula = str_replace('[addval_' . $v1['position'] . ']', '[' . $putted_fields['add' . $v1['name']] . ']', $formula);
                }
            }
        }
    }
    //$productArrayOtionsVariants = fn_get_options_variants_by_option_variant_id($product_id, $selected_options);
    //$view->assign('product_array_otions_variants', $productArrayOtionsVariants);
    //var_dump($productArrayOtionsVariants);
    if (!empty($selected_options)) {
        foreach ($selected_options as $k1 => $v1) {
            foreach ($product_options as $option) {
                if ($option['option_id'] == $k1) {
                    if (!empty($option['variants'])) {
                        foreach ($option['variants'] as $variant) {
                            if ($variant['variant_id'] == $v1) {
                                $var = !empty($variant['modifier']) ? $variant['modifier'] : 0;
                                if ($_POST['variant_modifier_value']) {
                                    $var = $_POST['variant_modifier_value'];
                                }
                                break;
                            }
                        }
                    }
                    break;
                }
            }
            if (empty($var)) {
                $var = '0';
            }
            $formula = str_replace('[opt_' . $k1 . ']', '[' . $var . ']', $formula);
            unset($var);
        }
    }
    // fn_get_product_option_data($option_id, $product_id, $lang_code = DESCR_SL)
    if (!empty($selected_options)) {
        foreach ($selected_options as $k1 => $v1) {
            foreach ($product_options as $option) {
                if ($option['option_id'] == $k1) {
                    if (!empty($option['variants'])) {
                        foreach ($option['variants'] as $variant) {
                            if ($variant['variant_id'] == $v1) {
                                $var = !empty($variant['weight_modifier']) ? $variant['weight_modifier'] : 0;
                                break;
                            }
                        }
                    }
                    break;
                }
            }
            if (empty($var)) {
                $var = '0';
            }
            $formula = str_replace('[optw_' . $k1 . ']', '[' . $var . ']', $formula);
            unset($var);
        }
    }
    $auth = $_SESSION['auth'];
    $def_price = fn_get_product_price($product_id, 1, $auth);
    $product = fn_get_product_data($product_id, $auth, CART_LANGUAGE, true, true, false, false, false);
    $def_weight = db_get_field('SELECT weight FROM ?:products WHERE product_id = ?i', $product_id);
    //	fn_promotion_apply('catalog', $product, $auth);
    //	if (!empty($product['discount'])) {
    //		$def_price -= $product['discount'];
    //		if ($def_price < 0) {
    //			$def_price = 0;
    //		}
    //	}
    $formula = str_replace('[price]', '[' . $def_price . ']', $formula);
    $formula = str_replace('[weight]', '[' . floatval($def_weight) . ']', $formula);
    return $formula;
}
コード例 #2
0
ファイル: func.php プロジェクト: ambient-lounge/site
function fn_get_single_map_data($order_info, $auth = null)
{
    $data = array();
    $data["order_date"] = date('d-m-Y', $order_info['timestamp']);
    $data["email"] = $order_info['email'];
    $data["customer_name"] = $order_info['firstname'] . ' ' . $order_info['lastname'];
    $data["order_id"] = $order_info['order_id'];
    $products = $order_info['products'];
    $products_arr = array();
    $currencies = Registry::get('currencies');
    $currency = isset($order_info['secondary_currency']) ? $currencies[$order_info['secondary_currency']] : $currencies[CART_SECONDARY_CURRENCY];
    #modified by Hungryweb 12.10.2015
    //$data["currency_iso"] = $currency['currency_code'];
    $data["currency_iso"] = 'USD';
    foreach ($products as $product) {
        $product_id = is_array($product) ? $product['product_id'] : intval($product);
        $product_data = array();
        $product_data['url'] = fn_get_product_url($product_id);
        #modified by Hungryweb 12.10.2015
        //$product_data['name'] = fn_get_product_name($product_id,CART_LANGUAGE,false);
        $product_data['name'] = fn_specific_development_get_category($product['product_id']) . ' ' . fn_get_product_name($product_id, CART_LANGUAGE, false);
        $product_data['description'] = db_get_field("SELECT full_description FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $product_id, CART_LANGUAGE);
        if (isset($product_data['description'])) {
            $product_data['description'] = strip_tags(html_entity_decode($product_data['description'], ENT_NOQUOTES, 'UTF-8'));
        }
        $product_data['image'] = fn_get_product_image_url($product_id);
        $price = is_array($product) ? $product['base_price'] : fn_get_product_price($product_id, 1, $auth);
        $product_data['price'] = fn_format_rate_value($price, 'F', '2', '.', ',', $currency['coefficient']);
        $products_arr[$product_id] = $product_data;
    }
    $data['products'] = $products_arr;
    return $data;
}
コード例 #3
0
ファイル: products.pre.php プロジェクト: diedsmiling/busenika
* 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;
        }
    }
}
コード例 #4
0
ファイル: fn.cart.php プロジェクト: heg-arc-ne/cscart
/**
 * Update cart products from passed products data
 *
 * @param array $cart Array of cart content and user information necessary for purchase
 * @param array $product_data Array of new products data
 * @param array $auth Array of user authentication data (e.g. uid, usergroup_ids, etc.)
 * @return boolean Always true
 */
function fn_update_cart_products(&$cart, $product_data, $auth)
{
    /**
     * Actions before updating cart products
     *
     * @param array $cart         Array of cart content and user information necessary for purchase
     * @param array $product_data Array of new products data
     * @param array $auth         Array of user authentication data (e.g. uid, usergroup_ids, etc.)
     */
    fn_set_hook('update_cart_products_pre', $cart, $product_data, $auth);
    if (is_array($cart['products']) && !empty($product_data)) {
        list($product_data, $cart) = fn_add_product_options_files($product_data, $cart, $auth, true);
        unset($product_data['custom_files']);
        foreach ($product_data as $k => $v) {
            if (!isset($cart['products'][$k]['extra']['exclude_from_calculate'])) {
                if (empty($v['extra'])) {
                    $v['extra'] = array();
                }
                if ($v['price'] < 0) {
                    $v['price'] = 0;
                }
                unset($v['object_id']);
                $amount = fn_normalize_amount($v['amount']);
                $price = fn_get_product_price($v['product_id'], $amount, $auth);
                $v['extra'] = empty($cart['products'][$k]['extra']) ? array() : $cart['products'][$k]['extra'];
                $v['extra']['product_options'] = empty($v['product_options']) ? array() : $v['product_options'];
                $_id = fn_generate_cart_id($v['product_id'], $v['extra']);
                if (!isset($cart['products'][$_id])) {
                    //if combination doesn't exist in the cart
                    $cart['products'][$_id] = $v;
                    $cart['products'][$_id]['company_id'] = !empty($cart['products'][$k]['company_id']) ? $cart['products'][$k]['company_id'] : 0;
                    $_product = $cart['products'][$k];
                    fn_define_original_amount($v['product_id'], $_id, $cart['products'][$_id], $_product);
                    fn_delete_cart_product($cart, $k);
                } elseif ($k != $_id) {
                    // if the combination is exist but differs from the current
                    $amount += $cart['products'][$_id]['amount'];
                    fn_delete_cart_product($cart, $k);
                }
                if (empty($amount)) {
                    fn_delete_cart_product($cart, $_id);
                    continue;
                } else {
                    $_product_options = !empty($v['product_options']) ? $v['product_options'] : array();
                    $cart['products'][$_id]['amount'] = fn_check_amount_in_stock($v['product_id'], $amount, $_product_options, $_id, !empty($cart['products'][$_id]['is_edp']) && $cart['products'][$_id]['is_edp'] == 'Y' ? 'Y' : 'N', !empty($cart['products'][$_id]['original_amount']) ? $cart['products'][$_id]['original_amount'] : 0, $cart);
                    if ($cart['products'][$_id]['amount'] == false && !empty($_product)) {
                        $cart['products'][$_id] = $_product;
                        unset($_product);
                    }
                }
                if ($k != $_id) {
                    $cart['products'][$_id]['prev_cart_id'] = $k;
                    // save stored taxes for products
                    fn_update_stored_cart_taxes($cart, $k, $_id, true);
                } elseif (isset($cart['products'][$_id]['prev_cart_id'])) {
                    unset($cart['products'][$_id]['prev_cart_id']);
                }
                $cart['products'][$_id]['stored_price'] = !empty($v['stored_price']) ? $v['stored_price'] : 'N';
                if ($cart['products'][$_id]['stored_price'] == 'Y') {
                    $cart['products'][$_id]['price'] = $v['price'];
                }
                $cart['products'][$_id]['stored_discount'] = !empty($v['stored_discount']) ? $v['stored_discount'] : 'N';
                if ($cart['products'][$_id]['stored_discount'] == 'Y') {
                    $cart['products'][$_id]['discount'] = $v['discount'];
                }
            }
        }
    }
    /**
     * Additional cart products updates from passed params
     *
     * @param array $cart         Array of cart content and user information necessary for purchase
     * @param array $product_data Array of new products data
     * @param array $auth         Array of user authentication data (e.g. uid, usergroup_ids, etc.)
     */
    fn_set_hook('update_cart_products_post', $cart, $product_data, $auth);
    return true;
}
コード例 #5
0
ファイル: orders.php プロジェクト: ambient-lounge/site
function fn_reorder($order_id, &$cart, &$auth)
{
    $order_info = fn_get_order_info($order_id, false, false, false, true);
    unset(Tygh::$app['session']['shipping_hash']);
    unset(Tygh::$app['session']['edit_step']);
    fn_set_hook('reorder', $order_info, $cart, $auth);
    foreach ($order_info['products'] as $k => $item) {
        // refresh company id
        $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $item['product_id']);
        $order_info['products'][$k]['company_id'] = $company_id;
        unset($order_info['products'][$k]['extra']['ekey_info']);
        unset($order_info['products'][$k]['extra']['promotions']);
        unset($order_info['products'][$k]['promotions']);
        $order_info['products'][$k]['product_options'] = empty($order_info['products'][$k]['extra']['product_options']) ? array() : $order_info['products'][$k]['extra']['product_options'];
        $order_info['products'][$k]['main_pair'] = fn_get_cart_product_icon($item['product_id'], $order_info['products'][$k]);
    }
    if (!empty($cart) && !empty($cart['products'])) {
        $cart['products'] = fn_array_merge($cart['products'], $order_info['products']);
    } else {
        $cart['products'] = $order_info['products'];
    }
    foreach ($cart['products'] as $k => $v) {
        $_is_edp = db_get_field("SELECT is_edp FROM ?:products WHERE product_id = ?i", $v['product_id']);
        if ($amount = fn_check_amount_in_stock($v['product_id'], $v['amount'], $v['product_options'], $k, $_is_edp, 0, $cart)) {
            $cart['products'][$k]['amount'] = $amount;
            // Check if the product price with options modifiers equals to zero
            $price = fn_get_product_price($v['product_id'], $amount, $auth);
            $zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $v['product_id']);
            if (!floatval($price) && $zero_price_action == 'A') {
                if (isset($v['custom_user_price'])) {
                    $price = $v['custom_user_price'];
                }
            }
            $price = fn_apply_options_modifiers($v['product_options'], $price, 'P', array(), array('product_data' => $v));
            if (!floatval($price)) {
                $data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
                if (AREA == 'C' && ($zero_price_action == 'R' || $zero_price_action == 'A' && floatval($data['price']) < 0)) {
                    if ($zero_price_action == 'A') {
                        fn_set_notification('E', __('error'), __('incorrect_price_warning'));
                    } else {
                        fn_set_notification('W', __('warning'), __('warning_zero_price_restricted_product', array('[product]' => $v['product'])));
                    }
                    unset($cart['products'][$k]);
                    continue;
                }
            }
            // Change the path of custom files
            if (!empty($v['extra']['custom_files'])) {
                foreach ($v['extra']['custom_files'] as $option_id => $_data) {
                    if (!empty($_data)) {
                        foreach ($_data as $file_id => $file) {
                            $cart['products'][$k]['extra']['custom_files'][$option_id][$file_id]['path'] = 'sess_data/' . fn_basename($file['path']);
                        }
                    }
                }
            }
        } else {
            unset($cart['products'][$k]);
        }
    }
    // Restore custom files for editing
    $dir_path = 'order_data/' . $order_id;
    if (Storage::instance('custom_files')->isExist($dir_path)) {
        Storage::instance('custom_files')->copy($dir_path, 'sess_data');
    }
    // Redirect customer to step three after reordering
    $cart['payment_updated'] = true;
    fn_save_cart_content($cart, $auth['user_id']);
    unset($cart['product_groups']);
}
コード例 #6
0
ファイル: events.php プロジェクト: diedsmiling/busenika
    return array(CONTROLLER_STATUS_REDIRECT, "events.search");
} elseif ($mode == 'unsubscribe') {
    db_query("DELETE FROM ?:giftreg_event_subscribers WHERE event_id = ?i AND email = ?s", $_REQUEST['event_id'], $_REQUEST['email']);
    fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_event_unsubscribe'));
    return array(CONTROLLER_STATUS_REDIRECT, "events.search");
} elseif ($mode == 'view') {
    $event_data = db_get_row("SELECT * FROM ?:giftreg_events WHERE event_id = ?i", $_REQUEST['event_id']);
    fn_add_breadcrumb($event_data['title']);
    $event_data['fields'] = db_get_hash_single_array("SELECT * FROM ?:giftreg_event_fields WHERE ?:giftreg_event_fields.event_id = ?i", array('field_id', 'value'), $_REQUEST['event_id']);
    $event_data['products'] = fn_get_event_product($_REQUEST['event_id'], Registry::get('settings.Appearance.products_per_page'), empty($_REQUEST['page']) ? 1 : $_REQUEST['page']);
    foreach ($event_data['products'] as $k => &$product) {
        $product['extra'] = unserialize($product['extra']);
        $product_options = $product['extra'];
        $product['product_options_ids'] = $product_options;
        $product['product_options'] = fn_get_selected_product_options_info($product_options, CART_LANGUAGE);
        $product['price'] = fn_get_product_price($product['product_id'], 1, $auth);
        $product['avail_amount'] = $product['amount'] - $product['ordered_amount'];
        // selected options combination
        $product['product_options_combination'] = fn_get_options_combination($product_options);
        fn_gather_additional_product_data($product, true, false, false, true);
        // If option combination image is exists than replace the main image with it
        $_options = $product_options;
        if (!empty($product['product_options']) && is_array($product['product_options'])) {
            foreach ($product['product_options'] as $_k => $_v) {
                if ($_v['inventory'] == 'N') {
                    unset($_options[$_v['option_id']]);
                }
            }
        }
        $combination_hash = fn_generate_cart_id($product['product_id'], array('product_options' => $_options));
        if (!empty($product['option_image_pairs']) && is_array($product['option_image_pairs'])) {
コード例 #7
0
            $_SESSION['excluded_features'] = array_diff($_SESSION['excluded_features'], $_REQUEST['add_features']);
        }
    }
    return array(CONTROLLER_STATUS_OK);
}
// Add product to comparison list
if ($mode == 'add_product') {
    if (empty($_SESSION['comparison_list'])) {
        $_SESSION['comparison_list'] = array();
    }
    $p_id = $_REQUEST['product_id'];
    if (!in_array($p_id, $_SESSION['comparison_list'])) {
        array_unshift($_SESSION['comparison_list'], $p_id);
        $added_products = array();
        $added_products[$p_id]['product_id'] = $p_id;
        $added_products[$p_id]['display_price'] = fn_get_product_price($p_id, 1, $_SESSION['auth']);
        $added_products[$p_id]['amount'] = 1;
        $added_products[$p_id]['main_pair'] = fn_get_cart_product_icon($p_id);
        Registry::get('view')->assign('added_products', $added_products);
        $title = __('product_added_to_cl');
        $msg = Registry::get('view')->fetch('views/product_features/components/product_notification.tpl');
        fn_set_notification('I', $title, $msg, 'I');
    } else {
        fn_set_notification('W', __('notice'), __('product_in_compare_list'));
    }
    return array(CONTROLLER_STATUS_REDIRECT);
} elseif ($mode == 'clear_list') {
    unset($_SESSION['comparison_list']);
    unset($_SESSION['excluded_features']);
    if (defined('AJAX_REQUEST')) {
        Registry::get('view')->assign('compared_products', array());
コード例 #8
0
ファイル: fn.cart.php プロジェクト: diedsmiling/busenika
function fn_add_product_to_cart($product_data, &$cart, &$auth, $update = false)
{
    $ids = array();
    if (!empty($product_data) && is_array($product_data)) {
        if (!defined('GET_OPTIONS')) {
            list($product_data, $cart) = fn_add_product_options_files($product_data, $cart, $auth, $update);
        }
        fn_set_hook('pre_add_to_cart', $product_data, $cart, $auth, $update);
        foreach ($product_data as $key => $data) {
            if (empty($key)) {
                continue;
            }
            if (empty($data['amount'])) {
                continue;
            }
            $data['stored_price'] = !empty($data['stored_price']) && AREA != 'C' ? $data['stored_price'] : 'N';
            if (empty($data['extra'])) {
                $data['extra'] = array();
            }
            $product_id = !empty($data['product_id']) ? $data['product_id'] : $key;
            // Check if product options exist
            if (!isset($data['product_options'])) {
                $data['product_options'] = fn_get_default_product_options($product_id);
            }
            // Generate cart id
            $data['extra']['product_options'] = $data['product_options'];
            $_id = fn_generate_cart_id($product_id, $data['extra'], false);
            if (isset($data['extra']['exclude_from_calculate'])) {
                if (!empty($cart['products'][$key]) && !empty($cart['products'][$key]['extra']['aoc'])) {
                    $cart['saved_product_options'][$cart['products'][$key]['extra']['saved_options_key']] = $data['product_options'];
                }
                if (isset($cart['deleted_exclude_products'][$data['extra']['exclude_from_calculate']][$_id])) {
                    continue;
                }
            }
            $amount = fn_normalize_amount(@$data['amount']);
            if (!isset($data['extra']['exclude_from_calculate'])) {
                if ($data['stored_price'] != 'Y') {
                    // Check if the product price with options modifiers equals to zero
                    $price = fn_get_product_price($product_id, $amount, $auth);
                    $price = fn_apply_options_modifiers($data['product_options'], $price, 'P');
                    if (!floatval($price)) {
                        $data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
                        $zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $product_id);
                        if (($zero_price_action == 'R' || $zero_price_action == 'A' && floatval($data['price']) < 0) && AREA == 'C') {
                            if ($zero_price_action == 'A') {
                                fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('incorrect_price_warning'));
                            }
                            continue;
                        }
                        $price = empty($data['price']) ? 0 : $data['price'];
                    }
                } else {
                    $price = empty($data['price']) ? 0 : $data['price'];
                }
            } else {
                $price = 0;
            }
            $data['is_edp'] = db_get_field('SELECT is_edp FROM ?:products WHERE product_id = ?i', $product_id);
            if (!isset($cart['products'][$_id])) {
                // If product doesn't exists in the cart
                $amount = empty($data['original_amount']) ? fn_check_amount_in_stock($product_id, $amount, $data['product_options'], $_id, $data['is_edp'], 0, $cart, $update == true ? $key : 0) : $data['original_amount'];
                if ($amount === false) {
                    continue;
                }
                $cart['products'][$_id]['product_id'] = $product_id;
                $cart['products'][$_id]['amount'] = $amount;
                $cart['products'][$_id]['product_options'] = $data['product_options'];
                $cart['products'][$_id]['price'] = $price;
                $cart['products'][$_id]['stored_price'] = $data['stored_price'];
                fn_define_original_amount($product_id, $_id, $cart['products'][$_id], $data);
                if ($update == true && $key != $_id) {
                    unset($cart['products'][$key]);
                }
            } else {
                // If product is already exist in the cart
                $_initial_amount = empty($cart['products'][$_id]['original_amount']) ? $cart['products'][$_id]['amount'] : $cart['products'][$_id]['original_amount'];
                // If ID changed (options were changed), summ the total amount of old and new products
                if ($update == true && $key != $_id) {
                    $amount += $_initial_amount;
                    unset($cart['products'][$key]);
                }
                $cart['products'][$_id]['amount'] = fn_check_amount_in_stock($product_id, ($update == true ? 0 : $_initial_amount) + $amount, $data['product_options'], $_id, !empty($data['is_edp']) && $data['is_edp'] == 'Y' ? 'Y' : 'N', 0, $cart, $update == true ? $key : 0);
            }
            $cart['products'][$_id]['extra'] = empty($data['extra']) ? array() : $data['extra'];
            $cart['products'][$_id]['stored_discount'] = @$data['stored_discount'];
            if (defined('ORDER_MANAGEMENT')) {
                $cart['products'][$_id]['discount'] = @$data['discount'];
            }
            // Increase product popularity
            if (empty($_SESSION['products_popularity']['added'][$product_id])) {
                $_data = array('product_id' => $product_id, 'added' => 1, 'total' => POPULARITY_ADD_TO_CART);
                db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE added = added + 1, total = total + ?i", $_data, POPULARITY_ADD_TO_CART);
                $_SESSION['products_popularity']['added'][$product_id] = true;
            }
            $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $product_id);
            $cart['products'][$_id]['company_id'] = $company_id;
            fn_set_hook('add_to_cart', $cart, $product_id, $_id);
            $ids[$_id] = $product_id;
        }
        $cart['recalculate'] = true;
        return $ids;
    } else {
        return false;
    }
}
コード例 #9
0
 }
 if ($mode == 'update') {
     // Clean up saved shipping rates
     unset($_SESSION['shipping_rates']);
     if (is_array($cart['products'])) {
         $product_data = $_REQUEST['cart_products'];
         list($product_data, $cart) = fn_add_product_options_files($product_data, $cart, $customer_auth, true);
         unset($product_data['custom_files']);
         foreach ($product_data as $k => $v) {
             if (!isset($cart['products'][$k]['extra']['exclude_from_calculate'])) {
                 if (empty($v['extra'])) {
                     $v['extra'] = array();
                 }
                 unset($v['object_id']);
                 $amount = fn_normalize_amount($v['amount']);
                 $price = fn_get_product_price($v['product_id'], $amount, $customer_auth);
                 $v['extra'] = empty($cart['products'][$k]['extra']) ? array() : $cart['products'][$k]['extra'];
                 $v['extra']['product_options'] = empty($v['product_options']) ? array() : $v['product_options'];
                 $_id = fn_generate_cart_id($v['product_id'], $v['extra']);
                 if (!isset($cart['products'][$_id])) {
                     //if combination doesn't exist in the cart
                     $cart['products'][$_id] = $v;
                     $_product = $cart['products'][$k];
                     fn_define_original_amount($v['product_id'], $_id, $cart['products'][$_id], $_product);
                     unset($cart['products'][$k]);
                 } elseif ($k != $_id) {
                     // if the combination is exist but differs from the current
                     $amount += $cart['products'][$_id]['amount'];
                     unset($cart['products'][$k]);
                 }
                 if (empty($amount)) {
コード例 #10
0
            Tygh::$app['session']['excluded_features'] = array_diff(Tygh::$app['session']['excluded_features'], $_REQUEST['add_features']);
        }
    }
    return array(CONTROLLER_STATUS_OK);
}
// Add product to comparison list
if ($mode == 'add_product') {
    if (empty(Tygh::$app['session']['comparison_list'])) {
        Tygh::$app['session']['comparison_list'] = array();
    }
    $p_id = $_REQUEST['product_id'];
    if (!in_array($p_id, Tygh::$app['session']['comparison_list'])) {
        array_unshift(Tygh::$app['session']['comparison_list'], $p_id);
        $added_products = array();
        $added_products[$p_id]['product_id'] = $p_id;
        $added_products[$p_id]['display_price'] = fn_get_product_price($p_id, 1, Tygh::$app['session']['auth']);
        $added_products[$p_id]['amount'] = 1;
        $added_products[$p_id]['main_pair'] = fn_get_cart_product_icon($p_id);
        Tygh::$app['view']->assign('added_products', $added_products);
        $title = __('product_added_to_cl');
        $msg = Tygh::$app['view']->fetch('views/product_features/components/product_notification.tpl');
        fn_set_notification('I', $title, $msg, 'I');
    } else {
        fn_set_notification('W', __('notice'), __('product_in_comparison_list'));
    }
    return array(CONTROLLER_STATUS_REDIRECT);
} elseif ($mode == 'clear_list') {
    unset(Tygh::$app['session']['comparison_list']);
    unset(Tygh::$app['session']['excluded_features']);
    if (defined('AJAX_REQUEST')) {
        Tygh::$app['view']->assign('compared_products', array());
コード例 #11
0
ファイル: fn.cart.php プロジェクト: ambient-lounge/site
function fn_add_product_to_cart($product_data, &$cart, &$auth, $update = false)
{
    $ids = array();
    if (!empty($product_data) && is_array($product_data)) {
        if (!defined('GET_OPTIONS')) {
            list($product_data, $cart) = fn_add_product_options_files($product_data, $cart, $auth, $update);
        }
        fn_set_hook('pre_add_to_cart', $product_data, $cart, $auth, $update);
        foreach ($product_data as $key => $data) {
            if (empty($key)) {
                continue;
            }
            if (empty($data['amount'])) {
                continue;
            }
            $data['stored_price'] = !empty($data['stored_price']) && defined('ORDER_MANAGEMENT') ? $data['stored_price'] : 'N';
            if (empty($data['extra'])) {
                $data['extra'] = array();
            }
            $product_id = !empty($data['product_id']) ? intval($data['product_id']) : intval($key);
            if (!fn_check_add_product_to_cart($cart, $data, $product_id)) {
                continue;
            }
            // Check if product options exist
            if (!isset($data['product_options'])) {
                $data['product_options'] = fn_get_default_product_options($product_id);
            }
            // Generate cart id
            $data['extra']['product_options'] = $data['product_options'];
            $data['product_id'] = $product_id;
            $_id = fn_generate_cart_id($product_id, $data['extra'], false);
            if (isset($ids[$_id]) && $key == $_id) {
                continue;
            }
            if (isset($data['extra']['exclude_from_calculate'])) {
                if ($update && !empty($cart['products'][$key]) && !empty($cart['products'][$key]['extra']['aoc'])) {
                    $cart['saved_product_options'][$cart['products'][$key]['extra']['saved_options_key']] = $data['product_options'];
                } elseif (!$update && !empty($data['extra']['saved_options_key']) && !empty($data['extra']['aoc'])) {
                    $cart['saved_product_options'][$data['extra']['saved_options_key']] = $data['product_options'];
                }
                if (isset($cart['deleted_exclude_products'][$data['extra']['exclude_from_calculate']][$_id])) {
                    continue;
                }
            }
            $amount = fn_normalize_amount(@$data['amount']);
            if (!isset($data['extra']['exclude_from_calculate'])) {
                if ($data['stored_price'] != 'Y') {
                    $allow_add = true;
                    // Check if the product price with options modifiers equals to zero
                    $price = fn_get_product_price($product_id, $amount, $auth);
                    $zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $product_id);
                    if (!floatval($price) && $zero_price_action == 'A') {
                        if (isset($cart['products'][$key]['custom_user_price'])) {
                            $price = $cart['products'][$key]['custom_user_price'];
                        } else {
                            $custom_user_price = empty($data['price']) ? 0 : $data['price'];
                        }
                    }
                    $price = fn_apply_options_modifiers($data['product_options'], $price, 'P', array(), array('product_data' => $data));
                    if (!floatval($price)) {
                        $data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
                        if (AREA == 'C' && ($zero_price_action == 'R' || $zero_price_action == 'A' && floatval($data['price']) < 0)) {
                            if ($zero_price_action == 'A') {
                                fn_set_notification('E', __('error'), __('incorrect_price_warning'));
                            }
                            $allow_add = false;
                        }
                        $price = empty($data['price']) ? 0 : $data['price'];
                    }
                    /**
                     * Recalculates price and checks if product can be added with the current price
                     *
                     * @param array $data Adding product data
                     * @param float $price Calculated product price
                     * @param boolean $allow_add Flag that determines if product can be added to cart
                     */
                    fn_set_hook('add_product_to_cart_check_price', $data, $price, $allow_add);
                    if (!$allow_add) {
                        continue;
                    }
                } else {
                    $price = empty($data['price']) ? 0 : $data['price'];
                }
            } else {
                $price = 0;
            }
            $_data = db_get_row('SELECT is_edp, options_type, tracking, unlimited_download FROM ?:products WHERE product_id = ?i', $product_id);
            if (isset($_data['is_edp'])) {
                $data['is_edp'] = $_data['is_edp'];
            } elseif (!isset($data['is_edp'])) {
                $data['is_edp'] = 0;
            }
            if (isset($_data['options_type'])) {
                $data['options_type'] = $_data['options_type'];
            }
            if (isset($_data['tracking'])) {
                $data['tracking'] = $_data['tracking'];
            }
            if (isset($_data['unlimited_download'])) {
                $data['extra']['unlimited_download'] = $_data['unlimited_download'];
            }
            // Check the sequential options
            if (!empty($data['tracking']) && $data['tracking'] == ProductTracking::TRACK_WITH_OPTIONS && $data['options_type'] == 'S') {
                $inventory_options = db_get_fields("SELECT a.option_id FROM ?:product_options as a LEFT JOIN ?:product_global_option_links as c ON c.option_id = a.option_id WHERE (a.product_id = ?i OR c.product_id = ?i) AND a.status = 'A' AND a.inventory = 'Y'", $product_id, $product_id);
                $sequential_completed = true;
                if (!empty($inventory_options)) {
                    foreach ($inventory_options as $option_id) {
                        if (!isset($data['product_options'][$option_id]) || empty($data['product_options'][$option_id])) {
                            $sequential_completed = false;
                            break;
                        }
                    }
                }
                if (!$sequential_completed) {
                    fn_set_notification('E', __('error'), __('select_all_product_options'));
                    // Even if customer tried to add the product from the catalog page, we will redirect he/she to the detailed product page to give an ability to complete a purchase
                    $redirect_url = fn_url('products.view?product_id=' . $product_id . '&combination=' . fn_get_options_combination($data['product_options']));
                    $_REQUEST['redirect_url'] = $redirect_url;
                    //FIXME: Very very very BAD style to use the global variables in the functions!!!
                    return false;
                }
            }
            if (!isset($cart['products'][$_id])) {
                // If product doesn't exists in the cart
                $amount = empty($data['original_amount']) ? fn_check_amount_in_stock($product_id, $amount, $data['product_options'], $_id, $data['is_edp'], 0, $cart, $update == true ? $key : 0) : $data['original_amount'];
                if ($amount === false) {
                    continue;
                }
                $cart['products'][$_id]['product_id'] = $product_id;
                $cart['products'][$_id]['product_code'] = fn_get_product_code($product_id, $data['product_options']);
                $cart['products'][$_id]['product'] = fn_get_product_name($product_id);
                $cart['products'][$_id]['amount'] = $amount;
                $cart['products'][$_id]['product_options'] = $data['product_options'];
                $cart['products'][$_id]['price'] = $price;
                if (!empty($zero_price_action) && $zero_price_action == 'A') {
                    if (isset($custom_user_price)) {
                        $cart['products'][$_id]['custom_user_price'] = $custom_user_price;
                    } elseif (isset($cart['products'][$key]['custom_user_price'])) {
                        $cart['products'][$_id]['custom_user_price'] = $cart['products'][$key]['custom_user_price'];
                    }
                }
                $cart['products'][$_id]['stored_price'] = $data['stored_price'];
                // add image for minicart
                $cart['products'][$_id]['main_pair'] = fn_get_cart_product_icon($product_id, $data);
                fn_define_original_amount($product_id, $_id, $cart['products'][$_id], $data);
                if ($update == true && $key != $_id) {
                    fn_delete_cart_product($cart, $key, false);
                }
            } else {
                // If product is already exist in the cart
                $_initial_amount = empty($cart['products'][$_id]['original_amount']) ? $cart['products'][$_id]['amount'] : $cart['products'][$_id]['original_amount'];
                // If ID changed (options were changed), summ the total amount of old and new products
                if ($update == true && $key != $_id) {
                    $amount += $_initial_amount;
                    fn_delete_cart_product($cart, $key, false);
                }
                $cart['products'][$_id]['amount'] = fn_check_amount_in_stock($product_id, ($update == true ? 0 : $_initial_amount) + $amount, $data['product_options'], $_id, !empty($data['is_edp']) && $data['is_edp'] == 'Y' ? 'Y' : 'N', 0, $cart, $update == true ? $key : 0);
            }
            $cart['products'][$_id]['extra'] = empty($data['extra']) ? array() : $data['extra'];
            $cart['products'][$_id]['stored_discount'] = @$data['stored_discount'];
            if (defined('ORDER_MANAGEMENT')) {
                $cart['products'][$_id]['discount'] = @$data['discount'];
            }
            // Increase product popularity
            if (empty(Tygh::$app['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);
                Tygh::$app['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'];
            }
            //if(AREA=='A') var_dump('aaaaaa',$cart); die();
            fn_set_hook('add_to_cart', $cart, $product_id, $_id);
            $ids[$_id] = $product_id;
        }
        /**
         * Change product data after adding product to cart
         *
         * @param array $product_data Product data
         * @param array $cart Cart data
         * @param array $auth Auth data
         * @param bool $update Flag the determains if cart data are updated
         */
        fn_set_hook('post_add_to_cart', $product_data, $cart, $auth, $update, $ids);
        $cart['recalculate'] = true;
        if (!empty($cart['chosen_shipping'])) {
            $cart['calculate_shipping'] = true;
            unset($cart['product_groups']);
        }
        return $ids;
    } else {
        return false;
    }
}