/** * insert promotion code (apply promotion code) */ public function insertPromotionCode($code, $order_id) { require_once 'models/ecommerce/ecommerce_promotion.php'; $Promotion = new ecommerce_promotion(); if ($compaign_data = $Promotion->checkCodeMatch($code)) { $data = array(); $data['promotion_id'] = $compaign_data['id']; $data['code'] = $code; $data['order_id'] = $order_id; if ($inserted_code_id = $this->insert($data)) { return $inserted_code_id; } } return false; }
/** * apply discount code * requires basket full detail with calculated sub totals */ public function calculateBasketDiscount(&$basket, $code, $check_code = true) { $promotion_data = false; $basket['face_value_voucher'] = 0; $basket['face_value_voucher_claim'] = 0; $basket['discount'] = 0; $basket['discount_fixed_claim'] = 0; $basket['discount_percentage_claim'] = 0; foreach ($basket['items'] as &$item) { $item['discount'] = 0; } if ($code) { require_once 'models/ecommerce/ecommerce_promotion.php'; $Promotion = new ecommerce_promotion(); $Promotion->setCacheable(false); if ($check_code) { $promotion_data = $Promotion->checkCodeBeforeApply($code, $basket['customer_id'], $basket); } else { $promotion_data = $Promotion->checkCodeMatch($code); } if ($promotion_data) { $promotion_data['discount_fixed_value'] = ecommerce_price::convertCurrency($promotion_data['discount_fixed_value'], GLOBAL_DEFAULT_CURRENCY, $basket['currency']); if ($promotion_data['type']['taxable']) { $this->calculateVoucherDiscount($basket, $promotion_data); } else { $this->calculateCouponDiscount($basket, $promotion_data); } } } return $promotion_data; }