Magento: Adding a custom entity

2019-09-03 13:47发布

问题:

Im creating an extension that adds extra functionality to the review model. I've created a database table and I need to add it as an entity in the etc/config.xml file. In the review config.xml it creates entities with the following:

<models>
        <review>
            <class>Mage_Review_Model</class>
            <resourceModel>review_mysql4</resourceModel>
        </review>
        <review_mysql4>
            <class>Mage_Review_Model_Mysql4</class>
            <entities>
                <review>
                    <table>review</table>
                </review>
                <review_detail>
                    <table>review_detail</table>
                </review_detail>
                <review_status>
                    <table>review_status</table>
                </review_status>
                <review_entity>
                    <table>review_entity</table>
                </review_entity>
                <review_aggregate>
                    <table>review_entity_summary</table>
                </review_aggregate>
                <review_store>
                    <table>review_store</table>
                </review_store>
                <review_parent>
                    <table>review_parent</table>
                </review_parent>
            </entities>
        </review_mysql4>
    </models>

And this is what I have so far (excluding the entity)

<config>
<modules>
    <XXX_CustomerReview>
        <version>0.1</version>
    </XXX_CustomerReview>
</modules>
<global>
    <models>
        <review_mysql4>
            <rewrite>
                <review>XXX_CustomerReview_Model_Mysql4_Review</review>
            </rewrite>
        </review_mysql4>
    </models>
</global>

I can't get my head round how I do this, any help would be grateful.

回答1:

There is quite a bit of work involved, and you can look at this video, especially from half way onward, where Ivan shows how he created the data definitions and and configurations for this.

http://vimeo.com/35937480

This should give you a better understanding of this.

More explanation can be found here:

http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-7-advanced-orm-entity-attribute-value



标签: magento