Magento – how to sort related products by position? magento 1.6

magento-1.6sorting

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?

core>Mage>Catalog>Block>Product>List>Related.php

Original

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

to

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

but this solution also not working for my site.

Best Answer

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.

Because

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.

$collection->joinField('category_id',
    'catalog/category_product',
    '*',
    'product_id=product_id',
    null,
    'left'
);
$collection->addAttributeToFilter('category_id',5);

Example:

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.

Related Topic