0

I am getting the following error when trying to export orders to CSV but am none the wiser on how to fix it!

EDIT: I am using an observer to add a Country column please see my module below, how can I fix this?

ERROR:

a:5:{i:0;s:62:"You cannot define a correlation name 'shipping' more than once";i:1;s:2687:"#0 /var/www/vhosts/MYSITE/httpdocs/lib/Varien/Db/Select.php(281): Zend_Db_Select->_join('left join', Array, 'main_table.enti...', Array, NULL)
#1 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Zend/Db/Select.php(373): Varien_Db_Select->_join('left join', Array, 'main_table.enti...', Array, NULL)
#2 /var/www/vhosts/MYSITE/httpdocs/app/code/local/Atwix/ExtendedGrid/Model/Observer.php(34): Zend_Db_Select->joinLeft(Array, 'main_table.enti...', Array)
#3 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Core/Model/App.php(1357): Atwix_ExtendedGrid_Model_Observer->salesOrderGridCollectionLoadBefore(Object(Varien_Event_Observer))
#4 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Core/Model/App.php(1336): Mage_Core_Model_App->_callObserverMethod(Object(Atwix_ExtendedGrid_Model_Observer), 'salesOrderGridC...', Object(Varien_Event_Observer))
#5 /var/www/vhosts/MYSITE/httpdocs/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('sales_order_gri...', Array)
#6 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php(590): Mage::dispatchEvent('sales_order_gri...', Array)
#7 /var/www/vhosts/MYSITE/httpdocs/lib/Varien/Data/Collection/Db.php(565): Mage_Core_Model_Resource_Db_Collection_Abstract->_beforeLoad()
#8 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(951): Varien_Data_Collection_Db->load()
#9 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(1008): Mage_Adminhtml_Block_Widget_Grid->_exportIterateCollection('_exportCsvItem', Array)
#10 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php(703): Mage_Adminhtml_Block_Widget_Grid->getCsvFile()
#11 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Sales_OrderController->exportCsvAction()
#12 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('exportCsv')
#13 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#14 /var/www/vhosts/MYSITE/httpdocs/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#15 /var/www/vhosts/MYSITE/httpdocs/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#16 /var/www/vhosts/MYSITE/httpdocs/index.php(87): Mage::run('', 'store')
#17 {main}";s:3:"url";s:103:"/index.php/spadmin/sales_order/exportCsv/key/54346fe7eb59bee82fd6e0a6aa777ff2/internal_order_ids/21318/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}

MY MODULE:

app/code/local/Atwix/ExtendedGrid/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Atwix_ExtendedGrid>
            <version>1.0.1</version>
        </Atwix_ExtendedGrid>
    </modules>
    <global>
        <blocks>
            <atwix_extendedgrid>
                <class>Atwix_ExtendedGrid_Block</class>
            </atwix_extendedgrid>
        </blocks>
        <helpers>
            <atwix_extendedgrid>
                <class>Atwix_ExtendedGrid_Helper</class>
            </atwix_extendedgrid>
        </helpers>
        <models>
            <atwix_extendedgrid>
                <class>Atwix_ExtendedGrid_Model</class>
            </atwix_extendedgrid>
            <sales_resource>
                <rewrite>
                    <order_grid_collection>Atwix_ExtendedGrid_Model_Resource_Sales_Order_Grid_Collection</order_grid_collection>
                </rewrite>
            </sales_resource>
        </models>
    </global>
    <adminhtml>
        <events>
            <sales_order_grid_collection_load_before>
                <observers>
                    <atwix_exgrid>
                        <model>atwix_extendedgrid/observer</model>
                        <method>salesOrderGridCollectionLoadBefore</method>
                    </atwix_exgrid>
                </observers>
            </sales_order_grid_collection_load_before>
        </events>
        <layout>
            <updates>
                <atwix_extendedgrid>
                    <file>atwix/extendedgrid.xml</file>
                </atwix_extendedgrid>
            </updates>
        </layout>
    </adminhtml>
</config>

app/code/local/Atwix/ExtendedGrid/model/Observer.php

<?php

class Atwix_ExtendedGrid_Model_Observer
{
    /**
     * Joins extra tables for adding custom columns to Mage_Adminhtml_Block_Sales_Order_Grid
     * @param Varien_Object $observer
     * @return Atwix_Exgrid_Model_Observer
     */
    public function salesOrderGridCollectionLoadBefore($observer)
    {
        $collection = $observer->getOrderGridCollection();
        $select = $collection->getSelect();
        $collection->getSelect()->joinLeft(array('shipping'=>'sales_flat_order_address'),
    'main_table.entity_id = shipping.parent_id AND shipping.address_type="shipping"',array('shipping.country_id AS bp'));
        $select->group('main_table.entity_id');
    }

    /**
     * callback function used to filter collection
     * @param $collection
     * @param $column
     * @return $this
     */

}

app/code/local/Atwix/ExtendedGrid/ModelResource/Sales/Order/Grid/Collection.php

<?php

class Atwix_ExtendedGrid_Model_Resource_Sales_Order_Grid_Collection extends Mage_Sales_Model_Resource_Order_Grid_Collection
{

    /**
     * Get SQL for get record count
     *
     * @return Varien_Db_Select
     */
    public function getSelectCountSql()
    {
        $countSelect = parent::getSelectCountSql();

        if (Mage::app()->getRequest()->getControllerName() == 'sales_order') {
            $countSelect->reset(Zend_Db_Select::GROUP);
            $countSelect->reset(Zend_Db_Select::COLUMNS);
            $countSelect->columns("COUNT(DISTINCT main_table.entity_id)");

            $havingCondition = $countSelect->getPart(Zend_Db_Select::HAVING);
            if (count($havingCondition)) {
                $countSelect->where(
                    str_replace("group_concat(`sales_flat_order_item`.sku SEPARATOR ', ')", 'sales_flat_order_item.sku', $havingCondition[0])
                );
                $countSelect->reset(Zend_Db_Select::HAVING);
            }
        }

        return $countSelect;
    }

    /**
     * Init select
     * @return Mage_Core_Model_Resource_Db_Collection_Abstract
     */
    protected function _initSelect()
    {
        $this->addFilterToMap('store_id', 'main_table.store_id')
            ->addFilterToMap('created_at', 'main_table.created_at')
            ->addFilterToMap('updated_at', 'main_table.updated_at');
        return parent::_initSelect();
    }
}

app/code/local/Atwix/ExtendedGrid/Helper/Data.php

<?php


class Atwix_ExtendedGrid_Helper_Data extends Mage_Core_Helper_Abstract
{
    /**
     * parameters for addColumnAfter method
     * @return array
     */
    public function getSkusColumnParams()
    {
        return array(
        'header' => Mage::helper('sales')->__('Shipping Country'),
        'index' => 'bp',
        'width' => '60px',
        'filter_index'  => 'shipping.country_id'
    );
    }
}
0

Seems an error from Atwix_ExtendedGrid extension.

Try disabling that extension from app/etc/modules/Atwix_ExtendedGrid.xml by setting active to false.

Flush your cache after editing it.

If disabling the extension works please contact Atwix for support.

  • The Atwix extension is my own code an Observer to add a country column to the order grid please see my code above :) – KiwisTasteGood Mar 8 '16 at 10:07
  • Is that possible your method is called twice? – Phoenix128_RiccardoT Mar 8 '16 at 10:22
  • I'm note too sure I have edited the post with my plugin source! – KiwisTasteGood Mar 8 '16 at 11:37
  • It should not be called twice, but can you check it? – Phoenix128_RiccardoT Mar 8 '16 at 11:39
  • Where would I check to see if it has been called twice? – KiwisTasteGood Mar 8 '16 at 12:45
0

This issue caused because atwix captured event sales_order_grid_collection_load_before and on same event tried to left join function. In error report

#1 /var/www/html/lib/Zend/Db/Select.php(357): Varien_Db_Select->_join('left join', Array, 'payment.parent_...', Array, NULL)
#2 /var/www/html/app/code/local/Atwix/ExtendedGrid/Model/Observer.php(33): Zend_Db_Select->joinLeft(Array, 'payment.parent_...', Array)

Shows two events performing same collection join function.

I tried to stop atwix left join on sales export csv action and this resolved issue to get csv file.

  • Thanks fo the reply, how can I change my left join then to still work in pulling in the shipping country, while not conflicting? – KiwisTasteGood Mar 30 '16 at 15:06

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.