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