Beispiel #1
0
<?php

//
// $Id: products.post.php 8413 2009-12-16 12:45:19Z imac $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($mode == 'update') {
    $is_restricted = false;
    $show_notice = false;
    fn_set_hook('buy_together_restricted_product', $_REQUEST['product_id'], $auth, $is_restricted, $show_notice);
    if (!$is_restricted) {
        Registry::set('navigation.tabs.buy_together', array('title' => fn_get_lang_var('buy_together'), 'js' => true));
        $params = array('product_id' => $_REQUEST['product_id']);
        $chains = fn_buy_together_get_chains($params, array(), DESCR_SL);
        $view->assign('chains', $chains);
    }
}
Beispiel #2
0
function fn_buy_together_calculate_cart_items(&$cart, &$cart_products, $auth)
{
    if (empty($cart['products'])) {
        return true;
    }
    $is_valid = true;
    $check_amount = Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.allow_negative_amount') != 'Y' ? true : false;
    foreach ($cart['products'] as $key => $product) {
        if (!empty($product['extra']['buy_together'])) {
            $allowed = true;
            $_products = array();
            $cart['products'][$key]['original_amount'] = $product['amount'];
            // Validate the combination
            $params['chain_id'] = $product['extra']['chain']['chain_id'];
            $params['status'] = 'A';
            $params['full_info'] = true;
            $params['date'] = true;
            $params['simple'] = true;
            $chain = fn_buy_together_get_chains($params, $auth);
            if (empty($chain)) {
                $allowed = false;
            }
            $_product = fn_get_product_data($product['product_id'], $auth, CART_LANGUAGE, '', false, false, false, false);
            if (empty($_product) || $check_amount && $product['amount'] > $_product['amount']) {
                $allowed = false;
            }
            foreach ($cart['products'] as $k => $v) {
                if (!empty($v['extra']['parent']['buy_together']) && ($v['extra']['parent']['buy_together'] == $key || isset($product['extra']['buy_id']) && $product['extra']['buy_id'] == $v['extra']['parent']['buy_together'])) {
                    $_products[] = $k;
                    $cart['products'][$k]['original_amount'] = $v['amount'];
                    if (isset($product['extra']['buy_id']) && $product['extra']['buy_id'] == $v['extra']['parent']['buy_together']) {
                        $v['extra']['parent']['buy_together'] = $cart_products[$k]['extra']['parent']['buy_together'] = $cart['products'][$k]['extra']['parent']['buy_together'] = $key;
                    }
                    if ($allowed) {
                        $_product = fn_get_product_data($v['product_id'], $auth, CART_LANGUAGE, '', false, false, false, false);
                        if (empty($_product) || $check_amount && $v['amount'] > $_product['amount'] && !defined('ORDER_MANAGEMENT')) {
                            fn_set_notification('E', fn_get_lang_var('notice'), str_replace(array('[product]', '[amount]'), array($_product['product'], $v['amount']), fn_get_lang_var('buy_together_product_was_removed')));
                            $allowed = false;
                        }
                        if (AREA != 'A' && MODE != 'place_order') {
                            $chain_discount = empty($chain['products'][$v['extra']['chain']['hash']]['discount']) ? 0 : $chain['products'][$v['extra']['chain']['hash']]['discount'];
                            $cart_products[$k]['price'] -= $chain_discount;
                            $cart_products[$k]['base_price'] -= $chain_discount;
                            $cart_products[$k]['price'] = $cart_products[$k]['price'] < 0 ? 0 : $cart_products[$k]['price'];
                            $cart_products[$k]['base_price'] = $cart_products[$k]['base_price'] < 0 ? 0 : $cart_products[$k]['base_price'];
                            $cart_products[$k]['original_price'] = $cart_products[$k]['subtotal'] = $cart_products[$k]['price'];
                        } elseif (AREA != 'A' && MODE == 'place_order') {
                            $cart_products[$k]['discount'] = 0;
                            $cart_products[$k]['base_price'] = $cart_products[$k]['price'] - $cart_products[$k]['modifiers_price'];
                        }
                    }
                }
                if (AREA != 'A' && MODE == 'place_order') {
                    $cart_products[$key]['base_price'] = $cart_products[$key]['price'] - $cart_products[$key]['modifiers_price'];
                }
            }
            if (AREA != 'A' && (!$allowed || count($_products) != count($product['extra']['buy_together']))) {
                $_products[] = $key;
                $cart['amount'] -= $product['amount'];
                foreach ($_products as $c_key) {
                    unset($cart['products'][$c_key]);
                    unset($cart_products[$c_key]);
                }
                $is_valid = false;
            } elseif (AREA != 'A' && MODE != 'place_order') {
                $cart_products[$key]['price'] -= empty($chain['discount']) ? 0 : $chain['discount'];
                if ($cart_products[$key]['price'] < 0) {
                    $cart_products[$key]['price'] = 0;
                }
                $cart_products[$key]['base_price'] -= $chain['discount'];
                $cart_products[$key]['base_price'] = $cart_products[$key]['base_price'] < 0 ? 0 : $cart_products[$key]['base_price'];
                $cart_products[$key]['original_price'] = $cart_products[$key]['subtotal'] = $cart_products[$key]['price'];
            } elseif (AREA != 'A' && MODE == 'place_order') {
                $cart_products[$key]['discount'] = 0;
            }
        }
    }
    if (!$is_valid) {
        fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('buy_together_combination_cannot_be_added'));
    }
    return $is_valid;
}
Beispiel #3
0
/***************************************************************************
*                                                                          *
*    Copyright (c) 2004 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 10229 2010-07-27 14:21:39Z 2tl $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($mode == 'view') {
    $is_restricted = false;
    $show_notices = false;
    fn_set_hook('buy_together_restricted_product', $_REQUEST['product_id'], $auth, $is_restricted, $show_notices);
    if (!$is_restricted) {
        $params['product_id'] = $_REQUEST['product_id'];
        $params['status'] = 'A';
        $params['full_info'] = true;
        $params['date'] = true;
        $chains = fn_buy_together_get_chains($params, $auth);
        $view->assign('chains', $chains);
    }
}