@@ -19,7 +19,7 @@ class Helper extends \Magento\Framework\DB\Helper implements \Magento\Reports\Mo
1919 /**
2020 * @var StoreManagerInterface
2121 */
22- protected StoreManagerInterface $ storeManager ;
22+ private StoreManagerInterface $ storeManager ;
2323
2424 /**
2525 * @param ResourceConnection $resource
@@ -55,60 +55,60 @@ public function mergeVisitorProductIndex($mainTable, $data, $matchFields)
5555 */
5656 public function updateReportRatingPos ($ connection , $ type , $ column , $ mainTable , $ aggregationTable )
5757 {
58- $ periodSubSelect = $ connection ->select ();
59- $ ratingSubSelect = $ connection ->select ();
60- $ ratingSelect = $ connection ->select ();
58+ foreach ($ this ->storeManager ->getStores (true ) as $ store ) {
59+ $ periodSubSelect = $ connection ->select ();
60+ $ ratingSubSelect = $ connection ->select ();
61+ $ ratingSelect = $ connection ->select ();
6162
62- switch ($ type ) {
63- case 'year ' :
64- $ periodCol = $ connection ->getDateFormatSql ('t.period ' , '%Y-01-01 ' );
65- break ;
66- case 'month ' :
67- $ periodCol = $ connection ->getDateFormatSql ('t.period ' , '%Y-%m-01 ' );
68- break ;
69- default :
70- $ periodCol = 't.period ' ;
71- break ;
72- }
63+ switch ($ type ) {
64+ case 'year ' :
65+ $ periodCol = $ connection ->getDateFormatSql ('t.period ' , '%Y-01-01 ' );
66+ break ;
67+ case 'month ' :
68+ $ periodCol = $ connection ->getDateFormatSql ('t.period ' , '%Y-%m-01 ' );
69+ break ;
70+ default :
71+ $ periodCol = 't.period ' ;
72+ break ;
73+ }
7374
74- $ columns = [
75- 'period ' => 't.period ' ,
76- 'store_id ' => 't.store_id ' ,
77- 'product_id ' => 't.product_id ' ,
78- 'product_name ' => 't.product_name ' ,
79- 'product_price ' => 't.product_price ' ,
80- ];
75+ $ columns = [
76+ 'period ' => 't.period ' ,
77+ 'store_id ' => 't.store_id ' ,
78+ 'product_id ' => 't.product_id ' ,
79+ 'product_name ' => 't.product_name ' ,
80+ 'product_price ' => 't.product_price ' ,
81+ ];
8182
82- if ($ type == 'day ' ) {
83- $ columns ['id ' ] = 't.id ' ; // to speed-up insert on duplicate key update
84- }
83+ if ($ type == 'day ' ) {
84+ $ columns ['id ' ] = 't.id ' ; // to speed-up insert on duplicate key update
85+ }
8586
86- $ cols = array_keys ($ columns );
87- $ cols ['total_qty ' ] = new \Zend_Db_Expr ('SUM(t. ' . $ column . ') ' );
88- $ periodSubSelect ->from (
89- ['t ' => $ mainTable ],
90- $ cols
91- )->group (
92- ['t.store_id ' , $ periodCol , 't.product_id ' ]
93- )->order (
94- ['t.store_id ' , $ periodCol , 'total_qty DESC ' ]
95- );
87+ $ cols = array_keys ($ columns );
88+ $ cols ['total_qty ' ] = new \Zend_Db_Expr ('SUM(t. ' . $ column . ') ' );
89+ $ periodSubSelect ->from (
90+ ['t ' => $ mainTable ],
91+ $ cols
92+ )->group (
93+ ['t.store_id ' , $ periodCol , 't.product_id ' ]
94+ )->order (
95+ ['t.store_id ' , $ periodCol , 'total_qty DESC ' ]
96+ );
9697
97- $ cols = $ columns ;
98- $ cols [$ column ] = 't.total_qty ' ;
99- $ cols ['rating_pos ' ] = new \Zend_Db_Expr (
100- "(@pos := IF(t.`store_id` <> @prevStoreId OR {$ periodCol } <> @prevPeriod, 1, @pos+1)) "
101- );
102- $ cols ['prevStoreId ' ] = new \Zend_Db_Expr ('(@prevStoreId := t.`store_id`) ' );
103- $ cols ['prevPeriod ' ] = new \Zend_Db_Expr ("(@prevPeriod := {$ periodCol }) " );
104- $ ratingSubSelect ->from ($ periodSubSelect , $ cols );
98+ $ cols = $ columns ;
99+ $ cols [$ column ] = 't.total_qty ' ;
100+ $ cols ['rating_pos ' ] = new \Zend_Db_Expr (
101+ "(@pos := IF(t.`store_id` <> @prevStoreId OR {$ periodCol } <> @prevPeriod, 1, @pos+1)) "
102+ );
103+ $ cols ['prevStoreId ' ] = new \Zend_Db_Expr ('(@prevStoreId := t.`store_id`) ' );
104+ $ cols ['prevPeriod ' ] = new \Zend_Db_Expr ("(@prevPeriod := {$ periodCol }) " );
105+ $ ratingSubSelect ->from ($ periodSubSelect , $ cols );
105106
106- $ cols = $ columns ;
107- $ cols ['period ' ] = $ periodCol ;
108- $ cols [$ column ] = 't. ' . $ column ;
109- $ cols ['rating_pos ' ] = 't.rating_pos ' ;
107+ $ cols = $ columns ;
108+ $ cols ['period ' ] = $ periodCol ;
109+ $ cols [$ column ] = 't. ' . $ column ;
110+ $ cols ['rating_pos ' ] = 't.rating_pos ' ;
110111
111- foreach ($ this ->storeManager ->getStores (true ) as $ store ) {
112112 $ ratingSubSelect ->where ('t.store_id = ' . $ store ->getId ());
113113 $ ratingSelect ->from ($ ratingSubSelect , $ cols );
114114 $ sql = $ ratingSelect ->insertFromSelect ($ aggregationTable , array_keys ($ cols ));
0 commit comments