11<?php
2- /*------------------------------------------------------------------------------
3- $Id$
2+ /*
3+ * $Id$
4+ *
5+ * AbanteCart, Ideal OpenSource Ecommerce Solution
6+ * http://www.AbanteCart.com
7+ *
8+ * Copyright © 2011-2026 Belavier Commerce LLC
9+ *
10+ * This source file is subject to Open Software License (OSL 3.0)
11+ * License details are bundled with this package in the file LICENSE.txt.
12+ * It is also available at this URL:
13+ * <http://www.opensource.org/licenses/OSL-3.0>
14+ *
15+ * UPGRADE NOTE:
16+ * Do not edit or add to this file if you wish to upgrade AbanteCart to newer
17+ * versions in the future. If you wish to customize AbanteCart for your
18+ * needs, please refer to http://www.AbanteCart.com for more information.
19+ */
20+ /** @noinspection PhpUnused */
21+ /** @noinspection PhpMultipleClassDeclarationsInspection */
422
5- AbanteCart, Ideal OpenSource Ecommerce Solution
6- http://www.AbanteCart.com
7-
8- Copyright © 2011-2020 Belavier Commerce LLC
9-
10- 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.
12- It is also available at this URL:
13- <http://www.opensource.org/licenses/OSL-3.0>
14-
15- UPGRADE NOTE:
16- Do not edit or add to this file if you wish to upgrade AbanteCart to newer
17- versions in the future. If you wish to customize AbanteCart for your
18- needs please refer to http://www.AbanteCart.com for more information.
19- ------------------------------------------------------------------------------*/
2023if (!defined ('DIR_CORE ' )) {
2124 header ('Location: static_pages/ ' );
2225}
@@ -32,23 +35,22 @@ public function __construct($registry, $instance_id, $controller, $parent_contro
3235
3336 public function main ()
3437 {
35-
3638 //init controller data
3739 $ this ->extensions ->hk_InitData ($ this , __FUNCTION__ );
3840
3941 $ this ->data ['heading_title ' ] = $ this ->language ->get ('heading_title ' , 'blocks/bestseller ' );
4042
41- $ this ->loadModel ('catalog/product ' );
43+ /** @var ModelCatalogProduct $pMdl */
44+ $ pMdl = $ this ->loadModel ('catalog/product ' );
4245 $ this ->loadModel ('catalog/review ' );
4346 $ this ->loadModel ('tool/image ' );
4447
4548 $ this ->data ['button_add_to_cart ' ] = $ this ->language ->get ('button_add_to_cart ' );
46-
4749 $ this ->data ['products ' ] = [];
4850
49- $ results = $ this -> model_catalog_product ->getBestSellerProducts ($ this ->config ->get ('config_bestseller_limit ' ));
51+ $ results = $ pMdl ->getBestSellerProducts ($ this ->config ->get ('config_bestseller_limit ' ));
5052 $ product_ids = array_column ($ results , 'product_id ' );
51- $ products_info = $ this -> model_catalog_product ->getProductsAllInfo ($ product_ids );
53+ $ products_info = $ pMdl ->getProductsAllInfo ($ product_ids );
5254
5355 //get thumbnails by one pass
5456 $ resource = new AResource ('image ' );
@@ -60,51 +62,41 @@ public function main()
6062 $ this ->config ->get ('config_image_product_height ' )
6163 )
6264 : [];
63- $ stock_info = $ this -> model_catalog_product ->getProductsStockInfo ($ product_ids );
65+ $ stock_info = $ pMdl ->getProductsStockInfo ($ product_ids );
6466
6567 foreach ($ results as $ result ) {
66- $ thumbnail = $ thumbnails [$ result ['product_id ' ]];
67- $ rating = $ products_info [$ result ['product_id ' ]]['rating ' ];
68- $ special = false ;
69- $ discount = $ products_info [$ result ['product_id ' ]]['discount ' ];
68+ $ productId = $ result ['product_id ' ];
69+ $ thumbnail = $ thumbnails [$ productId ];
70+ $ rating = $ products_info [$ productId ]['rating ' ];
71+ $ special = $ specialNum = false ;
72+ $ discount = $ products_info [$ productId ]['discount ' ];
7073
7174 if ($ discount ) {
72- $ price = $ this ->currency ->format (
73- $ this ->tax ->calculate (
74- $ discount ,
75- $ result ['tax_class_id ' ],
76- $ this ->config ->get ('config_tax ' )
77- )
78- );
75+ $ priceNum = $ discount ;
7976 } else {
80- $ price = $ this ->currency ->format (
81- $ this ->tax ->calculate (
82- $ result ['price ' ],
77+ $ priceNum = $ result ['price ' ];
78+ $ special = $ products_info [$ productId ]['special ' ];
79+ if ($ special ) {
80+ $ specialNum = $ this ->tax ->calculate (
81+ $ special ,
8382 $ result ['tax_class_id ' ],
8483 $ this ->config ->get ('config_tax ' )
85- )
86- );
87- $ special = $ products_info [$ result ['product_id ' ]]['special ' ];
88- if ($ special ) {
89- $ special = $ this ->currency ->format (
90- $ this ->tax ->calculate (
91- $ special ,
92- $ result ['tax_class_id ' ],
93- $ this ->config ->get ('config_tax ' )
94- )
9584 );
85+ $ special = $ this ->currency ->format ($ specialNum );
9686 }
9787 }
88+ $ priceNum = $ this ->tax ->calculate ($ priceNum , $ result ['tax_class_id ' ], $ this ->config ->get ('config_tax ' ));
89+ $ price = $ this ->currency ->format ($ priceNum );
9890
99- $ options = $ products_info [$ result [ ' product_id ' ] ]['options ' ];
91+ $ options = $ products_info [$ productId ]['options ' ];
10092
10193 if ($ options ) {
102- $ add = $ this ->html ->getSEOURL ('product/product ' , '&product_id= ' .$ result [ ' product_id ' ] , '&encode ' );
94+ $ add = $ this ->html ->getSEOURL ('product/product ' , '&product_id= ' .$ productId , '&encode ' );
10395 } else {
10496 if ($ this ->config ->get ('config_cart_ajax ' )) {
10597 $ add = '# ' ;
10698 } else {
107- $ add = $ this ->html ->getSecureURL ('checkout/cart ' , '&product_id= ' .$ result [ ' product_id ' ] , '&encode ' );
99+ $ add = $ this ->html ->getSecureURL ('checkout/cart ' , '&product_id= ' .$ productId , '&encode ' );
108100 }
109101 }
110102
@@ -113,11 +105,13 @@ public function main()
113105 $ in_stock = false ;
114106 $ no_stock_text = $ this ->language ->get ('text_out_of_stock ' );
115107 $ total_quantity = 0 ;
116- $ stock_checkout = $ result ['stock_checkout ' ] === '' ? $ this ->config ->get ('config_stock_checkout ' ) : $ result ['stock_checkout ' ];
117- if ($ stock_info [$ result ['product_id ' ]]['subtract ' ]) {
108+ $ stock_checkout = $ result ['stock_checkout ' ] === ''
109+ ? $ this ->config ->get ('config_stock_checkout ' )
110+ : $ result ['stock_checkout ' ];
111+ if ($ stock_info [$ productId ]['subtract ' ]) {
118112 $ track_stock = true ;
119- $ total_quantity = $ this -> model_catalog_product -> hasAnyStock ( $ result [ ' product_id ' ] );
120- //we have stock or out of stock checkout is allowed
113+ $ total_quantity = $ pMdl -> hasAnyStock ( $ productId );
114+ //we have stock or out-of- stock checkout is allowed
121115 if ($ total_quantity > 0 || $ stock_checkout ) {
122116 $ in_stock = true ;
123117 }
@@ -128,13 +122,17 @@ public function main()
128122 $ result ,
129123 [
130124 'rating ' => $ rating ,
131- 'stars ' => sprintf ( $ this ->language ->get ('text_stars ' ), $ rating ),
125+ 'stars ' => $ this ->language ->getAndReplace ('text_stars ' , replaces: $ rating ),
132126 'price ' => $ price ,
127+ 'price_num ' => $ priceNum ,
133128 'options ' => $ options ,
134129 'special ' => $ special ,
130+ 'special_num ' => $ specialNum ,
135131 'thumb ' => $ thumbnail ,
136132 'href ' => $ this ->html ->getSEOURL (
137- 'product/product ' , '&product_id= ' .$ result ['product_id ' ], '&encode '
133+ 'product/product ' ,
134+ '&product_id= ' .$ productId ,
135+ true
138136 ),
139137 'add ' => $ add ,
140138 'track_stock ' => $ track_stock ,
0 commit comments