More

    Magento Installation Scripts – Part 4: EAV Tables (Cool Ryan)


    In Part 3, we added a new table to the database with our install script.  Now let’s create an EAV table setup so we can leverage Magento’s EAV data architecture setup.
    If we are going to setup EAV tables, we will need a special kind of Setup class for our installation.  So, we need to tell Magento to use a class we specify.  For that, we will add a node to our config.xml.

    The <class>  node lets Magento know that this is what class we want to leverage in our install files. For this install file, we are going to use Mage_Eav_Model_Entity_Setup . So let’s start building our new entity.

    OK, so what in the world just happened?  Let’s go through it.

    What this did was create a new row in the eav_entity_type table.  Now Magento knows that you have a new EAV table set to work with. The ‘entity_model’ is the model you will be working with using the standard modelAbstract Factory Pattern.  The ‘table’ reference is the table you designated in the config.xml file. (See Part 3 for reference).

    What this did was create all of your tables for you.  That’s right!  All of your tables in one handy little line! It creates:

    • content (base table)
    • content_char
    • content_datetime
    • content_decimal
    • content_int
    • content_text
    • content_varchar

    Now you have your entity tables ready to go!  Many people think that creating EAV is tough, but Magento does all the heavy lifting for you.  While this isn’t the only part that goes into creating full fledged EAV models, the next lesson goes into creating attributes.

    Overview : Magento Installation Scripts (Cool Ryan) 
    Previous :Part 3: Installing New Tables
    Next : Part 5: Attributes

    Post from coolryan.com

    Recent Articles

    spot_img

    Related Stories

    Stay on op - Ge the daily news in your inbox