2

EDIT:

So I have narrowed it down to the fact that Magento does not like the JOIN when I am adding it to the collection. Is there anyway to make it so it doesnt duplicate the correlation name or whatever it is that is causing the error?


I've added an extra column to my customer order grid that will display the customer's street address, but when I try and export the CSV, I am getting the error "cannot define correlation name more than once". I've extended the Webtex extension "Customer Lifetime Sales" by adding a new function.

Here is my function in the Model:

public function addColumnCustomerStreetAddress($block,$after = null)
    {
        if(is_a($block, 'Mage_Adminhtml_Block_Customer_Grid')){
            $block->addColumn('street_address', array(
                'header'    => Mage::helper('customer')->__('Street Address'),
                'type'      => 'text',
                'align'     => 'center',
                'index'     => 'billing_street_first_line',
                'renderer'  => 'Webtex_CustomerLifetimeSales_Block_Catalog_Product_Renderer_Street'
            ));
            if($after)$block->addColumnOrder($this->getName(), $after);
        }
        return $block;
    }

Here is my join in the Observer that grabs the customers street address:

public function addAttributesToCollection($observer)
    {
        /** @var $collection  Mage_Customer_Model_Resource_Customer_Collection */
        $collection = $observer->getCollection();
        if(is_a($collection,'Mage_Customer_Model_Resource_Customer_Collection'))
            $collection->addAttributeToSelect('total_spent')
                ->addAttributeToSelect('total_in_cart')
                ->addAttributeToSelect('orders_count')
                ->joinAttribute('billing_street_first_line', 'customer_address/street', 'default_billing', null)
                ->addAttributeToSelect('last_order_date');
    }

And finally, here is my renderer:

class Webtex_CustomerLifetimeSales_Block_Catalog_Product_Renderer_Street extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        $value = $row->getData($this->getColumn()->getIndex());
        return $value;
    }
} 

Now this works fine when displaying the street address in the actual grid, but when I try and export to CSV I get this error:

    a:5:{i:0;s:75:"You cannot define a correlation name 'at_my_shipping_street' more than once";i:1;s:2870:"#0 /opt2/sites/mySite/lib/Varien/Db/Select.php(281): Zend_Db_Select->_join('left join', Array, '(`at_my_shippin...', Array, NULL)
#1 /opt2/sites/mySite/lib/Zend/Db/Select.php(357): Varien_Db_Select->_join('left join', Array, '(`at_my_shippin...', Array, NULL)
#2 /opt2/sites/mySite/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1348): Zend_Db_Select->joinLeft(Array, '(`at_my_shippin...', Array)
#3 /opt2/sites/mySite/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1315): Mage_Eav_Model_Entity_Collection_Abstract->_joinAttributeToSelect('joinLeft', Object(Mage_Customer_Model_Attribute), 'at_my_shipping_...', Array, 'my_shipping_str...', 'at_my_shipping_...')
#4 /opt2/sites/mySite/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(668): Mage_Eav_Model_Entity_Collection_Abstract->_addAttributeJoin('my_shipping_str...', 'left')
#5 /opt2/sites/mySite/app/code/local/Webtex/CustomerLifetimeSales/Model/Observer.php(153): Mage_Eav_Model_Entity_Collection_Abstract->joinAttribute('my_shipping_str...', 'customer_addres...', 'default_billing', NULL, 'left')
#6 /opt2/sites/mySite/app/code/core/Mage/Core/Model/App.php(1338): Webtex_CustomerLifetimeSales_Model_Observer->addAttributesToCollection(Object(Varien_Event_Observer))
#7 /opt2/sites/mySite/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Webtex_CustomerLifetimeSales_Model_Observer), 'addAttributesTo...', Object(Varien_Event_Observer))
#8 /opt2/sites/mySite/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('eav_collection_...', Array)
#9 /opt2/sites/mySite/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(863): Mage::dispatchEvent('eav_collection_...', Array)
#10 /opt2/sites/mySite/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(951): Mage_Eav_Model_Entity_Collection_Abstract->load()
#11 /opt2/sites/mySite/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(1008): Mage_Adminhtml_Block_Widget_Grid->_exportIterateCollection('_exportCsvItem', Array)
#12 /opt2/sites/mySite/app/code/core/Mage/Adminhtml/controllers/CustomerController.php(380): Mage_Adminhtml_Block_Widget_Grid->getCsvFile()
#13 /opt2/sites/mySite/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_CustomerController->exportCsvAction()
#14 /opt2/sites/mySite/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('exportCsv')
#15 /opt2/sites/mySite/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#16 /opt2/sites/mySite/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#17 /opt2/sites/mySite/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#18 /opt2/sites/mySite/index.php(91): Mage::run('', 'store')
#19 {main}";s:3:"url";s:83:"/mySite/index.php/myAdminArea/customer/exportCsv/key/be8bdec3e90d2a19c7d05bd23470542b/";s:11:"script_name";s:17:"/mySite/index.php";s:4:"skin";s:5:"admin";}

Your Answer

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

Browse other questions tagged or ask your own question.