1

I am currently trying to create a module to fix a core Magento bug as outlined here, however after doing so, and navigating to Reports > Shopping Cart > Abandoned Carts, I receive the following error:

Fatal error: Call to a member function prepareForAbandonedReport() on boolean in /home/stagestickers4/public_html/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned/Grid.php on line 57

app/etc/modules/COMPANY_AbandonCart.xml

<?xml version="1.0"?>
<config>
    <modules>
        <COMPANY_AbandonCart>
            <active>true</active>
            <codePool>local</codePool>
        </COMPANY_AbandonCart>
    </modules>
</config> 

app/code/local/COMPANY/AbandonCart/Model/Resource/Quote/Collection.php

<?php
class COMPANY_AbandonCart_Model_Resource_Quote_Collection extends Mage_Reports_Model_Resource_Quote_Collection
{
    public function addCustomerData($filter = null)
    {
        $customerEntity          = Mage::getResourceSingleton('customer/customer');
        $attrFirstname           = $customerEntity->getAttribute('firstname');
        $attrFirstnameId         = (int) $attrFirstname->getAttributeId();
        $attrFirstnameTableName  = $attrFirstname->getBackend()->getTable();

        $attrLastname            = $customerEntity->getAttribute('lastname');
        $attrLastnameId          = (int) $attrLastname->getAttributeId();
        $attrLastnameTableName   = $attrLastname->getBackend()->getTable();

        $attrMiddlename          = $customerEntity->getAttribute('middlename');
        $attrMiddlenameId        = (int) $attrMiddlename->getAttributeId();
        $attrMiddlenameTableName = $attrMiddlename->getBackend()->getTable();

        $attrEmail       = $customerEntity->getAttribute('email');
        $attrEmailTableName = $attrEmail->getBackend()->getTable();

        $adapter = $this->getSelect()->getAdapter();
        $customerName = $adapter->getConcatSql(array('cust_fname.value', 'cust_mname.value', 'cust_lname.value',), ' ');
        $this->getSelect()
            ->joinInner(
                array('cust_email' => $attrEmailTableName),
                'cust_email.entity_id = main_table.customer_id',
                array('email' => 'cust_email.email')
            )
            ->joinInner(
                array('cust_fname' => $attrFirstnameTableName),
                implode(' AND ', array(
                    'cust_fname.entity_id = main_table.customer_id',
                    $adapter->quoteInto('cust_fname.attribute_id = ?', (int) $attrFirstnameId),
                )),
                array('firstname' => 'cust_fname.value')
            )
            ->joinLeft(
                array('cust_mname' => $attrMiddlenameTableName),
                implode(' AND ', array(
                    'cust_mname.entity_id = main_table.customer_id',
                    $adapter->quoteInto('cust_mname.attribute_id = ?', (int) $attrMiddlenameId),
                )),
                array('middlename' => 'cust_mname.value')
            )
            ->joinInner(
                array('cust_lname' => $attrLastnameTableName),
                implode(' AND ', array(
                    'cust_lname.entity_id = main_table.customer_id',
                     $adapter->quoteInto('cust_lname.attribute_id = ?', (int) $attrLastnameId)
                )),
                array(
                    'lastname'      => 'cust_lname.value',
                    'customer_name' => $customerName
                )
            );

        $this->_joinedFields['customer_name'] = $customerName;
        $this->_joinedFields['email']         = 'cust_email.email';

        if ($filter) {
            if (isset($filter['customer_name'])) {
                $likeExpr = '%' . $filter['customer_name'] . '%';
                $this->getSelect()->where($this->_joinedFields['customer_name'] . ' LIKE ?', $likeExpr);
            }
            if (isset($filter['email'])) {
                $likeExpr = '%' . $filter['email'] . '%';
                $this->getSelect()->where($this->_joinedFields['email'] . ' LIKE ?', $likeExpr);
            }
        }

        return $this;
    }
}

app/code/local/COMPANY/AbandonCart/etc/config.xml##

<?xml version="1.0"?>
<config>
    <modules>
        <COMPANY_AbandonCart>
            <version>0.0.1</version>
        </COMPANY_AbandonCart>
    </modules>
    <global>
        <models>
            <reports_resource>
                <rewrite>
                    <quote_collection>COMPANY_AbandonCart_Resource_Quote_Collection</quote_collection>
                </rewrite>
            </reports_resource>
        </models>
    </global>
</config>

I read that extending a Collection is a little different to extending a normal model - guessing some sort of XML-related issue?

4

Your XML class name is wrong. Your model class is

COMPANY_AbandonCart_Model_Resource_Quote_Collection

but your XML rewrite says

COMPANY_AbandonCart_Resource_Quote_Collection

Edit:

  1. It may be oppion based, but I would not fix bugs in core with rewrites. I'd copy the fixed file to local codepool (app/code/local/Mage/Reports/Model/Resource/Quote/Collection.php)
  2. When fixing this, you can also replace the other joinInner with joinLeft
  3. Maybe use Magento-LTS instead, where this bug already has been fixed ;)
-1

Change your app/code/local/COMPANY/AbandonCart/etc/config.xml with below code and fatal error is fixed:

<?xml version="1.0"?>
<config>
    <modules>
        <COMPANY_AbandonCart>
            <version>0.0.1</version>
        </COMPANY_AbandonCart>
    </modules>
    <global>
        <models>
            <reports_resource>
                <rewrite>
                    <quote_collection>COMPANY_AbandonCart_Model_Resource_Quote_Collection</quote_collection>
                </rewrite>
            </reports_resource>
        </models>
    </global>
</config>

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.