If I used color and text swatch in magento 2, sequence/order of option isn't changing. I mean I want to show

1. size
2. color

but it always show

1. color
2. size

if I used dropdown instead of color and text swatch. it is working fine. Can anyone tell me, is that isssue comes with magento 2.0?

1 Answer 1


I have same issue just today and able to fix it by changing each attribute key as string by adding any character like "_" in the getJsonConfig result. It seems its a browser or javascript issue where it automatically sort numeric array keys so changing it to string key will prevent it from sorting automatically.

Testing Solution: 1. Edit vendor\magento\module-swatches\Block\Product\Renderer\Configurable.php 2. Add the below function to override the getJsonConfig:

public function getJsonConfig() {
        $jsonConfig = parent::getJsonConfig();
        $decodedConfig = json_decode($jsonConfig, true);

        foreach ($decodedConfig['attributes'] as $attributeId => $attributeData) {
            $decodedConfig['attributes']["_" . $attributeId] = $attributeData;

        return $this->jsonEncoder->encode($decodedConfig);

You have two choices, either use plugin or extend that file. I use plugin for this.

Hope that helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.