I want Magento to sort my related products by the position value I'm giving them in the back-end. When I try to do that, nothing happens; the related products are still sorted by ID and not by position.
I checked the configuration Catalog & rarr; Article sort by & rarr; Position and it seems to be fine.
In Magento version 1.7.1 this bug has been fixed
$this->_itemCollection = $product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->setPositionOrder()
->addStoreFilter()
;
under Mage_Catalog_Block_Product_List_Related
function _prepareData
change from
$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()
;
seems like a bug
I got this error in the Magento Backend Product Edit area of a CE 1.5.1.0, tab "Cross-sells". To fix this I had to use the code of Magento 1.8
diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php
index 2dd1611..813209e 100755
--- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php
+++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php
@@ -95,20 +95,20 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Crosssell extends Mage_Admin
*/
protected function _prepareCollection()
{
+ /* @var $collection Mage_Catalog_Model_Resource_Product_Link_Product_Collection */
$collection = Mage::getModel('catalog/product_link')->useCrossSellLinks()
->getProductCollection()
->setProduct($this->_getProduct())
- ->setPositionOrder()
->addAttributeToSelect('*');
+
if ($this->isReadonly()) {
$productIds = $this->_getSelectedProducts();
if (empty($productIds)) {
$productIds = array(0);
}
- $collection->addFieldToFilter('entity_id', array('in'=>$productIds));
+ $collection->addFieldToFilter('entity_id', array('in' => $productIds));
}
来源:https://stackoverflow.com/questions/8008076/sort-order-of-related-products-not-working-in-magento-1-6