I am doing the following to sort the product collection based on an attribute whose values are actually of type "String" but can only hold 0
or 1
. I also mentioned default value as 0
.
$collection = $this->getCollection()
->addAttributeToSort('attr_name' *1, 'DESC');
In the above code, since the attribute type is "string", I added *1
to convert the string type to Integer as mentioned in this post.
What should I do to sort the product collection based on a attribute which is of type string but has only values 0
and 1
?
PS: The collection is being sorted with other attribute in __construct
function already and then made to setCollection($collection)
.