正在调用“查找当前模型”



im 尝试按字母顺序对目录页面上色板上的名称(过滤器块(进行排序(制造商等(。

去了名为"swatches.phtml"的phtml文件,我发现它调用集合"$this->getItems((",但是在调用方法getItems之前,我需要设置顺序,例如在调用"getItems"之前,我尝试了上面的代码:

$items=$this->setOrder('updated_at', 'asc');

然后调用$items->getItems(("但它不起作用,任何人都有想法我做错了什么?

getItems() 函数是从app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php调用的,如果你看那里,你会看到它返回一个过滤器项对象的数组。 您可以使用 usort(( 函数直接在 swatches.phtml 中对它们进行排序。 它看起来与 php 手册页中的第一个示例非常相似:

<?php 
function sortByLabel($a, $b) {
    if ($a->getLabel() == $b->getLabel()) {
        return 0;
    }
    return ($a->getLabel() < $b->getLabel()) ? -1 : 1;
}
$items = $this->getItems();
usort($items, "sortByLabel");
?>
<!-- you will have to change the existing foreach loop to use your $items array -->
    <?php foreach ($items as $_item): ?>
....

最新更新