18 require_once dirname(__FILE__).
'/../../promotional_rule/promotional_rule_edit_fns.inc';
40 parent::__construct();
57 function paintRule(&$asset, &$o, $prefix, $rule_data, $write_access)
60 if (is_null($rule_data)) {
61 $rule_data = $asset->getDefaultRuleData();
65 $o->openField(translate(
'ecom_promotional_rule_type_quantity_discount_type'));
66 $discount_types = $asset->getDiscountTypes();
68 combo_box($prefix.
'[discount_type]', $discount_types, FALSE, $rule_data[
'discount_type']);
70 echo $discount_types[$rule_data[
'discount_type']];
72 $o->note(translate(
'ecom_promotional_rule_type_quantity_discount_type_note'));
77 $o->openField(translate(
'ecom_promotional_rule_type_quantity_new_discount_option'));
78 echo
'<b>'.translate(
'ecom_promotional_rule_type_quantity_asset_quantity').
'</b> ';
79 text_box($prefix.
'[new_asset_quantity]');
80 echo
' ';
81 echo
'<b>'.translate(
'ecom_promotional_rule_type_quantity_discount_amount').
'</b> ';
82 text_box($prefix.
'[new_discount_amount]');
87 $o->openField(translate(
'ecom_promotional_rule_type_quantity_discount_options'));
88 if (empty($rule_data[
'discount_options'])) {
89 echo translate(
'ecom_promotional_rule_type_quantity_no_discount_options');
92 <table
class=
"sq-backend-table">
94 <td
class=
"sq-backend-table-header"><?php echo translate(
'ecom_promotional_rule_type_quantity_asset_quantity'); ?></td>
95 <td
class=
"sq-backend-table-header"><?php echo translate(
'ecom_promotional_rule_type_quantity_discount_amount'); ?></td>
99 <td
class=
"sq-backend-table-header"><?php echo translate(
'delete_question'); ?></td>
106 foreach ($rule_data[
'discount_options'] as $asset_quantity => $discount_amount) {
109 <td
class=
"sq-backend-table-cell">
112 text_box($prefix.
"[discount_options][$i][asset_quantity]", $asset_quantity);
114 echo $asset_quantity;
118 <td
class=
"sq-backend-table-cell">
121 text_box($prefix.
"[discount_options][$i][discount_amount]", $discount_amount);
123 echo $discount_amount;
130 <td
class=
"sq-backend-table-cell">
132 check_box($prefix.
"[discount_options][$i][delete]");
149 $o->sectionNote(translate(
'ecom_promotional_rule_type_quantity_section_note'));
151 return $write_access;
169 if (!isset($_POST[$prefix]))
return FALSE;
172 if (is_null($rule_data)) {
173 $rule_data = $asset->getDefaultRuleData();
177 $discount_type = array_get_index($_POST[$prefix],
'discount_type');
178 if (array_key_exists($discount_type, $asset->getDiscountTypes())) {
179 $rule_data[
'discount_type'] = $discount_type;
183 $discount_options = Array();
184 $post_discount_options = array_get_index($_POST[$prefix],
'discount_options', Array());
185 foreach ($post_discount_options as $i => $option) {
187 if (isset($option[
'delete']))
continue;
190 $asset_quantity = array_get_index($option,
'asset_quantity');
191 $discount_amount = array_get_index($option,
'discount_amount');
192 if (is_numeric($asset_quantity) && is_numeric($discount_amount)) {
193 $asset_quantity = (int) $asset_quantity;
194 if ($asset_quantity > 0) {
195 $discount_options[$asset_quantity] = (float) $discount_amount;
201 $new_asset_quantity = array_get_index($_POST[$prefix],
'new_asset_quantity');
202 $new_discount_amount = array_get_index($_POST[$prefix],
'new_discount_amount');
204 if (is_numeric($new_asset_quantity) && is_numeric($new_discount_amount)) {
205 $new_asset_quantity = (int) $new_asset_quantity;
206 if ($new_asset_quantity > 0) {
207 $discount_options[$new_asset_quantity] = (float) $new_discount_amount;
212 if (!ksort($discount_options))
return FALSE;
215 $rule_data[
'discount_options'] = $discount_options;