@@ -98,6 +98,8 @@ public function __construct(
98
98
}
99
99
100
100
/**
101
+ * Return currency symbol.
102
+ *
101
103
* @return string
102
104
*/
103
105
public function getCurrencySymbol ()
@@ -274,6 +276,8 @@ public function getImageUploadUrl()
274
276
}
275
277
276
278
/**
279
+ * Return product qty.
280
+ *
277
281
* @param Product $product
278
282
* @return float
279
283
*/
@@ -283,6 +287,8 @@ public function getProductStockQty(Product $product)
283
287
}
284
288
285
289
/**
290
+ * Return variation wizard.
291
+ *
286
292
* @param array $initData
287
293
* @return string
288
294
*/
@@ -298,6 +304,8 @@ public function getVariationWizard($initData)
298
304
}
299
305
300
306
/**
307
+ * Return product configuration matrix.
308
+ *
301
309
* @return array|null
302
310
*/
303
311
public function getProductMatrix ()
@@ -309,17 +317,22 @@ public function getProductMatrix()
309
317
}
310
318
311
319
/**
320
+ * Return product attributes.
321
+ *
312
322
* @return array|null
313
323
*/
314
324
public function getProductAttributes ()
315
325
{
316
326
if ($ this ->productAttributes === null ) {
317
327
$ this ->prepareVariations ();
318
328
}
329
+
319
330
return $ this ->productAttributes ;
320
331
}
321
332
322
333
/**
334
+ * Prepare product variations.
335
+ *
323
336
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
324
337
* @return void
325
338
* TODO: move to class
@@ -344,36 +357,13 @@ protected function prepareVariations()
344
357
$ price = $ product ->getPrice ();
345
358
$ variationOptions = [];
346
359
foreach ($ usedProductAttributes as $ attribute ) {
347
- if (!isset ($ attributes [$ attribute ->getAttributeId ()])) {
348
- $ attributes [$ attribute ->getAttributeId ()] = [
349
- 'code ' => $ attribute ->getAttributeCode (),
350
- 'label ' => $ attribute ->getStoreLabel (),
351
- 'id ' => $ attribute ->getAttributeId (),
352
- 'position ' => $ configurableAttributes [$ attribute ->getAttributeId ()]['position ' ],
353
- 'chosen ' => [],
354
- ];
355
- foreach ($ attribute ->getOptions () as $ option ) {
356
- if (!empty ($ option ->getValue ())) {
357
- $ attributes [$ attribute ->getAttributeId ()]['options ' ][] = [
358
- 'attribute_code ' => $ attribute ->getAttributeCode (),
359
- 'attribute_label ' => $ attribute ->getStoreLabel (0 ),
360
- 'id ' => $ option ->getValue (),
361
- 'label ' => $ option ->getLabel (),
362
- 'value ' => $ option ->getValue (),
363
- ];
364
- }
365
- }
366
- }
367
- $ optionId = $ variation [$ attribute ->getId ()]['value ' ];
368
- $ variationOption = [
369
- 'attribute_code ' => $ attribute ->getAttributeCode (),
370
- 'attribute_label ' => $ attribute ->getStoreLabel (0 ),
371
- 'id ' => $ optionId ,
372
- 'label ' => $ variation [$ attribute ->getId ()]['label ' ],
373
- 'value ' => $ optionId ,
374
- ];
375
- $ variationOptions [] = $ variationOption ;
376
- $ attributes [$ attribute ->getAttributeId ()]['chosen ' ][] = $ variationOption ;
360
+ list ($ attributes , $ variationOptions ) = $ this ->prepareAttributes (
361
+ $ attributes ,
362
+ $ attribute ,
363
+ $ configurableAttributes ,
364
+ $ variation ,
365
+ $ variationOptions
366
+ );
377
367
}
378
368
379
369
$ productMatrix [] = [
@@ -387,12 +377,66 @@ protected function prepareVariations()
387
377
'price ' => $ price ,
388
378
'options ' => $ variationOptions ,
389
379
'weight ' => $ product ->getWeight (),
390
- 'status ' => $ product ->getStatus ()
380
+ 'status ' => $ product ->getStatus (),
381
+ '__disableTmpl ' => true ,
391
382
];
392
383
}
393
384
}
394
385
}
395
386
$ this ->productMatrix = $ productMatrix ;
396
387
$ this ->productAttributes = array_values ($ attributes );
397
388
}
389
+
390
+ /**
391
+ * Prepare attributes.
392
+ *
393
+ * @param array $attributes
394
+ * @param object $attribute
395
+ * @param array $configurableAttributes
396
+ * @param array $variation
397
+ * @param array $variationOptions
398
+ * @return array
399
+ */
400
+ private function prepareAttributes (
401
+ array $ attributes ,
402
+ $ attribute ,
403
+ array $ configurableAttributes ,
404
+ array $ variation ,
405
+ array $ variationOptions
406
+ ): array {
407
+ if (!isset ($ attributes [$ attribute ->getAttributeId ()])) {
408
+ $ attributes [$ attribute ->getAttributeId ()] = [
409
+ 'code ' => $ attribute ->getAttributeCode (),
410
+ 'label ' => $ attribute ->getStoreLabel (),
411
+ 'id ' => $ attribute ->getAttributeId (),
412
+ 'position ' => $ configurableAttributes [$ attribute ->getAttributeId ()]['position ' ],
413
+ 'chosen ' => [],
414
+ ];
415
+ foreach ($ attribute ->getOptions () as $ option ) {
416
+ if (!empty ($ option ->getValue ())) {
417
+ $ attributes [$ attribute ->getAttributeId ()]['options ' ][] = [
418
+ 'attribute_code ' => $ attribute ->getAttributeCode (),
419
+ 'attribute_label ' => $ attribute ->getStoreLabel (0 ),
420
+ 'id ' => $ option ->getValue (),
421
+ 'label ' => $ option ->getLabel (),
422
+ 'value ' => $ option ->getValue (),
423
+ '__disableTmpl ' => true ,
424
+ ];
425
+ }
426
+ }
427
+ }
428
+ $ optionId = $ variation [$ attribute ->getId ()]['value ' ];
429
+ $ variationOption = [
430
+ 'attribute_code ' => $ attribute ->getAttributeCode (),
431
+ 'attribute_label ' => $ attribute ->getStoreLabel (0 ),
432
+ 'id ' => $ optionId ,
433
+ 'label ' => $ variation [$ attribute ->getId ()]['label ' ],
434
+ 'value ' => $ optionId ,
435
+ '__disableTmpl ' => true ,
436
+ ];
437
+ $ variationOptions [] = $ variationOption ;
438
+ $ attributes [$ attribute ->getAttributeId ()]['chosen ' ][] = $ variationOption ;
439
+
440
+ return [$ attributes , $ variationOptions ];
441
+ }
398
442
}
0 commit comments