Given a commerce product with variations, how can I order the values within a variation attribute in the "Add to cart" form on the product page?

Steps so far:

  1. In /admin/commerce/config/product-types/TYPE/edit/display I'm using Add to cart form as field formatter for the Variations field
  2. In /admin/commerce/product-attributes/manage/TYPE I've ordered the values of my variation attribute as wanted.
  3. On the frontend, in my commerce_product.html.twig I'm rendering the cart form field with {{ product.variations }}

However, the Add to cart form does not follow the weights as set in step 2. I can't see any pattern in the attribute value ordering, it is neither ID, weight or name. How or where can I define the weights of the values within a variation attribute?

As a sidenote, the weights of step 2 are used when viewing the Bulk tab in /admin/commerce-bulk-attribute/TYPE. My problem seems to be related to this issue, but it is flagged as fixed, and I can see the $entity_query->sort('weight') in the class ProductAttributeValueStorage

Your Answer

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

Browse other questions tagged or ask your own question.