2

When I try to export csv in Sales > Order Grid, I am getting

        You cannot define a correlation name 'order' more than once

Trace: #0 /www/Myproject/htdocs/lib/Varien/Db/Select.php(281): Zend_Db_Select->_join('left join', Array, 'order.entity_id...', Array, NULL) #1 /www/Myproject/htdocs/lib/Zend/Db/Select.php(357): Varien_Db_Select->_join('left join', Array, 'order.entity_id...', Array, NULL) #2 /www/Myproject/htdocs/app/code/local/Abc/OrderType/Model/Observer.php(32): Zend_Db_Select->joinLeft(Array, 'order.entity_id...', Array) #3 /www/Myproject/htdocs/app/code/core/Mage/Core/Model/App.php(1339): Abc_OrderType_Model_Observer->salesOrderGridCollectionLoadBefore(Object(Varien_Event_Observer)) #4 /www/Myproject/htdocs/app/code/core/Mage/Core/Model/App.php(1318): Mage_Core_Model_App->_callObserverMethod(Object(Abc_OrderType_Model_Observer), 'salesOrderGridC...', Object(Varien_Event_Observer)) #5 /www/Myproject/htdocs/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('sales_order_gri...', Array) #6 /www/Myproject/htdocs/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php(590): Mage::dispatchEvent('sales_order_gri...', Array) #7 /www/Myproject/htdocs/lib/Varien/Data/Collection/Db.php(565): Mage_Core_Model_Resource_Db_Collection_Abstract->_beforeLoad() #8 /www/Myproject/htdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(951): Varien_Data_Collection_Db->load() #9 /www/Myproject/htdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(1011): Mage_Adminhtml_Block_Widget_Grid->_exportIterateCollection('_exportCsvItem', Array) #10 /www/Myproject/htdocs/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php(703): Mage_Adminhtml_Block_Widget_Grid->getCsvFile() #11 /www/Myproject/htdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Sales_OrderController->exportCsvAction() #12 /www/Myproject/htdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('exportCsv') #13 /www/Myproject/htdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) #14 /www/Myproject/htdocs/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch() #15 /www/Myproject/htdocs/app/Mage.php(684): Mage_Core_Model_App->run(Array) #16 /www/Myproject/htdocs/index.php(87): Mage::run('', 'store')

And my observer method looks like

public function salesOrderGridCollectionLoadBefore($observer) {
        $collection = $observer->getOrderGridCollection();
        $select = $collection->getSelect();
        $select->joinLeft(array('order' => $collection->getTable('sales/order'))
                , 'order.entity_id=main_table.entity_id'
                , array('type' => 'type'));
    }
  • what event are you using? – David Manners Dec 26 '16 at 17:11
3

It sounds like the event is called multiple times. Causing your code in observer to change the collection multiple times.

You should set a flag on collection and only inject your change if flag is not set. Alternatively determine why event is fired multiple times. Determine if that is correct. Maybe you are using the wrong event for your customization.

Hope that helps.

  • Yes, event is being called multiple times, thanks man :D – Abdul Ghaffar Dec 27 '16 at 5:29
0

It's because Magento tries to join the same collection with the same alias twice. Trying using order_new as your alias.

  • Now getting "You cannot define a correlation name 'order_new' more than once" – Abdul Ghaffar Dec 26 '16 at 13:40
  • try printing your query and check – Priyank Dec 26 '16 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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