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' .