2
votes

I want to add a custom field to the actions tab in the Catalog Price Rules section.

This is what I did:

  1. I added these lines to the file app\code\core\Mage\Adminhtml\Block\Promo\Catalog\Edit\Tab\Actions.php

    $fieldset->addField('custom_field', 'select', array(
        'label'     => 'Custom Field',
        'title'     => 'Custom Field',
        'name'      => 'custom_field',
        'options'    => array(
            '1' => Mage::helper('catalogrule')->__('Yes'),
            '0' => Mage::helper('catalogrule')->__('No'),
        ),
    ));
    
  2. I changed the version to 1.6.0.4 in this file: app\code\core\Mage\CatalogRule\etc\config.xml

    <Mage_CatalogRule>
        <version>1.6.0.4</version>
    </Mage_CatalogRule>
    
  3. I created new file with the name app\code\core\Mage\CatalogRule\sql\catalogrule_setup\upgrade-1.6.0.3-1.6.0.4.php
$installer->startSetup();
$ruleProductTable = $installer->getTable('catalogrule/rule');
$columnOptions = array(
    'TYPE' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
    'UNSIGNED'  => true,
    'NULLABLE'  => false,
    'DEFAULT'   => 0,
    'COMMENT'   => 'Custom Field',
);
$installer->getConnection()->addColumn($ruleProductTable, 'custom_field', $columnOptions);
$installer->endSetup();

Then, I logged in to the admin panel and tried to edit one of the catalog price rules.

I saw my new field in the actions tab - great!

But when I click "Save", the changes that I made in that field, was not saved.

I logged in to the phpmyadmin and went to catalogrule table. In this table I can see the new field custom_field, with the value 0 (default) - so It really didn't save the changed.

My question is what I did wrong? Why the changed in the custom_field didn't saved in the DB?

Thanks

1

1 Answers

0
votes

I'm not sure why it isn't working for you my guess is your installer isn't being called. I managed the modification through a module and local edits to future proof the change.

Directory structure:

/app/code/local/custom/promo
/app/code/local/custom/promo/etc/
/app/code/local/custom/promo/sql
/app/code/local/custom/promo/sql/promo_setup
/app/code/core/local/Adminhtml/Block/Promo/Catalog/Edit/Tab

add file /app/code/local/custom/promo/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_Promo>
            <version>1.0</version>
        </Custom_Promo>
    </modules>
    <global>
        <resources>
            <promo_setup>
                <setup>
                    <module>Custom_Promo</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
            </promo_setup>
        </resources>
    </global>
</config>

add file /app/code/local/custom/promo/sql/promo_setup/install-1-0.php

/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$ruleProductTable = $installer->getTable('catalogrule/rule');
$columnOptions = array(
    'TYPE' => Varien_Db_Ddl_Table::TYPE_BOOLEAN,
    'NULLABLE'  => false,
    'COMMENT'   => 'Custom Promo',
);
$installer->getConnection()->addColumn($ruleProductTable, 'custom_promo', $columnOptions);
$installer->endSetup();

Clear caches and verify the column is added by looking at the catalog_rule table

SELECT * FROM catalogrule;

Finally take a copy of /app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php and create the same file /app/code/core/local/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php

Edit the file and add the field before $form->setValues($model->getData());

//Custom Promo
        $fieldset->addField('custom_promo', 'select', array(
            'label'     => 'Custom Promo',
            'title'     => 'Custom Promo',
            'name'      => 'custom_promo',
            'options'    => array(
                '1' => Mage::helper('catalogrule')->__('Yes'),
                '0' => Mage::helper('catalogrule')->__('No'),
            ),
        ));