I have a plugin that adds some custom product sorting, based on a customer attribute, in a way similar to below.
# Vendor\ModuleName\Plugin\Product\ProductList\Toolbar; case 'capacity_low_to_high': $collection->setOrder('capacity', 'ASC'); break; case 'name_high_to_low': $collection->setOrder('capacity', 'DESC'); break;
However, the sorting is not as expected. When sorting via the custom 'capacity' attribute, the products are being sorted alphanumerically, such as that the result is someting like:
1 11 19 2 3 4 5
Obviously this is not as desired, but I am unsure of the best way to sort the collection based on the numerical value of the attribute. Can anybody point me in the right direction? Ideally, I'm thinking that storing the capacity attribute as an integer would work best, but there doesn't seem to be an obvious way to implement that. Am I missing something? What are my options. Magento 2.3