@@ -73,7 +73,6 @@ public function __construct(
73
73
* @param array $values
74
74
*
75
75
* @return array
76
- *
77
76
* @throws UnableRetrieveData
78
77
*/
79
78
public function get (array $ values ) : array
@@ -83,37 +82,39 @@ public function get(array $values) : array
83
82
$ mappedProducts = [];
84
83
$ attributesData = [];
85
84
86
- try {
87
- foreach ($ values as $ value ) {
88
- $ scope = $ value ['scopeId ' ] ?? Store::DEFAULT_STORE_ID ;
89
- $ queryArguments [$ scope ][$ value ['productId ' ]] = $ value ['attribute_ids ' ] ?? [];
90
- }
85
+ foreach ($ values as $ value ) {
86
+ $ scope = $ value ['scopeId ' ] ?? Store::DEFAULT_STORE_ID ;
87
+ $ queryArguments [$ scope ][$ value ['productId ' ]] = $ value ['attribute_ids ' ] ?? [];
88
+ }
91
89
92
- $ connection = $ this ->resourceConnection ->getConnection ();
93
- foreach ($ queryArguments as $ scopeId => $ productData ) {
94
- $ cursor = $ connection ->query (
95
- $ this ->productMainQuery ->getQuery (\array_keys ($ productData ), $ scopeId ?: null )
96
- );
90
+ $ connection = $ this ->resourceConnection ->getConnection ();
91
+ foreach ($ queryArguments as $ scopeId => $ productData ) {
92
+ $ cursor = $ connection ->query (
93
+ $ this ->productMainQuery ->getQuery (\array_keys ($ productData ), $ scopeId ?: null )
94
+ );
97
95
98
- while ($ row = $ cursor ->fetch ()) {
99
- $ mappedProducts [$ row ['storeViewCode ' ]][$ row ['productId ' ]] = $ row ;
100
- $ attributesData [$ row ['storeViewCode ' ]][$ row ['productId ' ]] = $ productData [$ row ['productId ' ]];
101
- }
96
+ while ($ row = $ cursor ->fetch ()) {
97
+ $ mappedProducts [$ row ['storeViewCode ' ]][$ row ['productId ' ]] = $ row ;
98
+ $ attributesData [$ row ['storeViewCode ' ]][$ row ['productId ' ]] = $ productData [$ row ['productId ' ]];
102
99
}
103
-
104
- foreach ($ mappedProducts as $ storeCode => $ products ) {
105
- $ output [] = \array_map (function ($ row ) {
106
- return $ this ->formatter ->format ($ row );
107
- }, \array_replace_recursive (
108
- $ products ,
109
- $ this ->entityEavAttributesResolver ->resolve ($ attributesData [$ storeCode ], $ storeCode )
110
- ));
111
- }
112
- } catch (\Throwable $ exception ) {
113
- $ this ->logger ->error ($ exception ->getMessage (), ['exception ' => $ exception ]);
114
- throw new UnableRetrieveData ('Unable to retrieve product data ' );
100
+ }
101
+ if (!$ mappedProducts ) {
102
+ $ productsIds = \implode (', ' , \array_unique (\array_column ($ values , 'productId ' )));
103
+ $ scopes = \implode (', ' , \array_unique (\array_column ($ values , 'scopeId ' )));
104
+ throw new UnableRetrieveData (
105
+ \sprintf ('Cannot collect product data for ids %s in scopes %s ' , $ productsIds , $ scopes )
106
+ );
115
107
}
116
108
109
+ foreach ($ mappedProducts as $ storeCode => $ products ) {
110
+ $ output [] = \array_map (function ($ row ) {
111
+ return $ this ->formatter ->format ($ row );
112
+ }, \array_replace_recursive (
113
+ $ products ,
114
+ $ this ->entityEavAttributesResolver ->resolve ($ attributesData [$ storeCode ], $ storeCode )
115
+ ));
116
+ }
117
+ /** @phpstan-ignore-next-line */
117
118
return !empty ($ output ) ? \array_merge (...$ output ) : [];
118
119
}
119
120
}
0 commit comments