0

I want to create a Model that could be called from another extension. The tutorials I've found so far are quite confusing and I couldn't get it to work.

What is the minimum I need to do to make a fully functional model?

I have setup a simple module.
config.xml with the content:

<?xml version="1.0"?>
<config>
    <modules>
        <Jurgis_Checkoutstep>
            <version>0.1.0</version>    
        </Jurgis_Checkoutstep>
    </modules>
    <frontend>
        <routers>
            <Checkoutstep>
                <use>standard</use>
                <args>
                    <module>Jurgis_Checkoutstep</module>
                    <frontName>Checkoutstep</frontName>
                </args>
            </Checkoutstep>
        </routers>
    </frontend>
</config>

Path: /app/code/local/Jurgis/Checkoutstep/etc/config.xml

Let's say I want to have a Model called deliverydate.php in:
app/code/local/Jurgis/Checkoutstep/Model

What do I need to add to config.xml and deliverydate.php (anywere else?) to create a working Model?

2

In your config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Jurgis_Checkoutstep>
            <version>0.1.0</version>    
        </Jurgis_Checkoutstep>
    </modules>
    ...
    <global>
        <models>
            <jurgis_checkoutstep>
                <class>Jurgis_Checkoutstep_Model</class>
            </jurgis_checkoutstep>
        </models>
    </global>
    ...
</config>

Then create PHP file app/code/local/Jurgis/Checkoutstep/Model/Deliverydate.php with your model.

When you need to call it you can use:

Mage::getModel('jurgis_checkoutstep/deliverydate');

or

Mage::getSingleton('jurgis_checkoutstep/deliverydate');

Depending if you need a new instance or a singleton model.

Your model class will look like this:

<?php
class Jurgis_Checkoutstep_Model_Deliverydate
{
...
// your methods here
...
}

There is no need to inerith from Mage_Core_Model_Abstract unless your are creating a datamodel representing a database object.

4
0

Check the below example ..

   <global>
    <!-- ... -->
    <models>
        <weblog>
            <class>Magentotutorial_Weblog_Model</class>
            <!--
            need to create our own resource, can't just
            use core_resource
            -->
            <resourceModel>weblog_resource</resourceModel>
        </weblog>
    </models>
    <!-- ... -->
</global>

The outer tag is your Group Name, which should match your module name. is the BASE name all Models in the weblog group will have, also calles Class Prefix. The tag indicates which Resource Model that weblog group Models should use. There's more on this below, but for now be content to know it's your Group Name, followed by a the literal string "resource".

Ref URL : http://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-5.html

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.