@@ -228,92 +228,6 @@ public function getConfigurableAttributesData()
228228 return $ result ;
229229 }
230230
231- protected function prepareVariations2 (): array
232- {
233- $ variations = $ this ->getVariations ();
234- $ productMatrix = [];
235- $ attributes = [];
236- $ productIds = [];
237- if ($ variations ) {
238- $ usedProductAttributes = $ this ->getUsedAttributes ();
239- $ productByUsedAttributes = $ this ->getAssociatedProducts ();
240- $ currency = $ this ->localeCurrency ->getCurrency ($ this ->locator ->getBaseCurrencyCode ());
241- $ configurableAttributes = $ this ->getAttributes ();
242- foreach ($ variations as $ variation ) {
243- $ attributeValues = [];
244- foreach ($ usedProductAttributes as $ attribute ) {
245- $ attributeValues [$ attribute ->getAttributeCode ()] = $ variation [$ attribute ->getId ()]['value ' ];
246- }
247- $ key = implode ('- ' , $ attributeValues );
248- if (isset ($ productByUsedAttributes [$ key ])) {
249- $ product = $ productByUsedAttributes [$ key ];
250- $ price = $ product ->getPrice ();
251- $ variationOptions = [];
252- foreach ($ usedProductAttributes as $ attribute ) {
253- if (!isset ($ attributes [$ attribute ->getAttributeId ()])) {
254- $ attributes [$ attribute ->getAttributeId ()] = [
255- 'code ' => $ attribute ->getAttributeCode (),
256- 'label ' => $ attribute ->getStoreLabel (),
257- 'id ' => $ attribute ->getAttributeId (),
258- 'position ' => $ configurableAttributes [$ attribute ->getAttributeId ()]['position ' ],
259- 'chosen ' => [],
260- ];
261- $ options = $ attribute ->usesSource () ? $ attribute ->getSource ()->getAllOptions () : [];
262- foreach ($ options as $ option ) {
263- if (!empty ($ option ['value ' ])) {
264- $ attributes [$ attribute ->getAttributeId ()]['options ' ][$ option ['value ' ]] = [
265- 'attribute_code ' => $ attribute ->getAttributeCode (),
266- 'attribute_label ' => $ attribute ->getStoreLabel (0 ),
267- 'id ' => $ option ['value ' ],
268- 'label ' => $ option ['label ' ],
269- 'value ' => $ option ['value ' ],
270- ];
271- }
272- }
273- }
274- $ optionId = $ variation [$ attribute ->getId ()]['value ' ];
275- $ variationOption = [
276- 'attribute_code ' => $ attribute ->getAttributeCode (),
277- 'attribute_label ' => $ attribute ->getStoreLabel (0 ),
278- 'id ' => $ optionId ,
279- 'label ' => $ variation [$ attribute ->getId ()]['label ' ],
280- 'value ' => $ optionId ,
281- ];
282- $ variationOptions [] = $ variationOption ;
283- $ attributes [$ attribute ->getAttributeId ()]['chosen ' ][$ optionId ] = $ variationOption ;
284- }
285-
286- $ productMatrix [] = [
287- 'id ' => $ product ->getId (),
288- 'product_link ' => '<a href=" ' . $ this ->urlBuilder ->getUrl (
289- 'catalog/product/edit ' ,
290- ['id ' => $ product ->getId ()]
291- ) . '" target="_blank"> ' . $ this ->escaper ->escapeHtml ($ product ->getName ()) . '</a> ' ,
292- 'sku ' => $ product ->getSku (),
293- 'name ' => $ product ->getName (),
294- 'qty ' => $ this ->getProductStockQty ($ product ),
295- 'price ' => $ price ,
296- 'price_string ' => $ currency ->toCurrency (sprintf ("%f " , $ price )),
297- 'price_currency ' => $ this ->locator ->getStore ()->getBaseCurrency ()->getCurrencySymbol (),
298- 'configurable_attribute ' => $ this ->getJsonConfigurableAttributes ($ variationOptions ),
299- 'weight ' => $ product ->getWeight (),
300- 'status ' => $ product ->getStatus (),
301- 'variationKey ' => $ this ->getVariationKey ($ variationOptions ),
302- 'canEdit ' => 0 ,
303- 'newProduct ' => 0 ,
304- 'attributes ' => $ this ->getTextAttributes ($ variationOptions ),
305- 'thumbnail_image ' => $ this ->imageHelper ->init ($ product , 'product_thumbnail_image ' )->getUrl (),
306- ];
307- $ productIds [] = $ product ->getId ();
308- }
309- }
310- }
311-
312- return $ productMatrix ;
313- //$this->productMatrix = $productMatrix;
314- //$this->productIds = $productIds;
315- }
316-
317231 /**
318232 * Prepare variations
319233 *
@@ -349,7 +263,7 @@ protected function prepareVariations(): void
349263 $ productMatrix [] = $ this ->buildChildProductDetails ($ product , $ childProductOptions );
350264 }
351265
352- $ this ->productMatrix = $ this -> prepareVariations2 () ;
266+ $ this ->productMatrix = $ productMatrix ;
353267 $ this ->productIds = $ productIds ;
354268 $ this ->productAttributes = array_values ($ attributes );
355269 }
0 commit comments