I want to sort a catalog_product_collection
by multiple attributes but with special input.
As I understand the method addAttributeToSort
calling it like this
addAttributeToSort("attribute");
Seems to do the trick, if it can load the attribute. But I need to call it like that:
addAttributeToSort("attribute IN ('001')");
Which will fail because it cannot load an attribute called attribute IN ('001')
How would I sort the collection in this case?
Reason: We want the product collection order in a special format. I have the algorithm done and its working fine (pagionation is broken now, but thats another topic) but a co worker showed me that you could so an ORDER BY
like that:
ORDER BY x.Component_Stone_Color IN ('001') DESC, x.Component_Stone_Color IN ('280') DESC, ....
Edit
Something like this seems to work:
$sql = $collection->getSelect();
$sql->order(array("sw_stone_color IN ('001') DESC", "sw_stone_color IN ('280') DESC", "sw_...", ...));
But the needed attributes are not (yet?) selected.
An $collection->addAttributeToSelect(array('sw_stone_color', 'sw_effects', 'sw_foiling', 'sw_motifs'));
doesnt seem to do the trick, sadly. (They are simply not selected when I look at the output query)
I'm in the catalog_product_collection_load_before
event.