I already had one custom sort by attribute which is agency_id but when i try to add new sort by attribute Location it shows me this error.
a:5:{i:0;s:48:"Joined field with this alias is already declared";i:1;s:3988:"#0 /home/test/public_html/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(695): Mage::exception('Mage_Eav', 'Joined field wi...')
#1 /home/test/public_html/app/code/local/Mage/Catalog/Block/Product/List.php(104): Mage_Eav_Model_Entity_Collection_Abstract->joinField('value', 'customer_entity...', 'value', 'entity_id=agenc...', Array, 'left')
#2 /home/test/public_html/app/code/local/Mage/Catalog/Block/Product/List.php(196): Mage_Catalog_Block_Product_List->_getProductCollection()
#3 /home/test/public_html/app/code/core/Mage/Core/Block/Abstract.php(918): Mage_Catalog_Block_Product_List->_beforeToHtml()
#4 /home/test/public_html/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml()
#5 /home/test/public_html/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('search_result_l...', true)
#6 /home/test/public_html/app/code/local/Mage/CatalogSearch/Block/Advanced/Result.php(103): Mage_Core_Block_Abstract->getChildHtml('search_result_l...')
#7 /home/test/public_html/app/design/frontend/default/default/template/catalogsearch/advanced/result.phtml(58): Mage_CatalogSearch_Block_Advanced_Result->getProductListHtml()
i did changes in
/app/code/local/Mage/Catalog/Block/Product/List.php
i added code in _getProductCollection() as below
$sortBy = $this->getRequest()->getParam('order');
$dir = $this->getRequest()->getParam('dir');
if($sortBy == "review"){
/* added for rating */
$this->_productCollection->joinField('review', 'review_entity_summary', 'rating_summary', 'entity_pk_value=entity_id', array('entity_type'=>1, 'store_id'=> Mage::app()->getStore()->getId()), 'left');
/* added for rating */
}elseif($sortBy == "agency_id"){
/* added for sort by agency id */
$this->_productCollection->addAttributeToFilter('agency_id',array('neq'=>'1111'));
$this->_productCollection->joinField('value', 'customer_entity_varchar', 'value', 'entity_id=agency_id', array('attribute_id'=>5), 'left');
$this->_productCollection->setOrder('value', $dir);
}elseif($sortBy == "package_location"){
/* added for sort by Location */
$this->_productCollection->addAttributeToFilter('package_location',array('neq'=>'1111'));
// $this->_productCollection->joinField('value', 'eav_attribute_option_value', 'value', 'option_id=package_location', array('attribute_id'=>197), 'left');
// $this->_productCollection->setOrder('value', $dir);
}
before i added condition of package_location, agency_id was working fine.
i found this question but its different.
Thanks