Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
promotional_rule_type_quantity.inc
1 <?php
18 require_once dirname(__FILE__).'/../../promotional_rule/promotional_rule.inc';
19 
32 {
33 
34 
40  function __construct($assetid=0)
41  {
42  parent::__construct($assetid);
43 
44  }//end constructor
45 
46 
53  public function getDiscountTypes()
54  {
55  return Array(
56  'fixed_amount' => 'Fixed Amount',
57  'percentage' => 'Percentage',
58  );
59 
60  }//end getDiscountTypes()
61 
62 
69  public function getDefaultDiscountType()
70  {
71  return 'fixed_amount';
72 
73  }//end getDefaultDiscountType()
74 
75 
88  public function getDefaultRuleData()
89  {
90  return Array(
91  'discount_type' => $this->getDefaultDiscountType(),
92  'discount_options' => Array(),
93  );
94 
95  }//end getDefaultRuleData()
96 
97 
107  public function evaluate(&$asset_data, $rule_data)
108  {
109  $price = $asset_data['price'];
110  $remaining_quantity = $asset_data['quantity'];
111  $discount = 0;
112 
113  $discount_options = $rule_data['discount_options'];
114  $fixed_amount = $rule_data['discount_type'] == 'fixed_amount' ? TRUE : FALSE;
115  $discount_options = array_reverse($discount_options, TRUE);
116  foreach ($discount_options as $asset_quantity => $discount_amount) {
117  if ($remaining_quantity >= $asset_quantity) {
118  $quotient = (int) ($remaining_quantity / $asset_quantity);
119  $remaining_quantity = $remaining_quantity % $asset_quantity;
120  if ($fixed_amount) {
121  $discount += $quotient * $discount_amount;
122  } else {
123  $discount += $quotient * ($asset_quantity * $price * $discount_amount / 100);
124  }
125 
126  if ($remaining_quantity == 0) break;
127  }
128  }
129 
130  $asset_data['discount'] = $discount;
131 
132  }//end evaluate()
133 
134 
135 }//end class
136 
137 ?>