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 */
2021if (!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 . ' '
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}
0 commit comments