Skip to content

Commit

Permalink
ENGCOM-4825: Fixed magento text swatch switches product image even if…
Browse files Browse the repository at this point in the history
… attribute feature is disabled magento#16446 magento#19184
  • Loading branch information
p-bystritsky authored Jun 3, 2019
2 parents cff969b + 282711e commit 821adca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<element name="DefaultLabel" type="input" selector="#attribute_label"/>
<element name="InputType" type="select" selector="#frontend_input"/>
<element name="ValueRequired" type="select" selector="#is_required"/>
<element name="UpdateProductPreviewImage" type="select" selector="[name='update_product_preview_image']"/>
<element name="AdvancedProperties" type="button" selector="#advanced_fieldset-wrapper"/>
<element name="DefaultValue" type="input" selector="#default_value_text"/>
<element name="Scope" type="select" selector="#is_global"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ public function getJsonSwatchConfig()
$attributeDataArray
);
}
if (isset($attributeDataArray['additional_data'])) {
$config[$attributeId]['additional_data'] = $attributeDataArray['additional_data'];
}
}

return $this->jsonEncoder->encode($config);
}

/**
* Get number of swatches from config to show on product listing.
*
* Other swatches can be shown after click button 'Show more'
*
* @return string
Expand Down Expand Up @@ -228,6 +232,8 @@ public function getProduct()
}

/**
* Get swatch attributes data.
*
* @return array
*/
protected function getSwatchAttributesData()
Expand All @@ -236,6 +242,8 @@ protected function getSwatchAttributesData()
}

/**
* Init isProductHasSwatchAttribute.
*
* @deprecated 100.1.5 Method isProductHasSwatchAttribute() is used instead of this.
*
* @codeCoverageIgnore
Expand Down Expand Up @@ -364,6 +372,8 @@ protected function getVariationMedia($attributeCode, $optionId)
}

/**
* Get swatch product image.
*
* @param Product $childProduct
* @param string $imageType
* @return string
Expand All @@ -384,6 +394,8 @@ protected function getSwatchProductImage(Product $childProduct, $imageType)
}

/**
* Check if product have image.
*
* @param Product $product
* @param string $imageType
* @return bool
Expand All @@ -394,6 +406,8 @@ protected function isProductHasImage(Product $product, $imageType)
}

/**
* Get configurable options ids.
*
* @param array $attributeData
* @return array
* @since 100.0.3
Expand Down Expand Up @@ -453,15 +467,17 @@ protected function getRendererTemplate()
}

/**
* @inheritDoc
* @deprecated 100.1.5 Now is used _toHtml() directly
* @return string
*/
protected function getHtmlOutput()
{
return parent::_toHtml();
}

/**
* Get media callback url.
*
* @return string
*/
public function getMediaCallback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<!-- Select visual swatch -->
<selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="swatch_visual" stepKey="selectInputType"/>

<!-- Set Update Product Preview Image to Yes-->
<selectOption selector="{{AttributePropertiesSection.UpdateProductPreviewImage}}" userInput="Yes" stepKey="setUpdateProductPreviewImage"/>

<!-- This hack is because the same <input type="file"> is re-purposed used for all uploads. -->
<executeJS function="HTMLInputElement.prototype.click = function() { if(this.type !== 'file') HTMLElement.prototype.click.call(this); };" stepKey="disableClick"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ define([
$wrapper = $this.parents('.' + $widget.options.classes.attributeOptionsWrapper),
$label = $parent.find('.' + $widget.options.classes.attributeSelectedOptionLabelClass),
attributeId = $parent.attr('attribute-id'),
$input = $parent.find('.' + $widget.options.classes.attributeInput);
$input = $parent.find('.' + $widget.options.classes.attributeInput),
checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']);

if ($widget.inProductList) {
$input = $widget.productForm.find(
Expand Down Expand Up @@ -753,7 +754,10 @@ define([
$widget.options.jsonConfig.optionPrices
]);

$widget._loadMedia();
if (checkAdditionalData['update_product_preview_image'] === '1') {
$widget._loadMedia();
}

$input.trigger('change');
},

Expand Down

0 comments on commit 821adca

Please sign in to comment.