0

I want to edit some tables of magento and I've made a module to do that. For example I want to edit table "catalog_product_bundle_price_index".

Here is the global section of my config.xml :

<global>
    <resources>
        <mymodule_setup>
            <setup>
                <module>Mynamespace_Mymodule</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </mymodule_setup>
        <mymodule_read>
            <connection>
                <use>core_read</use>
            </connection>
        </mymodule_read>
        <mymodule_write>
            <connection>
                <use>core_write</use>
            </connection>
        </mymodule_write>
    </resources>
</global>

And here is the code in mysql4-install-1.0.0.php :

$installer = $this;
$installer->startSetup();

$tables = array(
        $installer->getTable('bundle/price_index') => array(
                'columns' => array(
                        'min_price' => array(
                                'type'      => Varien_Db_Ddl_Table::TYPE_DECIMAL,
                                'scale'     => 4,
                                'precision' => 16,
                                'nullable'  => false,
                                'comment'   => 'Min Price'
                        ),
                        'max_price' => array(
                                'type'      => Varien_Db_Ddl_Table::TYPE_DECIMAL,
                                'scale'     => 4,
                                'precision' => 16,
                                'nullable'  => false,
                                'comment'   => 'Max Price'
                        )
                ),
                'comment' => 'Catalog Product Bundle Price Index'
        )
);



$installer->getConnection()->modifyTables($tables);
$installer->endSetup();

but it does not work, What am I doing wrong?

4
  • Try to clear your cache by deletiting everything inside var/cache folder. May be some kind of DDL cache is in place. Feb 5, 2014 at 8:18
  • It does not work, the fields are still decimal(12,4)! Feb 5, 2014 at 8:58
  • I think you should use modifyColumn() abhayraj4u.blogspot.com/2013/03/… Feb 5, 2014 at 9:40
  • I just delete the module and install it again and everything worked perfect!!!! I don't know why, but it seems to be correct! btw, thank you for your concern @EvgeniIvanov :) Feb 5, 2014 at 10:24

2 Answers 2

1

I'm sure the problem was, that you first added the setup to the config.xml which added the information "setup ran" to core_resource. In core_resource is saved which version of your module is installed.

To run the setup again you have to reset the version number or delete the row.

0

Try it using the changeColumn method.
Here is the method signature:

public function changeColumn($tableName, $oldColumnName, $newColumnName, $definition, $flushData = false, $schemaName = null);

it should go something like this:

$installer->getConnection()->changeColumn($installer->getTable('bundle/price_index'), 'min_price', 'min_price', array(
                                'type'      => Varien_Db_Ddl_Table::TYPE_DECIMAL,
                                'scale'     => 4,
                                'precision' => 16,
                                'nullable'  => false,
                                'comment'   => 'Min Price'
                        ));

I haven't tested though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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