Skip to content

Commit f463caf

Browse files
committed
rework
1 parent dbc514c commit f463caf

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\
6161
/**
6262
* Config path which contains number of swatches per product
6363
*/
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';
6565

6666
/**
6767
* Config path if swatch tooltips are enabled
6868
*/
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';
7070

7171
/**
7272
* @var Product
@@ -104,19 +104,19 @@ class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\
104104

105105
/**
106106
* @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
118118
* @param SwatchAttributesProvider|null $swatchAttributesProvider
119-
* @param UrlBuilder|null $imageUrlBuilder
119+
* @param UrlBuilder|null $imageUrlBuilder
120120
*/
121121
public function __construct(
122122
Context $context,
@@ -183,6 +183,7 @@ public function getJsonSwatchConfig()
183183
$attributesData = $this->getSwatchAttributesData();
184184
$allOptionIds = $this->getConfigurableOptionsIds($attributesData);
185185
$swatchesData = $this->swatchHelper->getSwatchesByOptionsId($allOptionIds);
186+
186187
$config = [];
187188
foreach ($attributesData as $attributeId => $attributeDataArray) {
188189
if (isset($attributeDataArray['options'])) {
@@ -232,13 +233,11 @@ public function getShowSwatchTooltip()
232233
* Set product to block
233234
*
234235
* @param Product $product
235-
*
236236
* @return $this
237237
*/
238238
public function setProduct(Product $product)
239239
{
240240
$this->product = $product;
241-
242241
return $this;
243242
}
244243

@@ -269,10 +268,10 @@ protected function getSwatchAttributesData()
269268
/**
270269
* Init isProductHasSwatchAttribute.
271270
*
272-
* @return void
273271
* @deprecated 100.1.5 Method isProductHasSwatchAttribute() is used instead of this.
274272
*
275273
* @codeCoverageIgnore
274+
* @return void
276275
*/
277276
protected function initIsProductHasSwatchAttribute()
278277
{
@@ -288,7 +287,6 @@ protected function initIsProductHasSwatchAttribute()
288287
protected function isProductHasSwatchAttribute()
289288
{
290289
$swatchAttributes = $this->swatchAttributesProvider->provide($this->getProduct());
291-
292290
return count($swatchAttributes) > 0;
293291
}
294292

@@ -298,7 +296,6 @@ protected function isProductHasSwatchAttribute()
298296
* @param array $options
299297
* @param array $swatchesCollectionArray
300298
* @param array $attributeDataArray
301-
*
302299
* @return array
303300
*/
304301
protected function addSwatchDataForAttribute(
@@ -321,10 +318,9 @@ protected function addSwatchDataForAttribute(
321318
/**
322319
* Add media from variation
323320
*
324-
* @param array $swatch
321+
* @param array $swatch
325322
* @param integer $optionId
326-
* @param array $attributeDataArray
327-
*
323+
* @param array $attributeDataArray
328324
* @return array
329325
*/
330326
protected function addAdditionalMediaData(array $swatch, $optionId, array $attributeDataArray)
@@ -333,25 +329,24 @@ protected function addAdditionalMediaData(array $swatch, $optionId, array $attri
333329
&& $attributeDataArray['use_product_image_for_swatch']
334330
) {
335331
$variationMedia = $this->getVariationMedia($attributeDataArray['attribute_code'], $optionId);
336-
if (!empty($variationMedia)) {
332+
if (! empty($variationMedia)) {
337333
$swatch['type'] = Swatch::SWATCH_TYPE_VISUAL_IMAGE;
338334
$swatch = array_merge($swatch, $variationMedia);
339335
}
340336
}
341-
342337
return $swatch;
343338
}
344339

345340
/**
346341
* Retrieve Swatch data for config
347342
*
348343
* @param array $swatchDataArray
349-
*
350344
* @return array
351345
*/
352346
protected function extractNecessarySwatchData(array $swatchDataArray)
353347
{
354348
$result['type'] = $swatchDataArray['type'];
349+
355350
if ($result['type'] == Swatch::SWATCH_TYPE_VISUAL_IMAGE && !empty($swatchDataArray['value'])) {
356351
$result['value'] = $this->swatchMediaHelper->getSwatchAttributeImage(
357352
Swatch::SWATCH_IMAGE_NAME,
@@ -371,9 +366,8 @@ protected function extractNecessarySwatchData(array $swatchDataArray)
371366
/**
372367
* Generate Product Media array
373368
*
374-
* @param string $attributeCode
369+
* @param string $attributeCode
375370
* @param integer $optionId
376-
*
377371
* @return array
378372
*/
379373
protected function getVariationMedia($attributeCode, $optionId)
@@ -382,12 +376,14 @@ protected function getVariationMedia($attributeCode, $optionId)
382376
$this->getProduct(),
383377
[$attributeCode => $optionId]
384378
);
379+
385380
if (!$variationProduct) {
386381
$variationProduct = $this->swatchHelper->loadFirstVariationWithImage(
387382
$this->getProduct(),
388383
[$attributeCode => $optionId]
389384
);
390385
}
386+
391387
$variationMediaArray = [];
392388
if ($variationProduct) {
393389
$variationMediaArray = [
@@ -403,8 +399,7 @@ protected function getVariationMedia($attributeCode, $optionId)
403399
* Get swatch product image.
404400
*
405401
* @param Product $childProduct
406-
* @param string $imageType
407-
*
402+
* @param string $imageType
408403
* @return string
409404
*/
410405
protected function getSwatchProductImage(Product $childProduct, $imageType)
@@ -416,6 +411,7 @@ protected function getSwatchProductImage(Product $childProduct, $imageType)
416411
$swatchImageId = $imageType == Swatch::SWATCH_IMAGE_NAME ? 'swatch_image_base' : 'swatch_thumb_base';
417412
$imageAttributes = ['type' => 'image'];
418413
}
414+
419415
if (!empty($swatchImageId) && !empty($imageAttributes['type'])) {
420416
return $this->imageUrlBuilder->getUrl($childProduct->getData($imageAttributes['type']), $swatchImageId);
421417
}
@@ -425,8 +421,7 @@ protected function getSwatchProductImage(Product $childProduct, $imageType)
425421
* Check if product have image.
426422
*
427423
* @param Product $product
428-
* @param string $imageType
429-
*
424+
* @param string $imageType
430425
* @return bool
431426
*/
432427
protected function isProductHasImage(Product $product, $imageType)
@@ -438,7 +433,6 @@ protected function isProductHasImage(Product $product, $imageType)
438433
* Get configurable options ids.
439434
*
440435
* @param array $attributeData
441-
*
442436
* @return array
443437
* @since 100.0.3
444438
*/
@@ -455,7 +449,6 @@ protected function getConfigurableOptionsIds(array $attributeData)
455449
}
456450
}
457451
}
458-
459452
return array_keys($ids);
460453
}
461454

@@ -540,6 +533,7 @@ public function getJsonSwatchSizeConfig()
540533
{
541534
$imageConfig = $this->swatchMediaHelper->getImageConfig();
542535
$sizeConfig = [];
536+
543537
$sizeConfig[self::SWATCH_IMAGE_NAME]['width'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['width'];
544538
$sizeConfig[self::SWATCH_IMAGE_NAME]['height'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['height'];
545539
$sizeConfig[self::SWATCH_THUMBNAIL_NAME]['height'] = $imageConfig[Swatch::SWATCH_THUMBNAIL_NAME]['height'];

0 commit comments

Comments
 (0)