magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Autoselect of swatch options not working for dropdown attributes

Open designhunger opened this issue 10 years ago • 5 comments

Steps to reproduce

  1. Create a configurable product with a dropdown product attribute (f.ex. size)
  2. Visit product page with following syntax to preselect the attributes: http://myshop.com/productname.html?size=6

Expected result

The size with the option-id of 6 should be selected for the size attribute.

Actual result

The option is not selected if the attribute is a dropdown. Only visual and text swatches are selected.

Solution

The js file should differentiate between clickable attributes like swatches and dropdowns. Therefor the find statements should be altered in the _EmulateSelected function.

/module-swatches/view/frontend/web/js/SwatchRenderer.js

    /**
     * Emulate mouse click on all swatches that should be selected
     *
     * @private
     */
    _EmulateSelected: function () {
        var $widget = this,
            $this = $widget.element,
            request = $.parseParams(window.location.search.substring(1));

        $.each(request, function (key, value) {

            $this.find('.' + $widget.options.classes.attributeClass
                + '[attribute-code="' + key + '"] .swatch-select').val(value).change();


            $this.find('.' + $widget.options.classes.attributeClass
                + '[attribute-code="' + key + '"] .swatch-option[option-id="' + value + '"]').trigger('click');


        });
    },

designhunger avatar Apr 28 '16 11:04 designhunger

Internal issue MAGETWO-52776

piotrekkaminski avatar May 13 '16 00:05 piotrekkaminski

I didn't even know you could do that with swatches. Is this url syntax formally documented anywhere?

sammarcus avatar Oct 19 '16 06:10 sammarcus

In Magento 1.9 this was already featured. I have not found any docs for Magento 2, but found it while crawling through the codebase.

designhunger avatar Oct 19 '16 06:10 designhunger

Interesting. I haven't been able to get it working so am curious if that functionality is even maintained anymore.

sammarcus avatar Nov 02 '16 08:11 sammarcus

Internal ticket was closed as not a bug. You can submit to Magento 2 Feature Requests and Improvements forum (see details here) if you think it should be implemented. Closed.

veloraven avatar Jun 19 '17 16:06 veloraven