类别除主页外,产品分类无效

时间:2015-12-23 18:05:24

标签: sorting magento categories product gridview-sorting

我已经在管理面板中的每个类别中对产品进行了排序。它在前端没有相应的工作,但在主页上一切都很好。我检查了这个链接,我想知道如何强制按位置STACK QUE

进行排序

我也在Grid视图中引用相同的list.phtml。谁能帮我?谢谢!

2 个答案:

答案 0 :(得分:0)

以防有人遇到同样的错误。这是我设法使其成功的解决方案。首先,您需要从mage核心复制Toolbar.php并将其粘贴到本地mage池中,找到函数setCollection并将其替换为以下代码:

    InputStream inputStream = resourceLoader.getResource('/META-INF/foo/file.txt').inputStream
    File tempFile = new File('file.txt')
    OutputStream outputStream = new FileOutputStream(tempFile)

    try {
        IOUtils.copy(inputStream, outputStream)
    } catch (IOException e) {
        // Handle exception
    } finally {
        outputStream.close()
    }

答案 1 :(得分:0)

app / design / frontend // default / template / catalog / product / list.phtml

中获取产品集后,在代码下面创建按位置编写排序
$_productCollection = new Varien_Data_Collection();
$sortedCollection = array();
foreach ($_defaultProductCollection as $key => $_product) {
    if(!isset($sortedCollection[$positions[$_product->getId()]])){
        $sortedCollection[$positions[$_product->getId()]] = array();
    }
    $sortedCollection[$positions[$_product->getId()]][] = $_product;
}
ksort($sortedCollection);
foreach ($sortedCollection as $_products) {
    foreach ($_products as $_product) {
        $_productCollection->addItem($_product);
    }
}

希望它对你有用。