0

I've got a shop with an attribute "capacity" created via Magento Backend: Shops -> Attribute -> Product

It has "Text Field" as input type and "Decimal" as validation. So for new products therefore only numerical values can be added.

Now if it comes to sorting in the store front or product list in the backend the sorting for "capacity" is incorrect because Magento handles the values as string.

Incorrect order:

  • 2l
  • 22l
  • 3l
  • 35l

Correct order should be:

  • 2l
  • 3l
  • 22l
  • 35l

What is the best practice to fix this? Changing the type to price doesn't seem legit to me and can lead to confusion in the future? Should i change the type directly in mysql, remove the current attribute and recreate it programmatically or should i add an plugin that adds some casting to the order function in the product collection?

Any kind of help is appreciated.

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.