Magento sorting related products by price

六眼飞鱼酱① 提交于 2019-12-25 06:47:30

问题


i've been trying to sort related products by price in descending oreder (cheapest at the top and expensive at bottom) without any luck so far, maybe someone could guide me on how to do that?


回答1:


See this file app\code\core\Mage\Catalog\Model\Product.php and check this function line 814

public function getRelatedProductCollection()
{
    $collection = $this->getLinkInstance()->useRelatedLinks()
        ->getProductCollection()
        ->setIsStrongMode();
    $collection->setProduct($this);
    return $collection;
}

You need to modify this function by extend this Model Class so first Create an Module and Write this function inside your function. and add Order to collection.

$collection->setOrder('price', 'DESC');


public function getRelatedProductCollection()
{
    $collection = $this->getLinkInstance()->useRelatedLinks()
        ->getProductCollection()
        ->setIsStrongMode();
    $collection->setProduct($this);
    $collection->setOrder('price', 'DESC');
    return $collection;
}

You need to Extend this Module Mage_Catalog_Model_Product and also modify this function




回答2:


Go to /app/code/core/Mage/Catalog/Model/ path and add the below code in Product.php

public function getRelatedProductCollection()
    {
$collection = $this->getLinkInstance()->useRelatedLinks()
        ->getProductCollection()
        ->setIsStrongMode();
    $collection->setProduct($this);
    $collection->setOrder('price', 'DESC');
    return $collection;
    }

You can also use this for weight. Just write 'weight' in place of 'price'. For ascending just write 'ASC' in place of 'DESC' .



来源:https://stackoverflow.com/questions/26179916/magento-sorting-related-products-by-price

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!