Sort order of related products seems to be same with sort order of category products.

I would like to use position for sorting. when I tried to set position fields of related products and reindex category products, nothing happen.

Does someone know how to edit specifically for related products?

Sorry Amit

I can't understand your solution. I just would like to use magento default function.

Usually, if I set positional order in related product tab in product editing page. It can use.

I searched the internet and somebody says related.php file has a bug in this thread. Do you think so?



$this->_itemCollection = $product->getRelatedProductCollection()
        ->addAttributeToSort('position', Varien_Db_Select::SQL_ASC)


$this->_itemCollection = $product->getRelatedProductCollection()
        ->setOrder('position', Varien_Db_Select::SQL_ASC)

but this solution also not working for my site.

  • If I set the position value of related products under the respective product's tab in the backend, the related products are shown in the specified order. That does not work for you?
    – Simon
    Nov 14, 2014 at 7:35
  • yes I tried but the sort order seems to follow "created at" setting which i use in default config setting for category.
    – user16342
    Nov 15, 2014 at 7:44

2 Answers 2


You can not sort related product Collection by using position sort field of category

First you need to add catalog_category_product table in related product Collection.


One product may be included on different different categories that product have different position on different category,therefore for this reason on you can only join a category.



Suppose a product is included in two category cat1 and cat2.From admin>Manage Category>

you have set different sort for Cat1-> 5, Cat2->8. That time you will face the issue.

  • Excellent.. +1 for that :-) Nov 14, 2014 at 7:51

I used a custom module to do this. The sorting function is for Magento 1.9.x though (see code block below). It might as well be implemented into your template file, but I did not try this.

public function custom_FilterSort_relatedProducts($_product, $viewType) {
    if( $viewType == 'related' ) :
        $_collection = $_product->getRelatedLinkCollection();
    elseif( $viewType == 'upsell' ) :
        $_collection = $_product;
    foreach ($_collection as $link):
        if( $viewType == 'related' ) :
            $_entityId = $link->getLinkedProductId();
            $relatedProduct = Mage::getModel('catalog/product')->load($link->getLinkedProductId());
        elseif( $viewType == 'upsell' ) :
            $_entityId = $link->getEntityId();
            $relatedProduct = $link;
        $relatedData[$_entityId]['position'] = $link->getPosition();
        $relatedData[$_entityId]['status'] = $relatedProduct->getStatus();
        $relatedData[$_entityId]['avalaibility'] = $relatedProduct->getStockItem()->getIsInStock();
        if( $relatedData[$_entityId]['status'] == 2 || $relatedData[$_entityId]['avalaibility'] == 0 ) {
    uasort($relatedData, function($first, $last) {
        return $first['position'] - $last['position'];
    return $relatedData;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.