0

I am trying to update the existing newsletter_subscriber table by adding 2 more additional columns, and updating the grid view within the Adminhtml by adding those 2 new columns and removing the middle name, website, etc.

Step 1: I successfully updated the front-end portion to include the required information in a phtml pop up and validating the fields.

Below are the basics of what I started for updating the database and moving towards the backend of my tasks, but seem to be getting nowhere. I have books and have been combing through Magento resources, to no avail other than feeling more perplexed.

My config.xml I have tried adding a class within the setup tags

(<class>Mage_Newsletter_Model_Resource_Subscriber_Collection</class>)

but I end up with a

Fatal error: Call to a member function getReadConnection() on string in...Mage/Core/Model/Resource/Db/Collection/Abstract.php on line 134:

    <?xml version="1.0"?>
<config>
    <modules>
        <CollegePark_Newsletter>
            <version>1.0.0</version>
        </CollegePark_Newsletter>
    </modules>
    <global>
        <resources>
            <cp_newsletter_setup>
                <setup>
                    <module>CollegePark_Newsletter</module>
                </setup>
            </cp_newsletter_setup>
        </resources>
    </global>
</config>

app/etc/modules/CollegePark_Newsletter.xml:

<?xml version="1.0"?>
    <config>
        <modules>
            <CollegePark_Newsletter>
                <active>true</active>
                <codePool>local</codePool>
                <depends>
                    <Mage_Newsletter />
                </depends>
            </CollegePark_Newsletter>
        </modules>
    </config>

And last my CollegePark/Newsletter/sql/cp_newsletter_setup/install-1.0.0.php:

    <?php
/**
 * Upgrade script to add columns:
 * 
 */

/* @var $installer Mage_Core_Model_Resource_Setup */

$installer = $this;
$installer->startSetup();
$installer->getConnection()
    ->addColumn(
        $installer->getTable('newsletter/subscriber'),
        'subscriber_facility',
        [
            'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
            'nullable'  => true,
            'comment'   => 'Facility'
        ]
    );

$installer->getConnection()
    ->addColumn(
        $installer->getTable('newsletter/subscriber'),
        'subscriber_zip',
        [
            'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
            'nullable'  => true,
            'comment'   => 'Zip/Postal Code'
        ]
    );
$installer->endSetup();

So to all you gurus out there, what am I doing wrong???

0

Ok, so I found out what was going on!!! Not sure why, but having my module named Newsletter seemed to be the issue. Once I modified it to Subscriber throughout, it worked. I did add a resourceModel tag and extended the proper class applied. I updated my data table with ease after I supplied a few modifications from further research on various threads. Now I am moving on to updated the database with info from the popup form, php validation, and lastly updating the Subscribers Adminhtml grid with removing the Middle Name along with a few other columns and adding the newly added columns to the grid. Any questions, let me know! Hopefully this helps someone else trying to modify or extend the Newsletter capabilities!

Updated config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <CollegePark_Subscriber>
            <version>1.0.0</version>
        </CollegePark_Subscriber>
    </modules>
    <global>
        <models>
            <cp_subscriber>
                <class>CollegePark_Subscriber_Model</class>
                <resourceModel>cp_subscriber_resources</resourceModel>
            </cp_subscriber>
            <cp_subscriber_resources>
                <class>CollegePark_Subscriber_Model_Resource</class>
            </cp_subscriber_resources>
        </models>
        <resources>
            <cp_subscriber_setup>
                <setup>
                    <module>CollegePark_Subscriber</module>
                </setup>
            </cp_subscriber_setup>
        </resources>
    </global>
</config>

Updated CollegePark/Subscriber/Model/Subscriber.php

<?php
class CollegePark_Newsletter_Model_Subscriber extends Mage_Core_Model_Resource_Abstract 
{

    public function _construct()
    {
        parent::_construct();
        $this->_init('newsletter/subscriber');
    }
}

Updated CollegePark/Subscriber/Model/Resource/Subscriber.php

<?php
/**
 * Upgrade script to add columns:
 /* Facility for Subscriber and Zip/Postal Code for Subscriber submission
 /* 
 */

/* @var $installer Mage_Core_Model_Resource_Setup */
    class CollegePark_Newsletter_Model_Resource_Subscriber extends Mage_Core_Model_Resource_Db_Abstract
{
    public function _construct()
    {
        $this->_init('newsletter/subscriber', 'subscriber_id');
    }
}

And last but not least, updated CollegePark/Subscriber/Model/Resource/Subscriber/Collection.php

<?php
/**
 * Upgrade script to add columns:
 /* Facility for Subscriber and Zip/Postal Code for Subscriber submission
 /* 
 */

/* @var $installer Mage_Core_Model_Resource_Setup */
    class CollegePark_Newsletter_Model_Resource_Subscriber_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('newsletter/subscriber', 'subscriber_id');
    }
}

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.