2014-10-03 208 views
0

我一直试图按降序排列价格排序相关产品(最便宜的顶部和昂贵的底部)到目前为止没有任何运气,也许有人可以指导我如何做到这一点?Magento按价格排序相关产品

+0

到目前为止你有什么代码... – Ashley 2014-10-03 14:44:28

回答

0

看到此文件的应用程序\代码\核心\法师\目录\型号\ Product.php,并检查该功能线814

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

您需要修改通过扩展这个模型类此功能,所以首先要创建一个模块并在您的功能中写入此功能。并添加订单到收藏。

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


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

您需要扩展这个模块Mage_Catalog_Model_Product并修改该功能

+0

感谢它工作:) – user3540304 2014-10-06 06:45:12

0

转到/应用/代码/核心/法师/目录/型号/路径和Product.php

添加下面的代码
public function getRelatedProductCollection() 
    { 
$collection = $this->getLinkInstance()->useRelatedLinks() 
     ->getProductCollection() 
     ->setIsStrongMode(); 
    $collection->setProduct($this); 
    $collection->setOrder('price', 'DESC'); 
    return $collection; 
    } 

您也可以将此用于体重。只需写'重量'来代替'价格'。 升序只需写'ASC'代替'DESC'。