3
votes

I've been working on a module that needs some attributes added to the table of sales_orders. So i thought i will make an resource install script and add it to the XML. Well for me this wasn't a easy task. To be really honest I cant make it work. I have searched some hours to get the solution, but i haven't found it. The weird thing is that my module isnt at the core_resource table...

Well this is my XML. I'm a bit new to XML editing. Maybe i have made an error.

XML:

<config>
        <global>
       <modules>
        <Sendcloud_Magento>
            <version>0.2.0</version>
        </Sendcloud_Magento>
    </modules>
    <helpers>
          <magento>
            <class>Sendcloud_Magento_Helper</class>
        </magento>
        </helpers>
      <models>
        <magento>
               <class>Sendcloud_Magento_Model</class>
            <resourceModel>magento_resource</resourceModel>
        </magento>
          <magento_mysql4>
            <class>Sendcloud_Magento_Model_Mysql4</class>
        </magento_mysql4>
     </models>

    <resources>
<!-- ... -->
<magento_setup>
    <setup>
        <module>Sendcloud_Magento</module>
        <class>Sendcloud_Magento_Model_Resource_Mysql4_Setup</class>
    </setup>
    <connection>
        <use>core_setup</use>
    </connection>
</magento_setup>
<!-- ... -->
</resources>
</global>
 <admin>
    <routers>
        <magento>
            <use>admin</use>
            <args>
                <module>Sendcloud_Magento</module>
                <frontName>sendcloud</frontName>
            </args>
        </magento>
    </routers>
</admin>
<adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <sendcloud>
                                        <title>Sendcloud</title>
                                    </sendcloud>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>

    <layout>
        <updates>
            <magento>
                <file>magento.xml</file>
            </magento>
        </updates>
    </layout>
    <events>
        <core_block_abstract_prepare_layout_before>
            <observers>
                <magento_core_block_abstract_prepare_layout_before>
                    <class>Sendcloud_Magento_Model_Observer</class>
                    <method>addMassAction</method>
                </magento_core_block_abstract_prepare_layout_before>
            </observers>
        </core_block_abstract_prepare_layout_before>
    </events>
</adminhtml>

Ive put an installer script in my module. the path /local/Sendcloud/Magento/sql/magento_setup/mysql4-install-0.2.0.php

echo 'Running This Upgrade: '.get_class($this)."\n <br /> \n";
die("Exit for now");    

I have an model made in Sendcloud/Magento/Model/Resource/Mysql4/Setup.php

class Sendcloud_Magento_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
}

I hope some of you have an solution to my question.

Best regards and a happy new year,

Paul

2
I assume you have cleared the cache and have not run the script before, correct?boruch
I had the script running. i mean by running that one controller works. I also cleared the cache through the system and did it also manually.Paul Oostenrijk

2 Answers

1
votes

So now you need to update the version from 0.2.0 to 0.3.0, Try this

app\code\local\Sendcloud\Magento\etc\config.xml

<?xml version="3.0"?>
<config>
    <modules>
        <Sendcloud_Magento>
            <version>0.3.0</version>
        </Sendcloud_Magento>
    </modules>
    <frontend>
        <routers>
            <magento>
                <use>standard</use>
                <args>
                    <module>Sendcloud_Magento</module>
                    <frontName>magento</frontName>
                </args>
            </magento>
        </routers>
    </frontend>
    <global>
        <models>
            <magento>
                <class>Sendcloud_Magento_Model</class>
                <resourceModel>magento_mysql4</resourceModel>
            </magento>
            <magento_mysql4>
                <class>Sendcloud_Magento_Model_Mysql4</class>
                <entities>
                    <magento>
                        <table>magento</table>
                    </magento>
                </entities>
            </magento_mysql4>
        </models>
        <resources>
            <magento_setup>
                <setup>
                    <module>Sendcloud_Magento</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </magento_setup>
            <magento_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </magento_write>
            <magento_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </magento_read>
        </resources>
    </global>
</config>

app\code\local\Sendcloud\Magento\Model\Magento.php

class Sendcloud_Magento_Model_Magento extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('magento/magento');
    }
}

app\code\local\Sendcloud\Magento\Model\Mysql4\Magento.php

class Sendcloud_Magento_Model_Mysql4_Magento extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {    
        // Note that the magento_id refers to the key field in your database table.
        $this->_init('magento/magento', 'magento_id');
    }
}

app\code\local\Sendcloud\Magento\Model\Mysql4\Magento\Collection.php

class Sendcloud_Magento_Model_Mysql4_Magento_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
    {
        public function _construct()
        {
            parent::_construct();
            $this->_init('magento/magento');
        }
    }

app\code\local\Sendcloud\Magento\sql\magento_setup\mysql4-upgrade-0.2.0-0.3.0.php

$installer = $this;

$installer->startSetup();

$installer->addAttribute(
));

$installer->endSetup(); 

app\etc\modules\Sendcloud_Magento.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Sendcloud_Magento>
            <active>true</active>
            <codePool>local</codePool>
        </Sendcloud_Magento>
    </modules>
</config> 
0
votes

Did you activate your model by putting another XML file in app/etc/modules/ ?