magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Swatches color image change not working #25059

Closed weeliem closed 5 years ago

weeliem commented 5 years ago

Preconditions (*)

  1. Magento 2.3.3

Steps to reproduce (*)

  1. Go to product details page with different color different images.
  2. Choose color to change image (http://prntscr.com/pjby6l)

Expected result (*)

  1. Image suppose to change base on selected color

Actual result (*)

  1. Selected color image is not changed (http://prntscr.com/pjbyko)
m2-assistant[bot] commented 5 years ago

Hi @weeliem. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@weeliem do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


m2-assistant[bot] commented 5 years ago

Hi @krishprakash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

krishprakash commented 5 years ago

Hi @weeliem. I'm not able to reproduce this issue as steps you described. Please provide more detail about this and please confirm that issue is reproduce on latest instance as instructed above. https://github.com/magento/magento2/issues/25059#issuecomment-542000542 Thanks.

ravi-chandra3197 commented 5 years ago

@magento give me 2.3-develop instance

magento-engcom-team commented 5 years ago

Hi @ravi-chandra3197. Thank you for your request. I'm working on Magento 2.3-develop instance for you

magento-engcom-team commented 5 years ago

Hi @ravi-chandra3197, here is your Magento instance. Admin access: https://i-25059-2-3-develop.instances.magento-community.engineering/admin Login: admin Password: 123123q Instance will be terminated in up to 3 hours.

magento-engcom-team commented 5 years ago

:white_check_mark: Confirmed by @krishprakash Thank you for verifying the issue. Based on the provided information internal tickets MC-22130 were created

Issue Available: @krishprakash, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] commented 5 years ago

Hi @raumatbel. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


raumatbel commented 5 years ago

The behavior in version 2.3 is correct. In Magento 2.2 it was wrong and the preview of the main image always changed without doing any kind of check.

Magento2.2 Swatches/view/frontend/web/js/swatch-renderer.js

/**
 * Event for swatch options
 *
 * @param {Object} $this
 * @param {Object} $widget
 * @param {String|undefined} eventName
 * @private
 */
_OnClick: function ($this, $widget, eventName) {
    var $parent = $this.parents('.' + $widget.options.classes.attributeClass),
        $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);

    if ($widget.inProductList) {
        $input = $widget.productForm.find(
            '.' + $widget.options.classes.attributeInput + '[name="super_attribute[' + attributeId + ']"]'
        );
    }

    if ($this.hasClass('disabled')) {
        return;
    }

    if ($this.hasClass('selected')) {
        $parent.removeAttr('option-selected').find('.selected').removeClass('selected');
        $input.val('');
        $label.text('');
        $this.attr('aria-checked', false);
    } else {
        $parent.attr('option-selected', $this.attr('option-id')).find('.selected').removeClass('selected');
        $label.text($this.attr('option-label'));
        $input.val($this.attr('option-id'));
        $input.attr('data-attr-name', this._getAttributeCodeById(attributeId));
        $this.addClass('selected');
        $widget._toggleCheckedAttributes($this, $wrapper);
    }

    $widget._Rebuild();

    if ($widget.element.parents($widget.options.selectorProduct)
            .find(this.options.selectorProductPrice).is(':data(mage-priceBox)')
    ) {
        $widget._UpdatePrice();
    }

    $widget._loadMedia(eventName);
    $input.trigger('change');
},

Magento 2.3 Swatches/view/frontend/web/js/swatch-renderer.js

/**
 * Event for swatch options
 *
 * @param {Object} $this
 * @param {Object} $widget
 * @private
 */
_OnClick: function ($this, $widget) {
    var $parent = $this.parents('.' + $widget.options.classes.attributeClass),
        $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),
        checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']);

    if ($widget.inProductList) {
        $input = $widget.productForm.find(
            '.' + $widget.options.classes.attributeInput + '[name="super_attribute[' + attributeId + ']"]'
        );
    }

    if ($this.hasClass('disabled')) {
        return;
    }

    if ($this.hasClass('selected')) {
        $parent.removeAttr('option-selected').find('.selected').removeClass('selected');
        $input.val('');
        $label.text('');
        $this.attr('aria-checked', false);
    } else {
        $parent.attr('option-selected', $this.attr('option-id')).find('.selected').removeClass('selected');
        $label.text($this.attr('option-label'));
        $input.val($this.attr('option-id'));
        $input.attr('data-attr-name', this._getAttributeCodeById(attributeId));
        $this.addClass('selected');
        $widget._toggleCheckedAttributes($this, $wrapper);
    }

    $widget._Rebuild();

    if ($widget.element.parents($widget.options.selectorProduct)
            .find(this.options.selectorProductPrice).is(':data(mage-priceBox)')
    ) {
        $widget._UpdatePrice();
    }

    $(document).trigger('updateMsrpPriceBlock',
        [
            _.findKey($widget.options.jsonConfig.index, $widget.options.jsonConfig.defaultValues),
            $widget.options.jsonConfig.optionPrices
        ]);

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

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

You can notice the call. $widget._loadMedia();

In Magento 2.3 to make the image reload it makes the check according to the setting that you have in the configuration of the attribute.

Update Image Swatch

Close this ticket.

irving0mar commented 4 years ago

@magento give me 2.3-develop instance

magento-engcom-team commented 4 years ago

Hi @irving0mar. Thank you for your request. I'm working on Magento 2.3-develop instance for you