@@ -61,12 +61,12 @@ class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\
61
61
/**
62
62
* Config path which contains number of swatches per product
63
63
*/
64
- const XML_PATH_SWATCHES_PER_PRODUCT = 'catalog/frontend/swatches_per_product ' ;
64
+ private const XML_PATH_SWATCHES_PER_PRODUCT = 'catalog/frontend/swatches_per_product ' ;
65
65
66
66
/**
67
67
* Config path if swatch tooltips are enabled
68
68
*/
69
- const XML_PATH_SHOW_SWATCH_TOOLTIP = 'catalog/frontend/show_swatch_tooltip ' ;
69
+ private const XML_PATH_SHOW_SWATCH_TOOLTIP = 'catalog/frontend/show_swatch_tooltip ' ;
70
70
71
71
/**
72
72
* @var Product
@@ -104,19 +104,19 @@ class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\
104
104
105
105
/**
106
106
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
107
- * @param Context $context
108
- * @param ArrayUtils $arrayUtils
109
- * @param EncoderInterface $jsonEncoder
110
- * @param Data $helper
111
- * @param CatalogProduct $catalogProduct
112
- * @param CurrentCustomer $currentCustomer
113
- * @param PriceCurrencyInterface $priceCurrency
114
- * @param ConfigurableAttributeData $configurableAttributeData
115
- * @param SwatchData $swatchHelper
116
- * @param Media $swatchMediaHelper
117
- * @param array $data
107
+ * @param Context $context
108
+ * @param ArrayUtils $arrayUtils
109
+ * @param EncoderInterface $jsonEncoder
110
+ * @param Data $helper
111
+ * @param CatalogProduct $catalogProduct
112
+ * @param CurrentCustomer $currentCustomer
113
+ * @param PriceCurrencyInterface $priceCurrency
114
+ * @param ConfigurableAttributeData $configurableAttributeData
115
+ * @param SwatchData $swatchHelper
116
+ * @param Media $swatchMediaHelper
117
+ * @param array $data
118
118
* @param SwatchAttributesProvider|null $swatchAttributesProvider
119
- * @param UrlBuilder|null $imageUrlBuilder
119
+ * @param UrlBuilder|null $imageUrlBuilder
120
120
*/
121
121
public function __construct (
122
122
Context $ context ,
@@ -183,6 +183,7 @@ public function getJsonSwatchConfig()
183
183
$ attributesData = $ this ->getSwatchAttributesData ();
184
184
$ allOptionIds = $ this ->getConfigurableOptionsIds ($ attributesData );
185
185
$ swatchesData = $ this ->swatchHelper ->getSwatchesByOptionsId ($ allOptionIds );
186
+
186
187
$ config = [];
187
188
foreach ($ attributesData as $ attributeId => $ attributeDataArray ) {
188
189
if (isset ($ attributeDataArray ['options ' ])) {
@@ -232,13 +233,11 @@ public function getShowSwatchTooltip()
232
233
* Set product to block
233
234
*
234
235
* @param Product $product
235
- *
236
236
* @return $this
237
237
*/
238
238
public function setProduct (Product $ product )
239
239
{
240
240
$ this ->product = $ product ;
241
-
242
241
return $ this ;
243
242
}
244
243
@@ -269,10 +268,10 @@ protected function getSwatchAttributesData()
269
268
/**
270
269
* Init isProductHasSwatchAttribute.
271
270
*
272
- * @return void
273
271
* @deprecated 100.1.5 Method isProductHasSwatchAttribute() is used instead of this.
274
272
*
275
273
* @codeCoverageIgnore
274
+ * @return void
276
275
*/
277
276
protected function initIsProductHasSwatchAttribute ()
278
277
{
@@ -288,7 +287,6 @@ protected function initIsProductHasSwatchAttribute()
288
287
protected function isProductHasSwatchAttribute ()
289
288
{
290
289
$ swatchAttributes = $ this ->swatchAttributesProvider ->provide ($ this ->getProduct ());
291
-
292
290
return count ($ swatchAttributes ) > 0 ;
293
291
}
294
292
@@ -298,7 +296,6 @@ protected function isProductHasSwatchAttribute()
298
296
* @param array $options
299
297
* @param array $swatchesCollectionArray
300
298
* @param array $attributeDataArray
301
- *
302
299
* @return array
303
300
*/
304
301
protected function addSwatchDataForAttribute (
@@ -321,10 +318,9 @@ protected function addSwatchDataForAttribute(
321
318
/**
322
319
* Add media from variation
323
320
*
324
- * @param array $swatch
321
+ * @param array $swatch
325
322
* @param integer $optionId
326
- * @param array $attributeDataArray
327
- *
323
+ * @param array $attributeDataArray
328
324
* @return array
329
325
*/
330
326
protected function addAdditionalMediaData (array $ swatch , $ optionId , array $ attributeDataArray )
@@ -333,25 +329,24 @@ protected function addAdditionalMediaData(array $swatch, $optionId, array $attri
333
329
&& $ attributeDataArray ['use_product_image_for_swatch ' ]
334
330
) {
335
331
$ variationMedia = $ this ->getVariationMedia ($ attributeDataArray ['attribute_code ' ], $ optionId );
336
- if (!empty ($ variationMedia )) {
332
+ if (! empty ($ variationMedia )) {
337
333
$ swatch ['type ' ] = Swatch::SWATCH_TYPE_VISUAL_IMAGE ;
338
334
$ swatch = array_merge ($ swatch , $ variationMedia );
339
335
}
340
336
}
341
-
342
337
return $ swatch ;
343
338
}
344
339
345
340
/**
346
341
* Retrieve Swatch data for config
347
342
*
348
343
* @param array $swatchDataArray
349
- *
350
344
* @return array
351
345
*/
352
346
protected function extractNecessarySwatchData (array $ swatchDataArray )
353
347
{
354
348
$ result ['type ' ] = $ swatchDataArray ['type ' ];
349
+
355
350
if ($ result ['type ' ] == Swatch::SWATCH_TYPE_VISUAL_IMAGE && !empty ($ swatchDataArray ['value ' ])) {
356
351
$ result ['value ' ] = $ this ->swatchMediaHelper ->getSwatchAttributeImage (
357
352
Swatch::SWATCH_IMAGE_NAME ,
@@ -371,9 +366,8 @@ protected function extractNecessarySwatchData(array $swatchDataArray)
371
366
/**
372
367
* Generate Product Media array
373
368
*
374
- * @param string $attributeCode
369
+ * @param string $attributeCode
375
370
* @param integer $optionId
376
- *
377
371
* @return array
378
372
*/
379
373
protected function getVariationMedia ($ attributeCode , $ optionId )
@@ -382,12 +376,14 @@ protected function getVariationMedia($attributeCode, $optionId)
382
376
$ this ->getProduct (),
383
377
[$ attributeCode => $ optionId ]
384
378
);
379
+
385
380
if (!$ variationProduct ) {
386
381
$ variationProduct = $ this ->swatchHelper ->loadFirstVariationWithImage (
387
382
$ this ->getProduct (),
388
383
[$ attributeCode => $ optionId ]
389
384
);
390
385
}
386
+
391
387
$ variationMediaArray = [];
392
388
if ($ variationProduct ) {
393
389
$ variationMediaArray = [
@@ -403,8 +399,7 @@ protected function getVariationMedia($attributeCode, $optionId)
403
399
* Get swatch product image.
404
400
*
405
401
* @param Product $childProduct
406
- * @param string $imageType
407
- *
402
+ * @param string $imageType
408
403
* @return string
409
404
*/
410
405
protected function getSwatchProductImage (Product $ childProduct , $ imageType )
@@ -416,6 +411,7 @@ protected function getSwatchProductImage(Product $childProduct, $imageType)
416
411
$ swatchImageId = $ imageType == Swatch::SWATCH_IMAGE_NAME ? 'swatch_image_base ' : 'swatch_thumb_base ' ;
417
412
$ imageAttributes = ['type ' => 'image ' ];
418
413
}
414
+
419
415
if (!empty ($ swatchImageId ) && !empty ($ imageAttributes ['type ' ])) {
420
416
return $ this ->imageUrlBuilder ->getUrl ($ childProduct ->getData ($ imageAttributes ['type ' ]), $ swatchImageId );
421
417
}
@@ -425,8 +421,7 @@ protected function getSwatchProductImage(Product $childProduct, $imageType)
425
421
* Check if product have image.
426
422
*
427
423
* @param Product $product
428
- * @param string $imageType
429
- *
424
+ * @param string $imageType
430
425
* @return bool
431
426
*/
432
427
protected function isProductHasImage (Product $ product , $ imageType )
@@ -438,7 +433,6 @@ protected function isProductHasImage(Product $product, $imageType)
438
433
* Get configurable options ids.
439
434
*
440
435
* @param array $attributeData
441
- *
442
436
* @return array
443
437
* @since 100.0.3
444
438
*/
@@ -455,7 +449,6 @@ protected function getConfigurableOptionsIds(array $attributeData)
455
449
}
456
450
}
457
451
}
458
-
459
452
return array_keys ($ ids );
460
453
}
461
454
@@ -540,6 +533,7 @@ public function getJsonSwatchSizeConfig()
540
533
{
541
534
$ imageConfig = $ this ->swatchMediaHelper ->getImageConfig ();
542
535
$ sizeConfig = [];
536
+
543
537
$ sizeConfig [self ::SWATCH_IMAGE_NAME ]['width ' ] = $ imageConfig [Swatch::SWATCH_IMAGE_NAME ]['width ' ];
544
538
$ sizeConfig [self ::SWATCH_IMAGE_NAME ]['height ' ] = $ imageConfig [Swatch::SWATCH_IMAGE_NAME ]['height ' ];
545
539
$ sizeConfig [self ::SWATCH_THUMBNAIL_NAME ]['height ' ] = $ imageConfig [Swatch::SWATCH_THUMBNAIL_NAME ]['height ' ];
0 commit comments