#		)
 #	)
 # )
 x_session_register("special_offers_apply");
 $special_offers_apply = array();
 $special_offers_apply['free_shipping'] = false;
 $join_statement = $where_statement = '';
 if ($domain_info) {
     $join_statement = " LEFT JOIN {$tables['domain_bonuses']} ON {$tables['domain_bonuses']}.bonusid = b.bonusid AND {$tables['domain_bonuses']}.domainid = {$domain_info['domainid']}";
     $where_statement = " AND {$tables['domain_bonuses']}.bonusid IS NOT NULL";
 }
 $bonuses = cw_query("SELECT b.bonusid, b.exclusive, b.repeat, b.pid FROM {$tables['bonuses']} b {$join_statement} WHERE b.bonus_active='Y' AND b.start_date<UNIX_TIMESTAMP() and (b.end_date+86400)>UNIX_TIMESTAMP() {$where_statement} ORDER BY priority");
 # Delete all free added products
 foreach ($cart['products'] as $kk => $vv) {
     if ($vv["special_offer"]["free_product"] == 'Y') {
         cw_delete_from_cart($cart, $vv['cartid']);
     } else {
         unset($cart['products'][$kk]['special_offer']);
     }
 }
 # / Delete all free added products
 $affected_product_ids = array("all" => false, "ids" => array());
 if (!empty($bonuses) and is_array($bonuses)) {
     $bonus_subindex = 0;
     for ($k = 0; $k < count($bonuses); $k++) {
         $b = $bonuses[$k];
         $bid = $b['bonusid'] . '.' . $bonus_subindex++;
         // Add subindex, e.g. 10->10.2
         # Pass the bonus if it's exclusive but some other bonuses already applied
         if ($b['exclusive'] == 'Y' && !empty($special_offers_apply['supply'])) {
             continue;
                }
            } else {
                cw_header_location("index.php?target=product&cat={$cat}&page={$page}");
            }
        }
    }
}
if ($action == "delete" && !empty($productindex)) {
    // product from invoice can't be deleted
    if (!empty($cart['info']['quote_doc_id'])) {
        $top_message['type'] = "E";
        $top_message['content'] = cw_get_langvar_by_name("err_delete_product_from_cart_with_quote");
        cw_header_location('index.php?target=' . $target);
    }
    cw_event('on_delete_cart', array($productindex));
    $product_id = cw_delete_from_cart($cart, $productindex);
    $products = cw_call('cw_products_in_cart', array($cart, $userinfo));
    $cart = cw_func_call('cw_cart_calc', array('cart' => $cart, 'products' => $products, 'userinfo' => $userinfo));
    cw_add_top_message(cw_get_langvar_by_name('msg_product_deleted_from_cart'));
    cw_header_location('index.php?target=' . $target);
}
if (in_array($action, array('update', 'ajax_update', 'checkout'))) {
    if (!empty($productindexes)) {
        $warehouse_selection = array();
        cw_event('on_cart_productindexes_update', array(&$cart, $productindexes));
        $min_amount_warns = cw_call('cw_update_quantity_in_cart', array(&$cart, $productindexes, $warehouse_selection));
        if (!empty($min_amount_warns) && !empty($cart['products'])) {
            $min_amount_ids = array();
            foreach ($cart['products'] as $k => $v) {
                if (!isset($min_amount_warns[$v['cartid']]) || !isset($productindexes[$k]) || isset($min_amount_ids[$v['product_id']])) {
                    continue;