如何在产品列表页面的排序中将空值产品设置为最后一个


How to set null value product in last in sorting on product listing page?

你好,我有主要的4种产品,比如

     product_name  attribute_name attribute_value
----------------------------------------------------------
     test1           catname        abc
     test2           catname        ccc
     test3           catname        ###
     test4           catname        bbb

当我尝试在产品列表页面上按catname对产品进行排序时,我首先得到的是空值产品test3,但我最后需要它。我必须忽略null属性值。

我在toolbar.phtml中尝试了ascdesc,但这不是我想要的。

有人能帮我吗??

您可以尝试作为

 ORDER BY if(attribute_value = '' or attribute_value is null,1,0),attribute_value ,product_name