} # / 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; } # save the current affected products in case the whole condition is not met $_affected_product_ids = $affected_product_ids; if (cw_special_offer_check($b['bonusid'])) { $current_bonus_supply = cw_query_hash("SELECT type, data FROM {$tables['bonus_supply']} WHERE bonusid='{$b['bonusid']}'", "type", false, true); $current_bonus_supply = array_map("unserialize", $current_bonus_supply); # Add applicable bonus info $special_offers_apply['supply'][$bid] = $current_bonus_supply; # # Prepare common array of supplies # $special_offers_apply['free_shipping']['method'] = cw_array_merge($special_offers_apply['free_shipping']['method'], $current_bonus_supply['S']['method']); if ($current_bonus_supply['S']['type'] == 'Y') { $special_offers_apply['free_shipping']['type'] = 'Y'; } if (in_array($current_bonus_supply['S']['type'], array('C', 'S')) && $special_offers_apply['free_shipping']['type'] != 'Y') { $special_offers_apply['free_shipping']['type'] = $current_bonus_supply['S']['type']; } if ($current_bonus_supply['S']['type'] == 'C') {
global $affected_product_ids, $_affected_product_ids; $affected_product_ids = array(); if (!empty($offers) and is_array($offers)) { $bonus_subindex = 0; // Subindex is just a suffix required to make repeatable offers unique in offers array for ($k = 0; $k < count($offers); $k++) { $b = $offers[$k]; $bid = $b['offer_id'] . '.' . $bonus_subindex++; // Add subindex, e.g. 10->10.2 # Forget the offer if it's exclusive but some other offers already applied if ($b['exclusive'] == 'Y' && !empty($special_offers_apply['supply'])) { continue; } # temporary save the current affected products in case the whole condition is not met $_affected_product_ids = $affected_product_ids; if (cw_special_offer_check($b['offer_id'])) { $current_bonuses = cw_call('cw_ps_offer_bonuses', array($b['offer_id'])); /* $current_bonuses = cw_query_hash("SELECT b.type, b.apply, b.coupon, b.discount, b.disctype, bd.object_id, bd.quantity, bd.object_type FROM $tables[ps_bonuses] b LEFT JOIN $tables[ps_bonus_details] bd ON b.bonus_id=bd.bonus_id WHERE b.offer_id='$b[offer_id]'",'type',true,false); foreach ($current_bonuses as $type=>$bonuses) foreach($bonuses as $kk=>$bonus) { if ($type == PS_COUPON) $current_bonuses[$type][$kk] = array_intersect_key($bonus,array('coupon'=>1)); if ($type == PS_FREE_PRODS) $current_bonuses[$type][$kk] = array_intersect_key($bonus,array('object_id'=>1,'quantity'=>1,'object_type'=>1)); if ($type == PS_DISCOUNT || $type == PS_FREE_SHIP) { if ($bonus['apply'] != PS_APPLY_PRODS) { unset($bonus['object_id'],$bonus['quantity'],$bonus['object_type']); } $current_bonuses[$type][$kk] = array_intersect_key($bonus,array('object_id'=>1,'quantity'=>1,'discount'=>1,'disctype'=>1,'apply'=>1,'object_type'=>1));