1

I try to add a type(extra field) to newsletter_subscriber table.

Following is my approach to add the field.

1.Add new column to newsletter_subscriber table(types)

2.Add types check box to subscribe.phtml file

3.Create an observer for newsletter_subscriber_save_before event

My Config.xml file is

<?xml version="1.0"?>
<config>
<modules>
    <Wired_Newsletters>
        <version>0.1.0</version>
    </Wired_Newsletters>
</modules>
<global>
    <models>
        <newsletters>
            <class>Wired_Newsletters_Model</class>
        </newsletter>
    </models>
    <events>
        <newsletter_subscriber_save_before>
            <observers>
                <newsletters_add_types>
                    <class>newsletters/observer</class>
                    <method>newsletterSubscriberSave</method>
                </newsletters_add_types>
            </observers>
        </newsletter_subscriber_save_before>
    </events>
 </global>   

My observer.php file(\app\code\local\Wired\Newsletters\Model)

<?php
class Wired_Newsletters_Model_Observer extends Varien_Event_Observer
{
public function newsletterSubscriberSave($observer){
    $subscriber = $observer->getEvent()->getSubscriber();
    $types = Mage::app()->getRequest()->getParam('types');

    $subscriber->setTypes($types);
    //$subscriber->save();
    return $this;
    }
}

Did i miss any steps or my approach is wrong and please advice me how can i check the process is in the relevant observer? Is there any alternative solution add an extra field to newsletter_subscriber table?

1

Model ending is wrong:

<models>
        <newsletters>
            <class>Wired_Newsletters_Model</class>
        </newsletters> <!-- it should be newsletters from newsletter -->
    </models> 

According to magento your model idenfier and end start tags should be same

<config>
    <global>
        <models>
            <{module identifier}>
                <class>{class prefix}</class>
            </{module identifier}>
        </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.