0

I am extending promo coupon labels so that I can define a failed label that would display when coupons fail to apply. So far I have been able to add the fields using:

class Module_Promomod_Block_Adminhtml_Promo_Quote_Edit_Tab_Labels extends Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Labels
{

    protected function _prepareForm()
    {
    $rule = Mage::registry('current_promo_quote_rule');
    $form = new Varien_Data_Form();
    $form->setHtmlIdPrefix('rule_');

    $fieldset = $form->addFieldset('default_label_fieldset', array(
        'legend' => Mage::helper('salesrule')->__('Default Label')
    ));
    $labels = $rule->getStoreLabels();
    $fieldset->addField('store_default_label', 'text', array(
        'name' => 'store_labels[0]',
        'required' => false,
        'label' => Mage::helper('salesrule')->__('Default Rule Label for All Store Views'),
        'value' => isset($labels[0]) ? $labels[0] : '',
    ));

    $labels = $rule->getStoreLabels();
    $fieldset->addField('store_default_failed_label', 'text', array(
        'name' => 'store_failed_labels[0]',
        'required' => false,
        'label' => Mage::helper('salesrule')->__('Default Label for failed coupon attempts - All Store Views'),
        'value' => isset($labels[0]) ? $labels[0] : '',
    ));

    $fieldset = $form->addFieldset('store_labels_fieldset', array(
        'legend' => Mage::helper('salesrule')->__('Store View Specific Labels'),
        'table_class' => 'form-list stores-tree',
    ));
    $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset');
    $fieldset->setRenderer($renderer);

    foreach (Mage::app()->getWebsites() as $website) {
        $fieldset->addField("w_{$website->getId()}_label", 'note', array(
            'label' => $website->getName(),
            'fieldset_html_class' => 'website',
        ));
        foreach ($website->getGroups() as $group) {
            $stores = $group->getStores();
            if (count($stores) == 0) {
                continue;
            }
            $fieldset->addField("sg_{$group->getId()}_label", 'note', array(
                'label' => $group->getName(),
                'fieldset_html_class' => 'store-group',
            ));
            foreach ($stores as $store) {
                $fieldset->addField("s_{$store->getId()}", 'text', array(
                    'name' => 'store_labels[' . $store->getId() . ']',
                    'required' => false,
                    'label' => $store->getName(),
                    'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '',
                    'fieldset_html_class' => 'store',
                ));
            }
        }
    }


    if ($rule->isReadonly()) {
        foreach ($fieldset->getElements() as $element) {
            $element->setReadonly(true, true);
        }
    }

    $this->setForm($form);
    //return parent::_prepareForm();
}

}

It seems like the best place to add the field would be in the salesrule_label as an additional column called something like "apply_failed_label". Is there an equivalent to $installer = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->startSetup(); $installer->addAttribute('catalog_product',... that I could use to accomplish this when the module is installed?

1

Yes, and it is just adding a column to the table, for flat tables that are unrelated to EAV entities, you don't need to register any attributes:

$installer->getConnection()
    ->addColumn($installer->getTable('salesrule_label'), 'apply_failed_label', array(
        'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
        'nullable' => false,
        'comment' => 'Apply Failed Label'
    ));

Not the answer you're looking for? Browse other questions tagged or ask your own question.