0

I'm using Magento 1.9.0.1

I have set everything in my new custom extension but i've noticed a problem when I packed my extension and I tried to install it on other magento.

It seems that my SQL "rules/actions" for creating the MySQL table of my extension are not working.

Let me show you my entrire config file:

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_SmsNotification>
      <version>1.0.0</version>
    </VivasIndustries_SmsNotification>
  </modules>
  <global>
    <models>
        <smsnotification>
            <class>VivasIndustries_SmsNotification_Model</class>
            <resourceModel>vivasindustries_smsnotification_resource</resourceModel>
        </smsnotification>
        <vivasindustries_smsnotification_resource>
        <class>VivasIndustries_SmsNotification_Model_Resource</class>
        <entities>
            <smsnotification>
            <table>VivasIndustries_SmsNotification</table>
            </smsnotification>
            <smsnotificationhistory>
            <table>VivasIndustries_SmsHistory</table>
            </smsnotificationhistory>
        </entities>
        </vivasindustries_smsnotification_resource>
    </models>
    <resources>
        <smsnotification_setup>
            <setup>
                <module>VivasIndustries_SmsNotification</module>
            </setup>
            <connection>
                 <use>core_setup</use>
             </connection>
        </smsnotification_setup>
        <smsnotification_read>
            <connection>
                <use>core_read</use>
            </connection>
        </smsnotification_read>
        <smsnotification_write>
            <connection>
                <use>core_write</use>
            </connection>
        </smsnotification_write>
    </resources>    
    <events>
    <checkout_type_onepage_save_order_after> <!-- identifier of the event we want to catch -->
        <observers>
          <checkout_type_onepage_save_order_after_smsprice_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>smsnotification/newordertotalobserver</class> <!-- observers class alias -->
            <method>saveSmspriceTotal</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </checkout_type_onepage_save_order_after_smsprice_handler>
        </observers>
      </checkout_type_onepage_save_order_after>  
    <checkout_type_multishipping_create_orders_single> <!-- identifier of the event we want to catch -->
        <observers>     
          <checkout_type_multishipping_create_orders_single_smsprice_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>smsnotification/newordertotalobserver</class> <!-- observers class alias -->
            <method>saveSmspriceTotalForMultishipping</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </checkout_type_multishipping_create_orders_single_smsprice_handler>      
        </observers>
      </checkout_type_multishipping_create_orders_single>     
        <sales_order_save_after>
            <observers>
                <vivasindustries_smsnotification>
                    <class>smsnotification/observer</class>
                    <method>orderSaved</method>
                </vivasindustries_smsnotification>
            </observers>
        </sales_order_save_after>
    </events>
     <sales>
        <quote>
            <totals>                
                <smsprice_total>
                    <class>smsnotification/quote_address_total_smsprice</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping</after>
                    <before>grand_total</before>
                </smsprice_total> 
            </totals>
        </quote>
            <order_invoice>
                <totals>                
                <smsprice_total>
                    <class>smsnotification/order_invoice_total_smsprice</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping</after>
                    <before>grand_total</before>
                </smsprice_total> 
                </totals>
            </order_invoice>
            <order_creditmemo>
                <totals>                
                <smsprice_total>
                    <class>percentpayment/order_creditmemo_total_smsprice</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping</after>
                    <before>grand_total</before>
                </smsprice_total> 
                </totals>
            </order_creditmemo>
    </sales>    
    <helpers>
        <smsnotification>
            <class>VivasIndustries_SmsNotification_Helper</class>
        </smsnotification>
    </helpers>
    <blocks>
        <smsnotification>
             <class>VivasIndustries_SmsNotification_Block</class>
        </smsnotification>
    </blocks>
  </global>
  <adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <vivas>
                                        <title>Vivas - All</title>
                                    </vivas>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
    <layout>
        <updates>
            <smsnotification>
                <file>smsnotification.xml</file>
            </smsnotification>
        </updates>
    </layout>   
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <default>
    <vivas>
        <smspricegroup>                
            <smsprice_name>SMS Notification</smsprice_name>
            <smsprice_fee>0.5</smsprice_fee>            
        </smspricegroup>      
    </vivas>
    </default>
</config>  

Here is what I have in: /app/code/community/VivasIndustries/SmsNotification/sql/smsnotification_setup/install-1.0.0.php:

<?php
$installer=$this;
$installer->startSetup();

$installer->addAttribute("quote_address", "smsprice_total", array("type"=>"varchar"));
$installer->addAttribute("order", "smsprice_total", array("type"=>"varchar"));

$installer->run("
CREATE TABLE IF NOT EXISTS `VivasIndustries_SmsNotification` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `state` varchar(500) NOT NULL,
  `smstext` varchar(500) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `VivasIndustries_SmsHistory` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `receiver` varchar(500) NOT NULL,
  `phone` varchar(500) NOT NULL,
  `email` varchar(500) NOT NULL,
  `smstext` text NOT NULL,
  `date` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

    ");
$installer->endSetup();
?>

It seems that this installer is not creating a new table in the Magento's DB, also it seems it is not adding atributes like smsprice_total.

Can you help me out resolve this problem?

Where is my mistake?

1
  • check whether you have enabled the cache. If enabled, turn off the cache and re-try to install the module.
    – Sukeshini
    Mar 9, 2015 at 3:49

2 Answers 2

1

To re-install a module that creates tables or makes other changes to the database you need to check core_resource for the entry corresponding to your module name. If the key is in there then delete it.

Then clear everything below var/cache and var/session (if on a dev site).

If you then go to the homepage on the frontend the module will reinstall.

This should be evidenced in the core_resource database table. If it is not then you have another problem.

5
  • I am not asking how to reinstall a module... I'm asking why it is not creating the MySQL table on a fresh install! Mar 9, 2015 at 14:43
  • Did you look at core_resource? Does it say your module is installed in there? Mar 9, 2015 at 14:49
  • How i can check that ? Mar 9, 2015 at 16:36
  • Go into phpmyadmin Mar 9, 2015 at 17:23
  • Or even better, get a real mysql client :P
    – user2045
    Mar 10, 2015 at 22:19
0

There are a few things that could of happened here.

  • Your extension configuration could be wrong and your setup script was never called even though magento is aware of your extension.
  • Your extension was installed and the setup scripts ran but they did not update the database as you expected.
  • Magento found your extension and the setup configuration, but couldn't find the setup script as the file is in the wrong location
  • Magento has your installed extensions cached in config so is still not aware your new extension exists and has therefore not run the script.

In magento the core_resource table is what takes care of keeping track of what version an extension is up to. If your extension setups have already run there would be an entry in the core_resource table stating what version your extension is up too, in your case something like smsnotification, 1.0.0, 1.0.0.

Look for that row in your core_resource table. If it already exists in your database it means that your extension setup has already run, if this is the case maybe your setup script is in the wrong location or your script is not working. If it does not exist either your setups haven't run yet or your extension is misconfigured and magento never attempted to run your setups.

Things to try

  • Clear your magento cache, it might be all thats required
  • If the core_resource row for your extension already exists remove it. Magento will try to run your scripts again.
  • If that didn't work, log to a file in your setup script and remove the core_resource row again. If your log is written it means that your getting into your setup script, perhaps its not doing what it is supposed to.

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.