3

I have created a custom Module using Ultimate Module Creator and it has created tables named xpresselectricals_customerproductprice_customerproductprice and xpresselectricals_customerproductprice_customerproductprice_store.

I would like to rename these tabels to xe_customer_product_price and xe_customer_product_price_store. I don't know which files have to be edited.

Can anyone guide through the steps?


Below is my Config.xml


<modules>
    <Xpresselectricals_CustomerProductPrice>
        <version>1.0.0</version>
    </Xpresselectricals_CustomerProductPrice>
</modules>
<global>
    <resources>
        <xpresselectricals_customerproductprice_setup>
            <setup>
                <module>Xpresselectricals_CustomerProductPrice</module>
                <class>Xpresselectricals_CustomerProductPrice_Model_Resource_Setup</class>
            </setup>
        </xpresselectricals_customerproductprice_setup>
    </resources>
    <blocks>
        <xpresselectricals_customerproductprice>
            <class>Xpresselectricals_CustomerProductPrice_Block</class>
        </xpresselectricals_customerproductprice>
    </blocks>
    <helpers>
        <xpresselectricals_customerproductprice>
            <class>Xpresselectricals_CustomerProductPrice_Helper</class>
        </xpresselectricals_customerproductprice>
    </helpers>

<events>
    <catalog_product_get_final_price>
        <observers>
            <Xpresselectricals_CustomerProductPrice_price_observer>
                <type>singleton</type>
                    <class>Xpresselectricals_CustomerProductPrice_Model_Observer</class>
                    <method>get_final_price</method>
            </Xpresselectricals_CustomerProductPrice_price_observer>
        </observers>
    </catalog_product_get_final_price>
    <catalog_product_load_after>
        <observers>
            <Xpresselectricals_CustomerProductPrice_price_observer>
                <type>singleton</type>
                    <class>Xpresselectricals_CustomerProductPrice_Model_Observer</class>
                    <method>get_product_load_after</method>
            </Xpresselectricals_CustomerProductPrice_price_observer>
        </observers>
    </catalog_product_load_after>
    <catalog_product_collection_load_after>
        <observers>
            <Xpresselectricals_CustomerProductPrice_price_observer>
                <type>singleton</type>
                    <class>Xpresselectricals_CustomerProductPrice_Model_Observer</class>
                    <method>get_product_collection_load_after</method>
            </Xpresselectricals_CustomerProductPrice_price_observer>
        </observers>
    </catalog_product_collection_load_after>
</events>






    <models>
        <xpresselectricals_customerproductprice>
            <class>Xpresselectricals_CustomerProductPrice_Model</class>
            <resourceModel>xpresselectricals_customerproductprice_resource</resourceModel>
        </xpresselectricals_customerproductprice>
        <xpresselectricals_customerproductprice_resource>
            <class>Xpresselectricals_CustomerProductPrice_Model_Resource</class>
            <entities>
                <customerproductprice>
                    <table>xpresselectricals_customerproductprice_customerproductprice</table>
                </customerproductprice>
                <customerproductprice_store>
                    <table>xpresselectricals_customerproductprice_customerproductprice_store</table>
                </customerproductprice_store>
            </entities>
        </xpresselectricals_customerproductprice_resource>
    </models>
</global>
<adminhtml>
    <layout>
        <updates>
            <xpresselectricals_customerproductprice>
                <file>xpresselectricals_customerproductprice.xml</file>
            </xpresselectricals_customerproductprice>
        </updates>
    </layout>
    <translate>
        <modules>
            <Xpresselectricals_CustomerProductPrice>
                <files>
                    <default>Xpresselectricals_CustomerProductPrice.csv</default>
                </files>
            </Xpresselectricals_CustomerProductPrice>
        </modules>
    </translate>
    <global_search>
        <customerproductprice>
            <class>xpresselectricals_customerproductprice/adminhtml_search_customerproductprice</class>
            <acl>xpresselectricals_customerproductprice</acl>
        </customerproductprice>
    </global_search>
</adminhtml>
<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Xpresselectricals_CustomerProductPrice before="Mage_Adminhtml">Xpresselectricals_CustomerProductPrice_Adminhtml</Xpresselectricals_CustomerProductPrice>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>
<frontend>
    <routers>
        <xpresselectricals_customerproductprice>
            <use>standard</use>
            <args>
                <module>Xpresselectricals_CustomerProductPrice</module>
                <frontName>xpresselectricals_customerproductprice</frontName>
            </args>
        </xpresselectricals_customerproductprice>
    </routers>
    <layout>
        <updates>
            <xpresselectricals_customerproductprice>
                <file>xpresselectricals_customerproductprice.xml</file>
            </xpresselectricals_customerproductprice>
        </updates>
    </layout>
    <translate>
        <modules>
            <Xpresselectricals_CustomerProductPrice>
                <files>
                    <default>Xpresselectricals_CustomerProductPrice.csv</default>
                </files>
            </Xpresselectricals_CustomerProductPrice>
        </modules>
    </translate>
</frontend>
<default>
    <xpresselectricals_customerproductprice>
        <customerproductprice>
            <breadcrumbs>1</breadcrumbs>
        </customerproductprice>
    </xpresselectricals_customerproductprice>
</default>

  • Can you please add code for your config.xml file? – John Jun 8 '17 at 6:19
  • @John i have updated my question with Config.xml – Guruprasad Jun 8 '17 at 6:53
  • 1
    Can you add your module version code(full config.xml)? It will require to create upgrade script. – Jaimin Sutariya Jun 8 '17 at 6:56
  • @JaiminSutariya i have updated with full Config.xml – Guruprasad Jun 8 '17 at 7:00
  • @Guruprasad, did you get the solution of your question? – Jaimin Sutariya Jun 8 '17 at 9:39
5

There is a function available in Magento to rename a table. Check, Varien_Db_Adapter_Pdo_Mysql::renameTable($oldTableName, $newTableName, $schemaName = null)

Update your models tag in config.xml by below.

<models>
    <xpresselectricals_customerproductprice>
        <class>Xpresselectricals_CustomerProductPrice_Model</class>
        <resourceModel>xpresselectricals_customerproductprice_resource</resourceModel>
    </xpresselectricals_customerproductprice>
    <xpresselectricals_customerproductprice_resource>
        <class>Xpresselectricals_CustomerProductPrice_Model_Resource</class>
        <entities>
            <customerproductprice>
                <table>xpresselectricals_customerproductprice_customerproductprice</table>
            </customerproductprice>
            <customerproductprice_store>
                <table>xpresselectricals_customerproductprice_customerproductprice_store</table>
            </customerproductprice_store>
            <customerproductprice_new>
                <table>xe_customer_product_price</table>
            </customerproductprice_new>
            <customerproductprice_store_new>
                <table>xe_customer_product_price_store</table>
            </customerproductprice_store_new>
        </entities>
    </xpresselectricals_customerproductprice_resource>
</models>

Update your module's version from 1.0.0 to 1.0.1 in below lines.

<modules>
    <Xpresselectricals_CustomerProductPrice>
        <version>1.0.1</version>
    </Xpresselectricals_CustomerProductPrice>
</modules>

Now create a new file in your sql/xpresselectricals_customerproductprice_setup/upgrade-1.0.0-1.0.1.php with below code

<?php

$installer = $this;

$installer->startSetup();

$this->getConnection()->renameTable($this->getTable('customerproductprice'),$this->getTable('customerproductprice_new'));
$this->getConnection()->renameTable($this->getTable('customerproductprice_store'),$this->getTable('customerproductprice_store_new'));
$installer->endSetup();

Now go to admin panel and refresh your cache. Once you are done with refreshing your cache, update your models section again to below.

<models>
    <xpresselectricals_customerproductprice>
        <class>Xpresselectricals_CustomerProductPrice_Model</class>
        <resourceModel>xpresselectricals_customerproductprice_resource</resourceModel>
    </xpresselectricals_customerproductprice>
    <xpresselectricals_customerproductprice_resource>
        <class>Xpresselectricals_CustomerProductPrice_Model_Resource</class>
        <entities>
            <customerproductprice>
                <table>xe_customer_product_price</table>
            </customerproductprice>
            <customerproductprice_store>
                <table>xe_customer_product_price_store</table>
            </customerproductprice_store>
        </entities>
    </xpresselectricals_customerproductprice_resource>
</models>
  • this didnt work, it is not creating the new table in the database – Guruprasad Jun 8 '17 at 9:40
  • It will not create new tables, it will rename your old tables to new tables. Also you need to refresh your cache to run the upgrade script – Jaimin Sutariya Jun 8 '17 at 9:51
  • i did the same, but it dint rename the tables – Guruprasad Jun 8 '17 at 9:53
  • oh yes, there is one more thing you need to do. please check updated code. – Jaimin Sutariya Jun 8 '17 at 10:00
  • Hi @jaimin your updated answer worked!! thank you – Guruprasad Jun 9 '17 at 6:22

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.