Skip to content

Commit 9930ec3

Browse files
committed
core: added fixed amount delta for specials and quantity discounts of products.
1 parent 65cd656 commit 9930ec3

File tree

11 files changed

+255
-288
lines changed

11 files changed

+255
-288
lines changed

public_html/admin/controller/pages/catalog/product_promotions.php

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
* AbanteCart, Ideal OpenSource Ecommerce Solution
66
* http://www.AbanteCart.com
77
*
8-
* Copyright © 2011-2025 Belavier Commerce LLC
8+
* Copyright © 2011-2026 Belavier Commerce LLC
99
*
1010
* This source file is subject to Open Software License (OSL 3.0)
11-
* License details is bundled with this package in the file LICENSE.txt.
11+
* License details are bundled with this package in the file LICENSE.txt.
1212
* It is also available at this URL:
1313
* <http://www.opensource.org/licenses/OSL-3.0>
1414
*
1515
* UPGRADE NOTE:
1616
* Do not edit or add to this file if you wish to upgrade AbanteCart to newer
1717
* versions in the future. If you wish to customize AbanteCart for your
18-
* needs please refer to http://www.AbanteCart.com for more information.
18+
* needs, please refer to http://www.AbanteCart.com for more information.
1919
*/
20+
/** @noinspection PhpMultipleClassDeclarationsInspection */
2021
if (!defined('DIR_CORE') || !IS_ADMIN) {
2122
header('Location: static_pages/');
2223
}
@@ -30,9 +31,10 @@ public function main()
3031
//init controller data
3132
$this->extensions->hk_InitData($this, __FUNCTION__);
3233

33-
$productId = (int)$this->request->get['product_id'];
34+
$productId = (int) $this->request->get['product_id'];
3435
$this->loadLanguage('catalog/product');
35-
$this->loadModel('catalog/product');
36+
/** @var ModelCatalogProduct $mdl */
37+
$mdl = $this->loadModel('catalog/product');
3638

3739
if ($productId && $this->request->is_GET()) {
3840
$product_info = $this->model_catalog_product->getProduct($productId);
@@ -46,36 +48,26 @@ public function main()
4648
$post = $this->request->post;
4749
foreach (['date_start', 'date_end'] as $datetime) {
4850
if ($post[$datetime]) {
49-
$post[$datetime] = dateDisplay2ISO(
50-
$post[$datetime],
51-
$this->language->get('date_format_short')
52-
);
51+
$post[$datetime] = dateDisplay2ISO($post[$datetime], $this->language->get('date_format_short'));
5352
}
5453
}
5554

5655
if ($post['promotion_type'] == 'discount') {
57-
if (has_value($this->request->get['product_discount_id'])) { //update
58-
$this->model_catalog_product->updateProductDiscount(
59-
$this->request->get['product_discount_id'],
60-
$post
61-
);
62-
} else { //insert
63-
$this->data['product_discount_id'] = $this->model_catalog_product->addProductDiscount(
64-
$productId,
65-
$post
66-
);
56+
$post['quantity'] = max((int) $post['quantity'], 2);
57+
//update
58+
if (has_value($this->request->get['product_discount_id'])) {
59+
$mdl->updateProductDiscount((int) $this->request->get['product_discount_id'], $post);
60+
} //insert
61+
else {
62+
$this->data['product_discount_id'] = $mdl->addProductDiscount($productId, $post);
6763
}
6864
} elseif ($post['promotion_type'] == 'special') {
69-
if (has_value($this->request->get['product_special_id'])) { //update
70-
$this->model_catalog_product->updateProductSpecial(
71-
$this->request->get['product_special_id'],
72-
$post
73-
);
74-
} else { //insert
75-
$this->data['product_special_id'] = $this->model_catalog_product->addProductSpecial(
76-
$productId,
77-
$post
78-
);
65+
//update
66+
if (has_value($this->request->get['product_special_id'])) {
67+
$mdl->updateProductSpecial((int) $this->request->get['product_special_id'], $post);
68+
} //insert
69+
else {
70+
$this->data['product_special_id'] = $mdl->addProductSpecial($productId, $post);
7971
}
8072
}
8173
$this->session->data['success'] = $this->language->get('text_success');
@@ -88,7 +80,7 @@ public function main()
8880
);
8981
}
9082

91-
$this->data['product_description'] = $this->model_catalog_product->getProductDescriptions(
83+
$this->data['product_description'] = $mdl->getProductDescriptions(
9284
$productId,
9385
$this->language->getContentLanguageID()
9486
);
@@ -146,7 +138,7 @@ public function main()
146138
$this->data['form_title'] = $this->language->get('text_edit')
147139
. '&nbsp;'
148140
. $this->language->get('text_product');
149-
$this->data['product_discounts'] = $this->model_catalog_product->getProductDiscounts(
141+
$this->data['product_discounts'] = $mdl->getProductDiscounts(
150142
$productId
151143
);
152144
$this->data['delete_discount'] = $this->html->getSecureURL(
@@ -158,9 +150,7 @@ public function main()
158150
'&product_id=' . $productId . '&product_discount_id=%ID%'
159151
);
160152

161-
$this->data['product_specials'] = $this->model_catalog_product->getProductSpecials(
162-
$productId
163-
);
153+
$this->data['product_specials'] = $mdl->getProductSpecials($productId);
164154
$this->data['delete_special'] = $this->html->getSecureURL(
165155
'catalog/product_promotions/delete',
166156
'&product_id=' . $productId . '&product_special_id=%ID%'
@@ -183,13 +173,13 @@ public function main()
183173
$this->data['button_remove'] = $this->html->buildElement(
184174
[
185175
'type' => 'button',
186-
'text' => $this->language->get('button_remove')
176+
'text' => $this->language->get('button_remove'),
187177
]
188178
);
189179
$this->data['button_edit'] = $this->html->buildElement(
190180
[
191181
'type' => 'button',
192-
'text' => $this->language->get('button_edit')
182+
'text' => $this->language->get('button_edit'),
193183
]
194184
);
195185
$this->data['button_add_discount'] = $this->html->buildElement(
@@ -199,7 +189,7 @@ public function main()
199189
'href' => $this->html->getSecureURL(
200190
'catalog/product_discount_form/insert',
201191
'&product_id=' . $productId
202-
)
192+
),
203193
]
204194
);
205195
$this->data['button_add_special'] = $this->html->buildElement(
@@ -223,7 +213,7 @@ public function main()
223213

224214
$this->view->assign('help_url', $this->gen_help_url('product_promotions'));
225215
if ($this->config->get('config_embed_status')) {
226-
$this->data['product_store'] = $this->model_catalog_product->getProductStores($productId);
216+
$this->data['product_store'] = $mdl->getProductStores($productId);
227217
$btnData = getEmbedButtonsData(
228218
'common/do_embed/product',
229219
['product_id' => $productId],
@@ -245,17 +235,18 @@ public function delete()
245235
$this->extensions->hk_InitData($this, __FUNCTION__);
246236

247237
$this->loadLanguage('catalog/product');
248-
$this->loadModel('catalog/product');
238+
/** @var ModelCatalogProduct $mdl */
239+
$mdl = $this->loadModel('catalog/product');
249240
if (has_value($this->request->get['product_discount_id'])) {
250-
$this->model_catalog_product->deleteProductDiscount($this->request->get['product_discount_id']);
241+
$mdl->deleteProductDiscount((int) $this->request->get['product_discount_id']);
251242
} elseif (has_value($this->request->get['product_special_id'])) {
252-
$this->model_catalog_product->deleteProductSpecial($this->request->get['product_special_id']);
243+
$mdl->deleteProductSpecial((int) $this->request->get['product_special_id']);
253244
}
254245
$this->session->data['success'] = $this->language->get('text_success');
255246
redirect(
256247
$this->html->getSecureURL(
257248
'catalog/product_promotions',
258-
'&product_id=' . (int)$this->request->get['product_id']
249+
'&product_id=' . (int) $this->request->get['product_id']
259250
)
260251
);
261252

@@ -270,10 +261,11 @@ protected function _validateForm()
270261
}
271262

272263
if (has_value($this->request->post['promotion_type'])) {
273-
$start = $this->request->post['date_start'];
274-
$end = $this->request->post['date_end'];
264+
$start = (string) $this->request->post['date_start'];
265+
$end = (string) $this->request->post['date_end'];
275266

276-
if ($start != '0000-00-00' && $end != '0000-00-00' && $start != '' && $end != ''
267+
if ($start != ''
268+
&& $end != ''
277269
&& dateFromFormat($start, $this->language->get('date_format_short'))
278270
> dateFromFormat($end, $this->language->get('date_format_short'))
279271
) {
@@ -282,7 +274,6 @@ protected function _validateForm()
282274
}
283275

284276
$this->extensions->hk_ValidateData($this, [__FUNCTION__]);
285-
286277
return (!$this->error);
287278
}
288279
}

public_html/admin/controller/responses/catalog/product_discount_form.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
/** @noinspection PhpMultipleClassDeclarationsInspection */
23

34
/*
45
* $Id$
56
*
67
* AbanteCart, Ideal OpenSource Ecommerce Solution
78
* http://www.AbanteCart.com
89
*
9-
* Copyright © 2011-2025 Belavier Commerce LLC
10+
* Copyright © 2011-2026 Belavier Commerce LLC
1011
*
1112
* This source file is subject to Open Software License (OSL 3.0)
1213
* License details are bundled with this package in the file LICENSE.txt.
@@ -56,8 +57,8 @@ protected function _getForm()
5657
/** @var ModelCatalogProduct $mdl */
5758
$mdl = $this->loadModel('catalog/product');
5859
$view = new AView($this->registry, 0);
59-
$productId = (int)$this->request->get['product_id'];
60-
$discountId = (int)$this->request->get['product_discount_id'];
60+
$productId = (int) $this->request->get['product_id'];
61+
$discountId = (int) $this->request->get['product_discount_id'];
6162

6263
$view->batchAssign($this->language->getASet('catalog/product'));
6364

@@ -85,19 +86,13 @@ protected function _getForm()
8586

8687
if ($discountId && $this->request->is_GET()) {
8788
$discount_info = $mdl->getProductDiscount($discountId);
88-
if ($discount_info['date_start'] == '0000-00-00') {
89-
$discount_info['date_start'] = '';
90-
}
91-
if ($discount_info['date_end'] == '0000-00-00') {
92-
$discount_info['date_end'] = '';
93-
}
9489
}
9590

9691
$this->loadModel('sale/customer_group');
9792
$results = $this->model_sale_customer_group->getCustomerGroups();
9893
$this->data['customer_groups'] = array_column($results, 'name', 'customer_group_id');
9994

100-
$fields = ['customer_group_id', 'quantity', 'priority', 'price_prefix', 'price', 'date_start', 'date_end',];
95+
$fields = ['customer_group_id', 'quantity', 'priority', 'price_prefix', 'price', 'date_start', 'date_end'];
10196
foreach ($fields as $f) {
10297
if (isset ($this->request->post [$f])) {
10398
$this->data [$f] = $this->request->post [$f];
@@ -197,38 +192,35 @@ protected function _getForm()
197192

198193
$this->data['form']['fields']['quantity'] = $form->getFieldHtml(
199194
[
200-
'type' => 'input',
195+
'type' => 'number',
201196
'name' => 'quantity',
202-
'value' => $this->data['quantity'],
203-
'style' => 'small-field',
197+
'value' => $this->data['quantity'] ? : 2,
204198
]
205199
);
206200
$this->data['form']['fields']['priority'] = $form->getFieldHtml(
207201
[
208202
'type' => 'input',
209203
'name' => 'priority',
210-
'value' => $this->data['priority'],
211-
'style' => 'small-field',
204+
'value' => $this->data['priority'] ? : 1,
212205
]
213206
);
214-
$currencyInfo = $this->currency->getCurrency($this->config->get('config_currency'));
215207
$this->data['form']['fields']['price_prefix'] = $form->getFieldHtml(
216208
[
217209
'type' => 'selectbox',
218210
'name' => 'price_prefix',
219211
'value' => $this->data['price_prefix'],
220212
'options' => [
221-
'$' => $currencyInfo['symbol_left'] . $currencyInfo['symbol_right'],
222-
'%' => '%'
223-
]
213+
'$' => $this->language->get('text_new_price'),
214+
'%' => $this->language->get('text_prc_off'),
215+
'Δ' => $this->language->get('text_fixed_amount_off'),
216+
],
224217
]
225218
);
226219
$this->data['form']['fields']['price'] = $form->getFieldHtml(
227220
[
228221
'type' => 'input',
229222
'name' => 'price',
230223
'value' => moneyDisplayFormat($this->data['price']),
231-
'style' => 'tiny-field',
232224
]
233225
);
234226

@@ -262,8 +254,8 @@ protected function _getForm()
262254

263255
$view->assign('help_url', $this->gen_help_url('product_discount_edit'));
264256
$view->batchAssign($this->data);
257+
/** @see public_html/admin/view/default/template/responses/catalog/product_promotion_form.tpl */
265258
$this->data['response'] = $view->fetch('responses/catalog/product_promotion_form.tpl');
266259
$this->response->setOutput($this->data['response']);
267260
}
268-
269261
}

public_html/admin/controller/responses/catalog/product_special_form.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
2+
/** @noinspection PhpMultipleClassDeclarationsInspection */
3+
24
/*
35
* $Id$
46
*
57
* AbanteCart, Ideal OpenSource Ecommerce Solution
68
* http://www.AbanteCart.com
79
*
8-
* Copyright © 2011-2025 Belavier Commerce LLC
10+
* Copyright © 2011-2026 Belavier Commerce LLC
911
*
1012
* This source file is subject to Open Software License (OSL 3.0)
1113
* License details are bundled with this package in the file LICENSE.txt.
@@ -84,12 +86,6 @@ private function _getForm()
8486

8587
if ($specialId) {
8688
$special_info = $mdl->getProductSpecial($specialId);
87-
if ($special_info['date_start'] == '0000-00-00') {
88-
$special_info['date_start'] = '';
89-
}
90-
if ($special_info['date_end'] == '0000-00-00') {
91-
$special_info['date_end'] = '';
92-
}
9389
}
9490

9591
$this->loadModel('sale/customer_group');
@@ -192,19 +188,20 @@ private function _getForm()
192188
[
193189
'type' => 'input',
194190
'name' => 'priority',
195-
'value' => $this->data['priority'],
191+
'value' => $this->data['priority'] ?: 1,
196192
'style' => 'small-field',
197193
]
198194
);
199-
$currencyInfo = $this->currency->getCurrency($this->config->get('config_currency'));
195+
200196
$this->data['form']['fields']['price_prefix'] = $form->getFieldHtml(
201197
[
202198
'type' => 'selectbox',
203199
'name' => 'price_prefix',
204200
'value' => $this->data['price_prefix'],
205201
'options' => [
206-
'$' => $currencyInfo['symbol_left'] . $currencyInfo['symbol_right'],
207-
'%' => '%'
202+
'$' => $this->language->get('text_new_price'),
203+
'%' => $this->language->get('text_prc_off'),
204+
'Δ' => $this->language->get('text_fixed_amount_off')
208205
]
209206
]
210207
);
@@ -214,7 +211,6 @@ private function _getForm()
214211
'type' => 'input',
215212
'name' => 'price',
216213
'value' => moneyDisplayFormat($this->data['price']),
217-
'style' => 'tiny-field',
218214
]
219215
);
220216

@@ -250,6 +246,7 @@ private function _getForm()
250246

251247
$view->assign('help_url', $this->gen_help_url('product_special_edit'));
252248
$view->batchAssign($this->data);
249+
/** @see public_html/admin/view/default/template/responses/catalog/product_promotion_form.tpl */
253250
$this->data['response'] = $view->fetch('responses/catalog/product_promotion_form.tpl');
254251
$this->response->setOutput($this->data['response']);
255252
}

public_html/admin/language/english/catalog/product.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,17 @@
658658
<key>entry_html_attributes</key>
659659
<value><![CDATA[html-attributes:<br /><span class="help">You can add your custom html-attributes for option element. Example: data-some-attribute="some value"</span>]]></value>
660660
</definition>
661+
662+
<definition>
663+
<key>text_new_price</key>
664+
<value><![CDATA[New Price]]></value>
665+
</definition>
666+
<definition>
667+
<key>text_prc_off</key>
668+
<value><![CDATA[% Off]]></value>
669+
</definition>
670+
<definition>
671+
<key>text_fixed_amount_off</key>
672+
<value><![CDATA[Fixed Amount Off]]></value>
673+
</definition>
661674
</definitions>

public_html/admin/language/english/english.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@
257257
<value><![CDATA[Data]]></value>
258258
</definition>
259259
<definition>
260-
<key>tab_discount</key>
261-
<value><![CDATA[Discounts]]></value>
260+
<key>text_quantity_discount</key>
261+
<value><![CDATA[Quantity Discounts]]></value>
262262
</definition>
263263
<definition>
264264
<key>tab_details</key>

0 commit comments

Comments
 (0)