예제 #1
0
    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);
    Registry::get('view')->assign('products', $products);
    Registry::get('view')->assign('search', $search);
예제 #2
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']);
}
예제 #3
0
         }
         if (count($promotionP) == 0) {
             unset($cart['promotions'][$keyPromotion]);
         }
     }
 } elseif (count($cart['product_groups']) > 1) {
 }
 if (!empty($cart['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 (fn_check_amount_in_stock($v['product_id'], $v['amount'], empty($v['product_options']) ? array() : $v['product_options'], $k, $_is_edp, 0, $cart) == false) {
             fn_delete_cart_product($cart, $k);
             return array(CONTROLLER_STATUS_REDIRECT, "checkout.cart");
         }
         if (!fn_allowed_for('ULTIMATE:FREE')) {
             $exceptions = fn_get_product_exceptions($v['product_id'], true);
             if (!isset($v['options_type']) || !isset($v['exceptions_type'])) {
                 $v = array_merge($v, db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $v['product_id']));
             }
             if (!fn_is_allowed_options_exceptions($exceptions, $v['product_options'], $v['options_type'], $v['exceptions_type'])) {
                 fn_set_notification('E', __('notice'), __('product_options_forbidden_combination', array('[product]' => $v['product'])));
                 fn_delete_cart_product($cart, $k);
                 return array(CONTROLLER_STATUS_REDIRECT, "checkout.cart");
             }
         }
     }
 }
 list($order_id, $process_payment) = fn_place_order($cart, $auth);
 // Clean up saved shipping rates
 unset($_SESSION['product_groups']);
 if (!empty($order_id)) {
예제 #4
0
 public function index($id = 0, $params = array())
 {
     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_exceptions WHERE exception_id = ?i', $id);
         }
         $product_data = fn_get_product_data($product_id, $this->auth, DESCR_SL, '', 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_exception_data($id);
                 $status = Response::STATUS_OK;
             } else {
                 $data = fn_get_product_exceptions($product_id);
                 $status = Response::STATUS_OK;
             }
             if (empty($data)) {
                 $status = Response::STATUS_NOT_FOUND;
             }
         }
     }
     return array('status' => $status, 'data' => $data);
 }
예제 #5
0
        fn_set_hook('after_options_calculation', $mode, $data);
        $view->display($display_tpl);
        exit;
    }
}
if ($mode == 'picker') {
    $params = $_REQUEST;
    $params['type'] = 'extended';
    $params['skip_view'] = 'Y';
    list($products, $search) = fn_get_products($params, AREA == 'C' ? Registry::get('settings.Appearance.products_per_page') : Registry::get('settings.Appearance.admin_products_per_page'));
    if (!empty($_REQUEST['display']) || AREA == 'C' && !defined('EVENT_OWNER')) {
        foreach ($products as $k => $v) {
            fn_gather_additional_product_data($products[$k], true, true, true, true);
        }
    }
    if (!empty($products)) {
        foreach ($products as $k => $v) {
            $products[$k]['options'] = fn_get_product_options($v['product_id'], DESCR_SL, true, false, true);
            $products[$k]['exceptions'] = fn_get_product_exceptions($v['product_id']);
            if (!empty($products[$k]['exceptions'])) {
                foreach ($products[$k]['exceptions'] as $v) {
                    $products[$k]['exception_combinations'][fn_get_options_combination($v['combination'])] = '';
                }
            }
        }
    }
    $view->assign('products', $products);
    $view->assign('search', $search);
    $view->display('pickers/products_picker_contents.tpl');
    exit;
}
예제 #6
0
function fn_apply_exceptions_rules($product)
{
    /**
     * Changes product data before applying options exceptions rules
     *
     * @param array $product Product data
     */
    fn_set_hook('apply_exceptions_rules_pre', $product);
    /*	Exceptions type:
               A - Allowed
               F - Forbidden
       */
    if (empty($product['selected_options']) && $product['options_type'] == 'S') {
        return $product;
    }
    $exceptions = fn_get_product_exceptions($product['product_id'], true);
    if (empty($exceptions)) {
        return $product;
    }
    $product['options_update'] = true;
    $options = array();
    $disabled = array();
    if (Registry::get('settings.General.exception_style') == 'warning') {
        $result = fn_is_allowed_options_exceptions($exceptions, $product['selected_options'], $product['options_type'], $product['exceptions_type']);
        if (!$result) {
            $product['show_exception_warning'] = 'Y';
        }
        return $product;
    }
    foreach ($exceptions as $exception_id => $exception) {
        if ($product['options_type'] == 'S') {
            // Sequential exceptions type
            $_selected = array();
            foreach ($product['selected_options'] as $option_id => $variant_id) {
                $disable = true;
                $full = array();
                $_selected[$option_id] = $variant_id;
                $elms = array_diff($exception, $_selected);
                $_exception = $exception;
                if (!empty($elms)) {
                    foreach ($elms as $opt_id => $var_id) {
                        if ($var_id != -2 && $var_id != -1) {
                            $disable = false;
                        }
                        if ($var_id == -1) {
                            $full[$opt_id] = $var_id;
                        }
                        if ($product['exceptions_type'] == 'A' && $var_id == -1 && isset($_selected[$opt_id]) || $product['exceptions_type'] != 'A' && $var_id == -1) {
                            unset($elms[$opt_id]);
                            if ($product['exceptions_type'] != 'A') {
                                unset($_exception[$opt_id]);
                            }
                        }
                    }
                }
                if ($disable && !empty($elms) && count($elms) != count($full)) {
                    $vars = array_diff($elms, $full);
                    $disable = false;
                    foreach ($vars as $var) {
                        if ($var != -1) {
                            $disable = true;
                        }
                    }
                }
                if ($disable && !empty($elms) && count($elms) != count($full)) {
                    foreach ($elms as $opt_id => $var_id) {
                        $disabled[$opt_id] = true;
                    }
                } elseif ($disable && !empty($full)) {
                    foreach ($full as $opt_id => $var_id) {
                        $options[$opt_id]['any'] = true;
                    }
                } elseif (count($elms) == 1 && reset($elms) == -2) {
                    $disabled[key($elms)] = true;
                } elseif ($product['exceptions_type'] == 'A' && count($elms) + count($_selected) != count($_exception) || $product['exceptions_type'] == 'F' && count($elms) != 1) {
                    continue;
                }
                if (!isset($product['simultaneous'][$option_id]) || isset($product['simultaneous'][$option_id]) && !isset($elms[$product['simultaneous'][$option_id]])) {
                    continue;
                }
                $elms[$product['simultaneous'][$option_id]] = $elms[$product['simultaneous'][$option_id]] == -1 ? 'any' : $elms[$product['simultaneous'][$option_id]];
                if (isset($product['simultaneous'][$option_id]) && !empty($elms) && isset($elms[$product['simultaneous'][$option_id]])) {
                    $options[$product['simultaneous'][$option_id]][$elms[$product['simultaneous'][$option_id]]] = true;
                }
            }
        } else {
            // Parallel exceptions type
            $disable = true;
            $full = array();
            $elms = array_diff($exception, $product['selected_options']);
            if (!empty($elms)) {
                foreach ($elms as $opt_id => $var_id) {
                    if ($var_id != -2 && $var_id != -1) {
                        $disable = false;
                    }
                    if ($var_id == -1) {
                        $full[$opt_id] = $var_id;
                        unset($elms[$opt_id]);
                    }
                }
            }
            if ($disable && !empty($elms)) {
                foreach ($elms as $opt_id => $var_id) {
                    $disabled[$opt_id] = true;
                }
            } elseif ($disable && !empty($full)) {
                foreach ($full as $opt_id => $var_id) {
                    $options[$opt_id]['any'] = true;
                }
            } elseif (count($elms) == 1 && reset($elms) == -2) {
                $disabled[key($elms)] = true;
            } elseif (count($elms) == 1 && !in_array(reset($elms), $product['selected_options'])) {
                list($option_id, $variant_id) = array(key($elms), reset($elms));
                $options[$option_id][$variant_id] = true;
            }
        }
    }
    if ($product['exceptions_type'] == 'A' && $product['options_type'] == 'P') {
        foreach ($product['selected_options'] as $option_id => $variant_id) {
            $options[$option_id][$variant_id] = true;
        }
    }
    $first_elm = array();
    $clear_variants = false;
    foreach ($product['product_options'] as $_id => &$option) {
        $option_id = $option['option_id'];
        if (!in_array($option['option_type'], array('I', 'T', 'F')) && empty($first_elm)) {
            $first_elm = $product['product_options'][$_id];
        }
        if (isset($disabled[$option_id])) {
            $option['disabled'] = true;
            $option['not_required'] = true;
        }
        if ($product['options_type'] == 'S' && $option['option_id'] == $first_elm['option_id'] || in_array($option['option_type'], array('I', 'T', 'F'))) {
            continue;
        }
        if ($product['options_type'] == 'S' && $option['disabled']) {
            if ($clear_variants) {
                $option['variants'] = array();
            }
            continue;
        }
        if (!empty($option['variants']) && $option['option_type'] != 'C') {
            // Exclude "C"heckboxes
            foreach ($option['variants'] as $variant_id => $variant) {
                if ($product['exceptions_type'] == 'A') {
                    // Allowed combinations
                    if (empty($options[$option_id][$variant_id]) && !isset($options[$option_id]['any'])) {
                        unset($option['variants'][$variant_id]);
                    }
                } else {
                    // Forbidden combinations
                    if (!empty($options[$option_id][$variant_id]) || isset($options[$option_id]['any'])) {
                        unset($option['variants'][$variant_id]);
                    }
                }
            }
            if (!in_array($option['value'], array_keys($option['variants']))) {
                $option['value'] = '';
            }
        }
        if (empty($option['variants'])) {
            $clear_variants = true;
        }
    }
    foreach ($product['product_options'] as $_id => &$option) {
        $option_id = $option['option_id'];
        if ($product['options_type'] == 'P' && !in_array($option['option_type'], array('I', 'T', 'F')) && empty($option['value'])) {
            if (empty($option['disabled']) && !empty($option['variants'])) {
                $variant = reset($option['variants']);
                $option['value'] = $variant['variant_id'];
                $product['selected_options'][$option_id] = $variant['variant_id'];
            }
        }
    }
    /**
     * Changes product data after applying options exceptions rules
     *
     * @param array $product    Product data
     * @param array $exceptions Options exceptions
     */
    fn_set_hook('apply_exceptions_post', $product, $exceptions);
    return $product;
}
예제 #7
0
/**
 * Place order handler
 *
 * @param  array $cart   Cart
 * @param  array $auth   Auth
 * @param  array $params Params
 * @return str
 */
function fn_checkout_place_order(&$cart, &$auth, $params)
{
    // Prevent unauthorized access
    if (empty($cart['user_data']['email'])) {
        return PLACE_ORDER_STATUS_DENIED;
    }
    // Prevent using disabled payment method by challenging HTTP data
    if (!empty($params['payment_id'])) {
        $cart['payment_id'] = $params['payment_id'];
    }
    if (isset($cart['payment_id'])) {
        $payment_method_data = fn_get_payment_method_data($cart['payment_id']);
        if (!empty($payment_method_data['status']) && $payment_method_data['status'] != 'A') {
            return PLACE_ORDER_STATUS_DENIED;
        }
    }
    // Remove previous failed order
    if (!empty($cart['failed_order_id']) || !empty($cart['processed_order_id'])) {
        $_order_ids = !empty($cart['failed_order_id']) ? $cart['failed_order_id'] : $cart['processed_order_id'];
        foreach ($_order_ids as $_order_id) {
            fn_delete_order($_order_id);
        }
        $cart['rewrite_order_id'] = $_order_ids;
        unset($cart['failed_order_id'], $cart['processed_order_id']);
    }
    if (!empty($params['payment_info'])) {
        $cart['payment_info'] = $params['payment_info'];
    } else {
        $cart['payment_info'] = array();
    }
    if (empty($params['payment_info']) && !empty($cart['extra_payment_info'])) {
        $cart['payment_info'] = empty($cart['payment_info']) ? array() : $cart['payment_info'];
        $cart['payment_info'] = array_merge($cart['extra_payment_info'], $cart['payment_info']);
    }
    unset($cart['payment_info']['secure_card_number']);
    if (!empty($cart['products'])) {
        foreach ($cart['products'] as $cart_id => $product) {
            $_is_edp = db_get_field("SELECT is_edp FROM ?:products WHERE product_id = ?i", $product['product_id']);
            if (fn_check_amount_in_stock($product['product_id'], $product['amount'], empty($product['product_options']) ? array() : $product['product_options'], $cart_id, $_is_edp, 0, $cart) == false) {
                fn_delete_cart_product($cart, $cart_id);
                return PLACE_ORDER_STATUS_TO_CART;
            }
            if (!fn_allowed_for('ULTIMATE:FREE')) {
                $exceptions = fn_get_product_exceptions($product['product_id'], true);
                if (!isset($product['options_type']) || !isset($product['exceptions_type'])) {
                    $product = array_merge($product, db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $product['product_id']));
                }
                if (!fn_is_allowed_options_exceptions($exceptions, $product['product_options'], $product['options_type'], $product['exceptions_type'])) {
                    fn_set_notification('E', __('notice'), __('product_options_forbidden_combination', array('[product]' => $product['product'])));
                    fn_delete_cart_product($cart, $cart_id);
                    return PLACE_ORDER_STATUS_TO_CART;
                }
                if (!fn_is_allowed_options($product)) {
                    fn_set_notification('E', __('notice'), __('product_disabled_options', array('[product]' => $product['product'])));
                    fn_delete_cart_product($cart, $cart_id);
                    return PLACE_ORDER_STATUS_TO_CART;
                }
            }
        }
    }
    list($order_id, $process_payment) = fn_place_order($cart, $auth);
    // Clean up saved shipping rates
    unset($_SESSION['product_groups']);
    if (!empty($order_id)) {
        if (empty($params['skip_payment']) && $process_payment == true || !empty($params['skip_payment']) && empty($auth['act_as_user'])) {
            // administrator, logged in as customer can skip payment
            $payment_info = !empty($cart['payment_info']) ? $cart['payment_info'] : array();
            fn_start_payment($order_id, array(), $payment_info);
        }
        fn_order_placement_routines('route', $order_id);
        return PLACE_ORDER_STATUS_OK;
    } else {
        return PLACE_ORDER_STATUS_TO_CART;
    }
}
예제 #8
0
/**
 * Gets displayable product data to show it in the cart
 *
 * @param string $hash Unique product HASH
 * @param array &$product Product data
 * @param bool $skip_promotion Skip promotion calculation
 * @param array &$cart Array of cart content and user information necessary for purchase
 * @param array &$auth Array with authorization data
 * @param array $promotion_amount Amount of product in promotion (like Free products, etc)
 * @return array Product data
 */
function fn_get_cart_product_data($hash, &$product, $skip_promotion, &$cart, &$auth, $promotion_amount = 0)
{
    /**
     * Prepare params before getting product data from cart
     *
     * @param string $hash Unique product HASH
     * @param array &$product Product data
     * @param bool $skip_promotion Skip promotion calculation
     * @param array &$cart Array of cart content and user information necessary for purchase
     * @param array &$auth Array with authorization data
     * @param array $promotion_amount Amount of product in promotion (like Free products, etc)
     */
    fn_set_hook('get_cart_product_data_pre', $hash, $product, $skip_promotion, $cart, $auth, $promotion_amount);
    if (!empty($product['product_id'])) {
        $fields = array('?:products.product_id', '?:products.company_id', "GROUP_CONCAT(IF(?:products_categories.link_type = 'M', CONCAT(?:products_categories.category_id, 'M'), ?:products_categories.category_id)) as category_ids", '?:products.product_code', '?:products.weight', '?:products.tracking', '?:product_descriptions.product', '?:product_descriptions.short_description', '?:products.is_edp', '?:products.edp_shipping', '?:products.shipping_freight', '?:products.free_shipping', '?:products.zero_price_action', '?:products.tax_ids', '?:products.qty_step', '?:products.list_qty_count', '?:products.max_qty', '?:products.min_qty', '?:products.amount as in_stock', '?:products.shipping_params', '?:companies.status as company_status', '?:companies.company as company_name');
        $join = db_quote("LEFT JOIN ?:product_descriptions ON ?:product_descriptions.product_id = ?:products.product_id AND ?:product_descriptions.lang_code = ?s", CART_LANGUAGE);
        $_p_statuses = array('A', 'H');
        $_c_statuses = array('A', 'H');
        $avail_cond = AREA == 'C' ? " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:categories.usergroup_ids', true) . ")" : '';
        $avail_cond .= AREA == 'C' ? " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:products.usergroup_ids', true) . ")" : '';
        $avail_cond .= AREA == 'C' && !(isset($auth['area']) && $auth['area'] == 'A') ? db_quote(' AND ?:categories.status IN (?a) AND ?:products.status IN (?a)', $_c_statuses, $_p_statuses) : '';
        $avail_cond .= AREA == 'C' ? fn_get_localizations_condition('?:products.localization') : '';
        $join .= " INNER JOIN ?:products_categories ON ?:products_categories.product_id = ?:products.product_id INNER JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id {$avail_cond}";
        $join .= " LEFT JOIN ?:companies ON ?:companies.company_id = ?:products.company_id";
        if ($product['extra']['price_calc']['total_price_calc']) {
            $productTest = fn_get_product_data($product['product_id'], $auth, CART_LANGUAGE, '', true, true, true, true, fn_is_preview_action($auth, $_REQUEST));
            $productTest['extra']['product_options'] = $product['product_options'];
            fn_gather_additional_product_data($productTest, true, true);
            $product['base_price'] = $productTest['base_price'];
        }
        fn_set_hook('pre_get_cart_product_data', $hash, $product, $skip_promotion, $cart, $auth, $promotion_amount, $fields, $join);
        $_pdata = db_get_row("SELECT " . implode(', ', $fields) . " FROM ?:products ?p WHERE ?:products.product_id = ?i GROUP BY ?:products.product_id", $join, $product['product_id']);
        // delete product from cart if vendor was disabled.
        if (empty($_pdata) || !empty($_pdata['company_id']) && !defined('ORDER_MANAGEMENT') && $_pdata['company_status'] != 'A') {
            fn_delete_cart_product($cart, $hash);
            return false;
        }
        if (!empty($_pdata['category_ids'])) {
            list($_pdata['category_ids'], $_pdata['main_category']) = fn_convert_categories($_pdata['category_ids']);
        } else {
            $_pdata['category_ids'] = array();
        }
        $_pdata['options_count'] = db_get_field("SELECT COUNT(*) FROM ?:product_options WHERE product_id = ?i AND status = 'A'", $product['product_id']);
        $amount = !empty($product['amount_total']) ? $product['amount_total'] : $product['amount'];
        $_pdata['price'] = fn_get_product_price($product['product_id'], $amount, $auth);
        if (!$product['extra']['price_calc']['total_price_calc']) {
            $_pdata['base_price'] = isset($product['stored_price']) && $product['stored_price'] == 'Y' ? $product['price'] : $_pdata['price'];
        } else {
            $_pdata['base_price'] = $product['base_price'];
        }
        fn_set_hook('get_cart_product_data', $product['product_id'], $_pdata, $product, $auth, $cart, $hash);
        if ($product['extra']['price_calc']['total_price_calc']) {
            $_pdata['price'] = $product['base_price'];
        }
        $product['stored_price'] = empty($product['stored_price']) ? 'N' : $product['stored_price'];
        $product['stored_discount'] = empty($product['stored_discount']) ? 'N' : $product['stored_discount'];
        $product['product_options'] = empty($product['product_options']) ? array() : $product['product_options'];
        if (empty($_pdata['product_id'])) {
            // FIXME - for deleted products for OM
            fn_delete_cart_product($cart, $hash);
            return array();
        }
        if (!empty($_pdata['options_count']) && empty($product['product_options'])) {
            $cart['products'][$hash]['product_options'] = fn_get_default_product_options($product['product_id']);
        }
        if (Registry::get('settings.General.inventory_tracking') == 'Y' && !empty($_pdata['tracking']) && $_pdata['tracking'] == 'O' && !empty($product['selectable_cart_id'])) {
            $_pdata['in_stock'] = db_get_field("SELECT amount FROM ?:product_options_inventory WHERE combination_hash = ?i", $product['selectable_cart_id']);
        }
        $product['amount'] = fn_check_amount_in_stock($product['product_id'], $product['amount'], $product['product_options'], $hash, $_pdata['is_edp'], !empty($product['original_amount']) ? $product['original_amount'] : 0, $cart);
        if ($product['amount'] == 0) {
            fn_delete_cart_product($cart, $hash);
            $out_of_stock = true;
            return false;
        }
        if (!fn_allowed_for('ULTIMATE:FREE')) {
            $exceptions = fn_get_product_exceptions($product['product_id'], true);
            if (!isset($product['options_type']) || !isset($product['exceptions_type'])) {
                $product = array_merge($product, db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $product['product_id']));
            }
            if (!fn_is_allowed_options_exceptions($exceptions, $product['product_options'], $product['options_type'], $product['exceptions_type']) && !defined('GET_OPTIONS')) {
                fn_set_notification('E', __('notice'), __('product_options_forbidden_combination', array('[product]' => $_pdata['product'])));
                fn_delete_cart_product($cart, $hash);
                return false;
            }
        }
        if (isset($product['extra']['custom_files'])) {
            $_pdata['extra']['custom_files'] = $product['extra']['custom_files'];
        }
        $_pdata['calculation'] = array();
        if (isset($product['extra']['exclude_from_calculate']) && $product['extra']['exclude_from_calculate']) {
            $_pdata['exclude_from_calculate'] = $product['extra']['exclude_from_calculate'];
            $_pdata['aoc'] = !empty($product['extra']['aoc']);
            $_pdata['price'] = 0;
        } else {
            if ($product['stored_price'] == 'Y') {
                $_pdata['price'] = $product['price'];
            }
        }
        $product['price'] = $_pdata['zero_price_action'] == 'A' && isset($product['custom_user_price']) ? $product['custom_user_price'] : floatval($_pdata['price']);
        $cart['products'][$hash]['price'] = $product['price'];
        $_pdata['original_price'] = $product['price'];
        if ($product['stored_price'] != 'Y' && (!isset($product['extra']['exclude_from_calculate']) || isset($product['extra']['exclude_from_calculate']) && !$product['extra']['exclude_from_calculate'])) {
            $_tmp = $product['price'];
            if (!$product['extra']['price_calc']['total_price_calc']) {
                $product['price'] = fn_apply_options_modifiers($product['product_options'], $product['price'], 'P', array(), array('product_data' => $product));
            }
            $product['modifiers_price'] = $_pdata['modifiers_price'] = $product['price'] - $_tmp;
            // modifiers
        } else {
            $product['modifiers_price'] = $_pdata['modifiers_price'] = 0;
        }
        if (isset($product['modifiers_price']) && $_pdata['zero_price_action'] == 'A') {
            $_pdata['base_price'] = $product['price'] - $product['modifiers_price'];
        }
        $_pdata['weight'] = fn_apply_options_modifiers($product['product_options'], $_pdata['weight'], 'W', array(), array('product_data' => $product));
        $_pdata['amount'] = $product['amount'];
        $_pdata['price'] = $_pdata['original_price'] = fn_format_price($product['price']);
        $_pdata['stored_price'] = $product['stored_price'];
        if ($cart['options_style'] == 'F') {
            $_pdata['product_options'] = fn_get_selected_product_options($product['product_id'], $product['product_options'], CART_LANGUAGE);
        } elseif ($cart['options_style'] == 'I') {
            $_pdata['product_options'] = fn_get_selected_product_options_info($product['product_options'], CART_LANGUAGE);
        } else {
            $_pdata['product_options'] = $product['product_options'];
        }
        fn_set_hook('get_cart_product_data_post_options', $product['product_id'], $_pdata, $product);
        if (($_pdata['free_shipping'] != 'Y' || AREA == 'A') && ($_pdata['is_edp'] != 'Y' || $_pdata['is_edp'] == 'Y' && $_pdata['edp_shipping'] == 'Y')) {
            $cart['shipping_required'] = true;
        }
        $cart['products'][$hash]['is_edp'] = !empty($_pdata['is_edp']) && $_pdata['is_edp'] == 'Y' ? 'Y' : 'N';
        $cart['products'][$hash]['edp_shipping'] = !empty($_pdata['edp_shipping']) && $_pdata['edp_shipping'] == 'Y' ? 'Y' : 'N';
        if (empty($cart['products'][$hash]['extra']['parent'])) {
            // count only products without parent
            if ($skip_promotion == true && !empty($promotion_amount)) {
                $cart['amount'] += $promotion_amount;
            } else {
                $cart['amount'] += $product['amount'];
            }
        }
        if (empty($cart['order_id']) || !empty($cart['recalculate_catalog_promotions'])) {
            fn_promotion_apply('catalog', $_pdata, $auth);
        } else {
            if (isset($product['discount'])) {
                $_pdata['discount'] = $product['discount'];
                $_pdata['price'] -= $product['discount'];
                if ($_pdata['price'] < 0) {
                    $_pdata['discount'] += $_pdata['price'];
                    $_pdata['price'] = 0;
                }
            }
        }
        // apply discount to the product
        if (!empty($_pdata['discount'])) {
            $cart['use_discount'] = true;
        }
        if (!empty($product['object_id'])) {
            $_pdata['object_id'] = $product['object_id'];
        }
        $_pdata['shipping_params'] = empty($_pdata['shipping_params']) ? array() : unserialize($_pdata['shipping_params']);
        $_pdata['stored_discount'] = $product['stored_discount'];
        $cart['products'][$hash]['modifiers_price'] = $product['modifiers_price'];
        $_pdata['subtotal'] = $_pdata['price'] * $product['amount'];
        $cart['original_subtotal'] += $_pdata['original_price'] * $product['amount'];
        $cart['subtotal'] += $_pdata['subtotal'];
        /**
         * Prepare params before getting product data from cart
         *
         * @param string $hash Unique product HASH
         * @param array &$product Product data
         * @param bool $skip_promotion Skip promotion calculation
         * @param array &$cart Array of cart content and user information necessary for purchase
         * @param array &$auth Array with authorization data
         * @param array $promotion_amount Amount of product in promotion (like Free products, etc)
         * @param array $promotion_amount Product data
         */
        fn_set_hook('get_cart_product_data_post', $hash, $product, $skip_promotion, $cart, $auth, $promotion_amount, $_pdata);
        if ($product['extra']['price_calc']['total_price_calc']) {
            $_pdata['display_price'] = $_pdata['price'];
            foreach ($cart['product_groups'] as $key_product_groups => $product_groups) {
                $cart['product_groups'][$key_product_groups]['products'][$hash]['price'] = $_pdata['price'];
                $cart['product_groups'][$key_product_groups]['products'][$hash]['extra']['price_calc']['total_price_calc'] = $_pdata['price'];
            }
        }
        return $_pdata;
    }
    return array();
}
예제 #9
0
function fn_get_cart_product_data($hash, &$product, $skip_promotion, &$cart, &$auth, $promotion_amount = 0)
{
    if (!empty($product['product_id'])) {
        $_p_statuses = array('A', 'H');
        $_c_statuses = array('A', 'H');
        $avail_cond = AREA == 'C' ? " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:categories.usergroup_ids', true) . ")" : '';
        $avail_cond .= AREA == 'C' ? " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:products.usergroup_ids', true) . ")" : '';
        $avail_cond .= AREA == 'C' ? db_quote(' AND ?:categories.status IN (?a) AND ?:products.status IN (?a)', $_c_statuses, $_p_statuses) : '';
        $avail_cond .= AREA == 'C' ? fn_get_localizations_condition('?:products.localization') : '';
        $join = " INNER JOIN ?:products_categories ON ?:products_categories.product_id = ?:products.product_id INNER JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id {$avail_cond}";
        $_pdata = db_get_row("SELECT ?:products.product_id, ?:products.company_id, GROUP_CONCAT(IF(?:products_categories.link_type = 'M', CONCAT(?:products_categories.category_id, 'M'), ?:products_categories.category_id)) as category_ids, ?:products.product_code, ?:products.weight, ?:products.tracking, ?:product_descriptions.product, ?:product_descriptions.short_description, ?:products.is_edp, ?:products.edp_shipping, ?:products.shipping_freight, ?:products.free_shipping, ?:products.zero_price_action, ?:products.tax_ids, ?:products.qty_step, ?:products.list_qty_count, ?:products.max_qty, ?:products.min_qty, ?:products.amount as in_stock FROM ?:products LEFT JOIN ?:product_descriptions ON ?:product_descriptions.product_id = ?:products.product_id AND ?:product_descriptions.lang_code = ?s ?p WHERE ?:products.product_id = ?i GROUP BY ?:products.product_id", CART_LANGUAGE, $join, $product['product_id']);
        $companies =& Registry::get('s_companies');
        // delete product from cart if supplier or vendor was disabled.
        if (empty($_pdata) || !empty($_pdata['company_id']) && ($companies[$_pdata['company_id']]['status'] != 'A' || (PRODUCT_TYPE == 'PROFESSIONAL' || PRODUCT_TYPE == 'COMMUNITY') && Registry::get('settings.Suppliers.enable_suppliers') != 'Y')) {
            return false;
        }
        $_pdata['category_ids'] = fn_convert_categories($_pdata['category_ids']);
        $_pdata['options_count'] = db_get_field("SELECT COUNT(*) FROM ?:product_options WHERE product_id = ?i AND status = 'A'", $product['product_id']);
        $_pdata['price'] = fn_get_product_price($product['product_id'], $product['amount'], $auth);
        $_pdata['base_price'] = isset($product['stored_price']) && $product['stored_price'] == 'Y' ? $product['price'] : $_pdata['price'];
        fn_set_hook('get_cart_product_data', $product['product_id'], $_pdata, $product);
        $product['stored_price'] = empty($product['stored_price']) ? 'N' : $product['stored_price'];
        $product['stored_discount'] = empty($product['stored_discount']) ? 'N' : $product['stored_discount'];
        $product['product_options'] = empty($product['product_options']) ? array() : $product['product_options'];
        if (empty($_pdata['product_id'])) {
            // FIXME - for deleted products for OM
            unset($cart['products'][$hash]);
            return array();
        }
        if (!empty($_pdata['options_count']) && empty($product['product_options'])) {
            $cart['products'][$hash]['product_options'] = fn_get_default_product_options($product['product_id']);
        }
        if (Registry::get('settings.General.inventory_tracking') == 'Y' && !empty($_pdata['tracking']) && $_pdata['tracking'] == 'O' && !empty($product['selectable_cart_id'])) {
            $_pdata['in_stock'] = db_get_field("SELECT amount FROM ?:product_options_inventory WHERE combination_hash = ?i", $product['selectable_cart_id']);
        }
        if (fn_check_amount_in_stock($product['product_id'], $product['amount'], $product['product_options'], $hash, $_pdata['is_edp'], !empty($product['original_amount']) ? $product['original_amount'] : 0, $cart) == false) {
            unset($cart['products'][$hash]);
            $out_of_stock = true;
            return false;
        }
        $exceptions = fn_get_product_exceptions($product['product_id'], true);
        if (!isset($product['options_type']) || !isset($product['exceptions_type'])) {
            $product = array_merge($product, db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $product['product_id']));
        }
        if (!fn_is_allowed_options_exceptions($exceptions, $product['product_options'], $product['options_type'], $product['exceptions_type']) && !defined('GET_OPTIONS')) {
            fn_set_notification('E', fn_get_lang_var('notice'), str_replace('[product]', $_pdata['product'], fn_get_lang_var('product_options_forbidden_combination')));
            unset($cart['products'][$hash]);
            return false;
        }
        if (isset($product['extra']['custom_files'])) {
            $_pdata['extra']['custom_files'] = $product['extra']['custom_files'];
        }
        $_pdata['calculation'] = array();
        if (isset($product['extra']['exclude_from_calculate'])) {
            $_pdata['exclude_from_calculate'] = $product['extra']['exclude_from_calculate'];
            $_pdata['aoc'] = !empty($product['extra']['aoc']);
            $_pdata['price'] = 0;
        } else {
            if ($product['stored_price'] == 'Y') {
                $_pdata['price'] = $product['price'];
            }
        }
        // If price defined and zero price action allows add zero priced product to cart, get price from the database
        if (isset($_pdata['price']) && $_pdata['zero_price_action'] != 'A') {
            $product['price'] = floatval($_pdata['price']);
            $cart['products'][$hash]['price'] = $product['price'];
        }
        $_pdata['original_price'] = $product['price'];
        if ($product['stored_price'] != 'Y' && !isset($product['extra']['exclude_from_calculate'])) {
            if ($_pdata['zero_price_action'] != 'A' || $_pdata['zero_price_action'] == 'A' && empty($product['modifiers_price'])) {
                $_tmp = $product['price'];
                $product['price'] = fn_apply_options_modifiers($product['product_options'], $product['price'], 'P');
                $product['modifiers_price'] = $_pdata['modifiers_price'] = $product['price'] - $_tmp;
                // modifiers
            }
        } else {
            $product['modifiers_price'] = $_pdata['modifiers_price'] = 0;
        }
        if (isset($product['modifiers_price']) && $_pdata['zero_price_action'] == 'A') {
            $_pdata['base_price'] = $product['price'] - $product['modifiers_price'];
        }
        $_pdata['weight'] = fn_apply_options_modifiers($product['product_options'], $_pdata['weight'], 'W');
        $_pdata['amount'] = $product['amount'];
        $_pdata['price'] = $_pdata['original_price'] = fn_format_price($product['price']);
        $_pdata['stored_price'] = $product['stored_price'];
        if ($cart['options_style'] == 'F') {
            $_pdata['product_options'] = fn_get_selected_product_options($product['product_id'], $product['product_options'], CART_LANGUAGE);
        } elseif ($cart['options_style'] == 'I') {
            $_pdata['product_options'] = fn_get_selected_product_options_info($product['product_options'], CART_LANGUAGE);
        } else {
            $_pdata['product_options'] = $product['product_options'];
        }
        if (($_pdata['free_shipping'] != 'Y' || AREA == 'A') && ($_pdata['is_edp'] != 'Y' || $_pdata['is_edp'] == 'Y' && $_pdata['edp_shipping'] == 'Y')) {
            $cart['shipping_required'] = true;
        }
        $cart['products'][$hash]['is_edp'] = !empty($_pdata['is_edp']) && $_pdata['is_edp'] == 'Y' ? 'Y' : 'N';
        $cart['products'][$hash]['edp_shipping'] = !empty($_pdata['edp_shipping']) && $_pdata['edp_shipping'] == 'Y' ? 'Y' : 'N';
        if (empty($cart['products'][$hash]['extra']['parent'])) {
            // count only products without parent
            if ($skip_promotion == true && !empty($promotion_amount)) {
                $cart['amount'] += $promotion_amount;
            } else {
                $cart['amount'] += $product['amount'];
            }
        }
        if ($skip_promotion == false) {
            if (empty($cart['order_id'])) {
                fn_promotion_apply('catalog', $_pdata, $auth);
            } else {
                if (empty($product['original_discount'])) {
                    $product['original_discount'] = !empty($product['discount']) ? $product['discount'] : 0;
                    $cart['products'][$hash]['original_discount'] = $product['original_discount'];
                }
                if (isset($product['discount'])) {
                    $_pdata['discount'] = $product['discount'];
                    $_pdata['price'] -= $product['discount'];
                    if ($_pdata['price'] < 0) {
                        $_pdata['discount'] += $_pdata['price'];
                        $_pdata['price'] = 0;
                    }
                }
            }
            // apply discount to the product
            if (!empty($_pdata['discount'])) {
                $cart['use_discount'] = true;
            }
        }
        if (!empty($product['object_id'])) {
            $_pdata['object_id'] = $product['object_id'];
        }
        $_pdata['stored_discount'] = $product['stored_discount'];
        $cart['products'][$hash]['modifiers_price'] = $product['modifiers_price'];
        $_pdata['subtotal'] = $_pdata['price'] * $product['amount'];
        $cart['original_subtotal'] += $_pdata['original_price'] * $product['amount'];
        $cart['subtotal'] += $_pdata['subtotal'];
        return $_pdata;
    }
    return array();
}