11<?php
2- /** @noinspection PhpMultipleClassDeclarationsInspection */
3-
42/*
53 * $Id$
64 *
108 * Copyright © 2011-2025 Belavier Commerce LLC
119 *
1210 * This source file is subject to Open Software License (OSL 3.0)
13- * 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.
1412 * It is also available at this URL:
1513 * <http://www.opensource.org/licenses/OSL-3.0>
1614 *
1715 * UPGRADE NOTE:
1816 * Do not edit or add to this file if you wish to upgrade AbanteCart to newer
1917 * versions in the future. If you wish to customize AbanteCart for your
20- * needs please refer to http://www.AbanteCart.com for more information.
18+ * needs, please refer to http://www.AbanteCart.com for more information.
2119 */
2220
21+ /** @noinspection PhpMultipleClassDeclarationsInspection */
22+
2323class ControllerResponsesProductProduct extends AController
2424{
2525 public $ error = [];
@@ -38,14 +38,16 @@ public function products()
3838 }
3939 //init controller data
4040 $ this ->extensions ->hk_InitData ($ this , __FUNCTION__ );
41- $ this ->loadModel ('catalog/product ' );
41+ /** @var ModelCatalogProduct $mdl */
42+ $ mdl = $ this ->loadModel ('catalog/product ' );
4243 if (isset ($ post ['coupon_products ' ])) {
4344 $ products = (array )$ post ['coupon_products ' ];
4445 foreach ($ products as $ productId ) {
45- $ productInfo = $ this ->model_catalog_product ->getProduct ((int )$ productId );
46+ $ productId = (int )$ productId ;
47+ $ productInfo = $ mdl ->getProduct ($ productId );
4648 if ($ productInfo ) {
4749 $ output [] = [
48- 'id ' => $ productInfo [ ' product_id ' ] ,
50+ 'id ' => $ productId ,
4951 'name ' => $ productInfo ['name ' ],
5052 'meta ' => $ productInfo ['model ' ],
5153 'sort_order ' => (int )$ productInfo ['sort_order ' ],
@@ -68,7 +70,7 @@ public function products()
6870 $ filter ['filter ' ]['status ' ] = 1 ;
6971 $ filter ['subsql_filter ' ] = 'date_available<=NOW() ' ;
7072 }
71- $ products = $ this -> model_catalog_product ->getProducts ($ filter );
73+ $ products = $ mdl ->getProducts ($ filter );
7274
7375 $ productIds = filterIntegerIdList (array_column ($ products , 'product_id ' ));
7476 $ resource = new AResource ('image ' );
@@ -83,7 +85,6 @@ public function products()
8385
8486 foreach ($ products as $ productData ) {
8587 $ thumbnail = $ thumbnails [$ productData ['product_id ' ]];
86-
8788 if ($ get ['currency_code ' ]) {
8889 $ price = round (
8990 $ this ->currency ->convert (
@@ -104,7 +105,7 @@ public function products()
104105
105106 $ output [] = [
106107 'image ' => $ thumbnail ['thumb_html ' ],
107- 'id ' => $ productData ['product_id ' ],
108+ 'id ' => ( int ) $ productData ['product_id ' ],
108109 'name ' => $ productData ['name ' ] . ' - ' . $ formatted_price ,
109110 'price ' => $ price ,
110111 'meta ' => $ productData ['model ' ],
@@ -147,15 +148,12 @@ public function update()
147148 }
148149
149150 $ this ->loadLanguage ('catalog/product ' );
150- $ this -> loadModel ( ' catalog/product ' );
151-
151+ /** @var ModelCatalogProduct $mdl */
152+ $ mdl = $ this -> loadModel ( ' catalog/product ' );
152153 $ result = '' ;
153154
154155 if ($ this ->request ->is_POST ()) {
155- $ this ->model_catalog_product ->updateProduct (
156- (int )$ this ->request ->get ['product_id ' ],
157- $ this ->request ->post
158- );
156+ $ mdl ->updateProduct ((int )$ this ->request ->get ['product_id ' ], $ this ->request ->post );
159157 $ result = 'Saved! ' ;
160158 }
161159
@@ -169,20 +167,20 @@ public function category()
169167 //init controller data
170168 $ this ->extensions ->hk_InitData ($ this , __FUNCTION__ );
171169
172- $ this -> loadModel ( ' catalog/product ' );
173- $ promotion = new APromotion ( $ this ->request -> get [ ' customer_group_id ' ] );
174-
170+ /** @var ModelCatalogProduct $mdl */
171+ $ mdl = $ this ->loadModel ( ' catalog/product ' );
172+ $ promotion = new APromotion (( int ) $ this -> request -> get [ ' customer_group_id ' ]);
175173 $ categoryId = (int )$ this ->request ->get ['category_id ' ];
176-
177174 $ product_data = [];
178- $ results = $ this -> model_catalog_product ->getProductsByCategoryId ($ categoryId );
175+ $ results = $ mdl ->getProductsByCategoryId ($ categoryId );
179176 foreach ($ results as $ result ) {
180- $ discount = $ promotion ->getProductDiscount ((int )$ result ['product_id ' ]);
177+ $ productId = (int )$ result ['product_id ' ];
178+ $ discount = $ promotion ->getProductDiscount ($ productId );
181179 if ($ discount ) {
182180 $ price = $ discount ;
183181 } else {
184182 $ price = $ result ['price ' ];
185- $ special = $ promotion ->getProductSpecial (( int ) $ result [ ' product_id ' ] );
183+ $ special = $ promotion ->getProductSpecial ($ productId );
186184 if ($ special ) {
187185 $ price = $ special ;
188186 }
@@ -199,7 +197,7 @@ public function category()
199197 }
200198
201199 $ product_data [] = [
202- 'product_id ' => $ result [ ' product_id ' ] ,
200+ 'product_id ' => $ productId ,
203201 'name ' => $ result ['name ' ],
204202 'model ' => $ result ['model ' ],
205203 'price ' => $ price ,
@@ -249,20 +247,20 @@ public function related()
249247 //init controller data
250248 $ this ->extensions ->hk_InitData ($ this , __FUNCTION__ );
251249
252- $ this ->loadModel ('catalog/product ' );
250+ /** @var ModelCatalogProduct $mdl */
251+ $ mdl = $ this ->loadModel ('catalog/product ' );
253252
254253 if (isset ($ this ->request ->post ['product_related ' ])) {
255254 $ products = (array )$ this ->request ->post ['product_related ' ];
256255 } elseif (isset ($ this ->request ->post ['id ' ])) { // variant for popup listing
257- $ products = $ this ->request ->post ['id ' ];
256+ $ products = ( array ) $ this ->request ->post ['id ' ];
258257 } else {
259258 $ products = [];
260259 }
261260 $ product_data = [];
262261
263262 foreach ($ products as $ product_id ) {
264- $ product_info = $ this ->model_catalog_product ->getProduct ($ product_id );
265-
263+ $ product_info = $ mdl ->getProduct ($ product_id );
266264 if ($ product_info ) {
267265 $ product_data [] = [
268266 'id ' => $ product_info ['product_id ' ],
@@ -762,7 +760,7 @@ protected function _option_value_form($form)
762760 if (in_array ($ attribute ['element_type ' ], $ this ->data ['elements_with_options ' ])) {
763761 $ this ->data ['option_attribute ' ]['group ' ][$ attrId ]['type ' ] = 'selectbox ' ;
764762 $ values = $ this ->attribute_manager ->getAttributeValues (
765- $ attribute [ ' attribute_id ' ] ,
763+ $ attrId ,
766764 $ this ->language ->getContentLanguageID ()
767765 );
768766
@@ -2051,22 +2049,17 @@ public function orderProductForm()
20512049 $ this ->processTemplate ('responses/product/product_form.tpl ' );
20522050 }
20532051
2054- public function stockLocations ($ product_id = 0 , $ product_option_value_id = null )
2052+ public function stockLocations ($ product_id = 0 , $ optionValueId = null )
20552053 {
20562054 //init controller data
20572055 $ this ->extensions ->hk_InitData ($ this , __FUNCTION__ );
20582056
2059- $ product_id = $ product_id
2060- ? (int )$ product_id
2061- : $ this ->request ->get ['product_id ' ];
2057+ $ product_id = (int )($ product_id ?: $ this ->request ->get ['product_id ' ]);
2058+ $ optionValueId = (int )($ optionValueId ?: $ this ->request ->get ['product_option_value_id ' ]);
20622059
2063- $ product_option_value_id = $ product_option_value_id
2064- ? (int )$ product_option_value_id
2065- : $ this ->request ->get ['product_option_value_id ' ];
2060+ $ this ->data ['product_option_value_id ' ] = $ optionValueId ;
20662061
2067- $ this ->data ['product_option_value_id ' ] = $ product_option_value_id ;
2068-
2069- if (!$ product_option_value_id ) {
2062+ if (!$ optionValueId ) {
20702063 $ this ->data ['save_url ' ] = $ this ->html ->getSecureURL (
20712064 'listing_grid/product/update_field ' ,
20722065 '&id= ' . $ product_id
@@ -2075,15 +2068,12 @@ public function stockLocations($product_id = 0, $product_option_value_id = null)
20752068
20762069 $ this ->loadLanguage ('catalog/product ' );
20772070 $ this ->loadModel ('catalog/product ' );
2078- $ locations = $ this ->model_catalog_product ->getProductStockLocations (
2079- $ product_id ,
2080- $ product_option_value_id
2081- );
2071+ $ locations = $ this ->model_catalog_product ->getProductStockLocations ($ product_id , $ optionValueId );
20822072
20832073 $ this ->data ['zero_location ' ] = $ this ->html ->buildElement (
20842074 [
20852075 'type ' => 'hidden ' ,
2086- 'name ' => 'stock_location ' . ($ product_option_value_id ? "[ " . $ product_option_value_id . "] " : "" ) . '[0][] ' ,
2076+ 'name ' => 'stock_location ' . ($ optionValueId ? "[ " . $ optionValueId . "] " : "" ) . '[0][] ' ,
20872077 ]
20882078 );
20892079 foreach ($ locations as $ row ) {
@@ -2096,7 +2086,7 @@ public function stockLocations($product_id = 0, $product_option_value_id = null)
20962086 [
20972087 'type ' => 'input ' ,
20982088 'name ' => 'stock_location '
2099- . ($ product_option_value_id ? "[ " . $ product_option_value_id . "] " : "" )
2089+ . ($ optionValueId ? "[ " . $ optionValueId . "] " : "" )
21002090 . '[ ' . $ location_id . '][quantity] ' ,
21012091
21022092 'value ' => $ row ['quantity ' ],
@@ -2107,7 +2097,7 @@ public function stockLocations($product_id = 0, $product_option_value_id = null)
21072097 [
21082098 'type ' => 'input ' ,
21092099 'name ' => 'stock_location '
2110- . ($ product_option_value_id ? "[ " . $ product_option_value_id . "] " : "" )
2100+ . ($ optionValueId ? "[ " . $ optionValueId . "] " : "" )
21112101 . '[ ' . $ location_id . '][sort_order] ' ,
21122102 'value ' => $ row ['sort_order ' ],
21132103 ]
@@ -2123,44 +2113,42 @@ public function stockLocations($product_id = 0, $product_option_value_id = null)
21232113 $ options [$ row ['location_id ' ]] = $ row ['name ' ] . ' ' . $ row ['description ' ];
21242114 }
21252115
2126- $ this ->data ['all_locations ' ] =
2127- [
2128- 'location_list ' => $ this ->html ->buildElement (
2129- [
2130- 'type ' => 'selectbox ' ,
2131- 'id ' => 'location_list '
2132- . ($ product_option_value_id ?: "" ),
2133- 'name ' => 'location_list ' ,
2134- 'value ' => [],
2135- 'options ' => $ options ,
2136- 'style ' => 'chosen static_field ' ,
2137- 'placeholder ' => $ this ->language ->get ('text_select ' ),
2138- 'disabled_options ' => array_keys ((array )$ this ->data ['locations ' ]),
2139- ]
2140- ),
2141- 'quantity ' => $ this ->html ->buildElement (
2142- [
2143- 'type ' => 'input ' ,
2144- 'name ' => 'stock_location '
2145- . ($ product_option_value_id ? "[ " . $ product_option_value_id . "] " : "" )
2146- . '[0][quantity] ' ,
2147- 'value ' => '' ,
2148- 'style ' => 'stock_location_quantity static_field hidden ' ,
2149- 'attr ' => 'disabled ' ,
2150- ]
2151- ),
2152- 'sort_order ' => $ this ->html ->buildElement (
2153- [
2154- 'type ' => 'input ' ,
2155- 'name ' => 'stock_location '
2156- . ($ product_option_value_id ? "[ " . $ product_option_value_id . "] " : "" )
2157- . '[0][sort_order] ' ,
2158- 'value ' => '' ,
2159- 'style ' => 'stock_location_sort_order static_field hidden ' ,
2160- 'attr ' => 'disabled ' ,
2161- ]
2162- ),
2163- ];
2116+ $ this ->data ['all_locations ' ] = [
2117+ 'location_list ' => $ this ->html ->buildElement (
2118+ [
2119+ 'type ' => 'selectbox ' ,
2120+ 'id ' => 'location_list ' . ($ optionValueId ?: "" ),
2121+ 'name ' => 'location_list ' ,
2122+ 'value ' => [],
2123+ 'options ' => $ options ,
2124+ 'style ' => 'chosen static_field ' ,
2125+ 'placeholder ' => $ this ->language ->get ('text_select ' ),
2126+ 'disabled_options ' => array_keys ((array )$ this ->data ['locations ' ]),
2127+ ]
2128+ ),
2129+ 'quantity ' => $ this ->html ->buildElement (
2130+ [
2131+ 'type ' => 'input ' ,
2132+ 'name ' => 'stock_location '
2133+ . ($ optionValueId ? "[ " . $ optionValueId . "] " : "" )
2134+ . '[0][quantity] ' ,
2135+ 'value ' => '' ,
2136+ 'style ' => 'stock_location_quantity static_field hidden ' ,
2137+ 'attr ' => 'disabled ' ,
2138+ ]
2139+ ),
2140+ 'sort_order ' => $ this ->html ->buildElement (
2141+ [
2142+ 'type ' => 'input ' ,
2143+ 'name ' => 'stock_location '
2144+ . ($ optionValueId ? "[ " . $ optionValueId . "] " : "" )
2145+ . '[0][sort_order] ' ,
2146+ 'value ' => '' ,
2147+ 'style ' => 'stock_location_sort_order static_field hidden ' ,
2148+ 'attr ' => 'disabled ' ,
2149+ ]
2150+ ),
2151+ ];
21642152
21652153 //update controller data
21662154 $ this ->extensions ->hk_UpdateData ($ this , __FUNCTION__ );
@@ -2185,9 +2173,9 @@ public function getTaxPrice()
21852173 $ cData = [];
21862174 $ tax = new ATax ($ this ->registry , $ cData );
21872175 if (isset ($ price )) {
2188- $ output = $ tax ->calculate ($ price , $ taxClassId );
2176+ $ output = $ tax ->calculate (( float ) $ price , $ taxClassId );
21892177 } elseif (isset ($ priceWithTax )) {
2190- $ output = $ tax ->calculate ($ priceWithTax , $ taxClassId , true , true );
2178+ $ output = $ tax ->calculate (( float ) $ priceWithTax , $ taxClassId , true , true );
21912179 }
21922180 }
21932181 //update controller data
0 commit comments