コード例 #1
0
ファイル: Discounts.php プロジェクト: forthrobot/inuvik
 /**
  * Adds a discount entry for a promotion that applies
  *
  * @author Jonathan Davis
  * @since 1.1
  * @version 1.3
  *
  * @param Object $Promotion The pseudo-Promotion object to apply
  * @param float $discount The calculated discount amount
  * @return void
  **/
 private function apply(ShoppOrderPromo $Promo)
 {
     $exists = $this->exists($Promo->id);
     $itemrules = isset($Promo->rules['item']);
     // If it already is applied and the promo does not have item rules
     if ($exists && !$itemrules) {
         return;
     }
     $this->applycode($Promo);
     // Apply the appropriate discount code from the promo
     // Build the discount to apply to the order
     $Discount = new ShoppOrderDiscount();
     $Discount->ShoppOrderPromo($Promo);
     // Check matching line item discount targets to apply the discount to
     if ($itemrules) {
         $this->items($Promo, $Discount);
         $items = $Discount->items();
         if (empty($items)) {
             // No items match
             if ($exists) {
                 $this->reset($Promo);
             }
             // If it was applied, remove the discount
             return;
             // Do not apply the discount
         }
     }
     $this->add($Promo->id, $Discount);
     $this->shipping($Discount);
     // Flag shipping changes
 }