0

I'm using Magento CE 1.7. I want to add the customer telephone number to the Abandoned Cart grid (Reports->Shopping Carts->Abandoned Carts). I have overridden the block Mage_Adminhtml_Block_Report_Shopcart_Abandoned_Grid. My _prepareCollection() function is as below. But it loads the wrong telephone number. Can anyone suggest what tables should i join here or the issue with this code ? Any help will be appreciated.

protected function _prepareCollection()
    {               
        $collection = Mage::getResourceModel('reports/quote_collection');

        $filter = $this->getParam($this->getVarNameFilter(), array());
        if ($filter) {
            $filter = base64_decode($filter);
            parse_str(urldecode($filter), $data);
        }

        if (!empty($data)) {
            $collection->prepareForAbandonedReport($this->_storeIds, $data);
        } else {
            $collection->prepareForAbandonedReport($this->_storeIds);
        }

        //-----------------------------------------------------------------------
        // Get customer telephone.
        $collection->getSelect()
        ->joinLeft(
        array('table_billing'=>'customer_entity_int'),
        ('table_billing.entity_id=main_table.customer_id AND table_billing.attribute_id=13'), // 'default_billing' attribute id = 13
        array('table_billing_value'=>'value')
        )

        ->joinLeft(
        array('table_billing_telephone'=>'customer_address_entity_varchar'),
        ('table_billing_telephone.entity_id=main_table.customer_id AND table_billing_telephone.attribute_id=31'), // 'telephone' attribute id = 31 
        array('telephone'=>'value')
        );  

        //-----------------------------------------------------------------------

        $this->setCollection($collection);
        return Mage_Adminhtml_Block_Report_Grid_Shopcart::_prepareCollection();
    }
2

Hi the problem is with this join,

    ->joinLeft(
    array('table_billing_telephone'=>'customer_address_entity_varchar'),
    ('table_billing_telephone.entity_id=main_table.customer_id AND table_billing_telephone.attribute_id=31'), // 'telephone' attribute id = 31 
    array('telephone'=>'value')
    );

You're join condition is

table_billing_telephone.entity_id = main_table.customer_id

"table_billing_telephone.entity_id" is referring to the Address entity and not the Customer entity so joining on this field will have an unexpected result.

To fix this you need to join the customers billing table which should be already included through your first join as table_billing.

So the second join should read

   ->joinLeft(
    array('table_billing_telephone'=>'customer_address_entity_varchar'),
    ('table_billing_telephone.entity_id=`table_billing`.`value` AND table_billing_telephone.attribute_id=31'), // 'telephone' attribute id = 31 
    array('telephone'=>'value')
    );  

This will then return the correct telephone numbers for each customer

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.