Magento Forum

   
créating it’s own eav model:  Can’t retrieve entity config
 
Matthieu MARY
Member
 
Total Posts:  33
Joined:  2008-08-28
France
 

hello everybody,

I’m trying to extends the catalogrule model for magento 1.1.4 to use the eav model by using a 1/1 link between original catalogrule table and my catalogrule eav model (catalogrule_entity, catalogrule_entity_varchar, catalogrule_entity_decimal, catalogrule_entity_text, catalogrule_entity_int, ...)

For that I have:
- create my module Namespace_Offers loaded and visible in back office

- module have the following directory tree:

app/
   
code/
      
local/
        Namespace/
                       
Offers/
                                   
etc/
                                          
config.xml
                                    Model
/
                                             
Entity/
                                                      
Offers/
                                                                 
Collection.php
                                                      Offers
.php
                                              Offers
/
                                                       
Setup.php
                                              Offers
.php   
                                     sql
/
                                          
offers_setup/
                                                  
mysql4-install-0.1.0.php

- my module configuration file is the following one:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <!-- 
turn on our modulerequired for install support -->
    <
modules>
        <
Namespace_Offers>
            <
version>0.1.</version>
            <
depends>
                <
module>Mage_Eav</module>
            </
depends>
        </
Namespace_Offers>
    </
modules>
    <global>
        <
models>
            <
offers>
                <class>
Namespace_Offers_Model</class>
                <
resourceModel>offers_entity</resourceModel>
            </
offers>
            <
offers_entity>
                <class>
Namespace_Offers_Model_Entity</class>
                <
entities>
                       <
rule_entity><table>catalogrule_entity</table></rule_entity>
                       <
rule_attribute_varchar><table>catalogrule_varchar</table></rule_attribute_varchar>
                       <
rule_attribute_int><table>catalogrule_int</table></rule_attribute_int>
                       <
rule_attribute_decimal><table>catalogrule_decimal</table></rule_attribute_decimal>
                       <
rule_attribute_text><table>catalogrule_text</table></rule_attribute_text>
                       <
rule_attribute_datetime><table>catalogrule_datetime</table></rule_attribute_datetime>
                </
entities>
            </
offers_entity>    
        </
models>
        <
resources>
            <
offers_setup>
                <
setup>
                    <
module>Namespace_Offers</module>
                    <class>
Namespace_Offers_Model_Offers_Setup</class>
                </
setup>
                <
connection>
                    <use>
core_setup</use>
                </
connection>
            </
offers_setup>
            <
offers_write>
                <
connection>
                    <use>
core_write</use>
                </
connection>
            </
offers_write>
            <
offers_read>
                <
connection>
                    <use>
core_read</use>
                </
connection>
            </
offers_read>
        </
resources>
    </global>
</
config>

loading data throught setup works fine

my Namespace_Offers_Model_Offers class have the following code:

<?php
require_once 'Mage/CatalogRule/Model/Rule.php';
class 
Namespace_Offers_Model_Offers extends Mage_CatalogRule_Model_Rule
{

    
protected $_attributes null;
    private 
$_rule null;

    protected function 
_construct ()
    
{
        parent
::_construct();
        
$this->_init('catalogrule/rule');
    
}
    
    
public function loadByAttribute ($attribute$value)
    
{
        $collection 
$this->getOffersCollection()->addAttributeToFilter($attribute$value)->setPage(11);
        foreach (
$collection as $object{
            
return $object;
        
}
        
return false;
    
}

    
public function getOffersCollection ()
    
{
        
return Mage::getResourceModel('offers/offers_collection');
    
}
}
- class Namespace_Offers_Model_Entity_Offers_Collection have the following content:
class Namespace_Offers_Model_Entity_Offers_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
{

    
protected function _construct ()
    
{
        $this
->_init('offers/offers');
    
}

    
public function onlyActive ()
    
{
        $this
->addAttributeToFilter('is_active'1);
        return 
$this;
    
}
}
but when I try to fetch a required value in database for an attribute registered in eav_attribute, and link to my entity_type,
$offer = new Namespace_Offers_Model_Offers();
$offer->loadByAttribute('my_attribute'1);
I have each time the following exception in /data/magdev6/app/Mage.php (375)

Can’t retrieve entity config: eav/catalogrule_entity

what does it mean? here’s the content of my record in eav_entity_type :

- entity_type_code: offers
- entity_model: offer/offer
- entity_table: catalogrule_entity
all others values are defaults.

is there something specific to make when make it’s own model?
here’s the first lines of the exception:
does someone have an idea, your help will be appreciated.
best regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pedro Bernardo
Jr. Member
 
Total Posts:  11
Joined:  2008-09-23
 

Hi,

Did you found the problem.

I have the code like you in a module i’m creating and i have the same problem

 
Magento Community Magento Community
Magento Community
Magento Community
 
Matthieu MARY
Member
 
Total Posts:  33
Joined:  2008-08-28
France
 

hello,

yes my code works fine, but I don’t remember exactly why I have done to do that.
Make sure that yours record in eav_entity_type is fine (model, table_prefix, entity_table).
And make sure to load your model object throught Mage::getModel instead of using new.
Hope this can help you.
Best regards

Matthieu

 
Magento Community Magento Community
Magento Community
Magento Community
 
yogendrabmishra
Member
 
Total Posts:  34
Joined:  2008-01-22
Bangalore
 

Hello Mimic,

Can you let me know that what values you exactly put in your row. I am facing the same problem. I can see the array of my all attributes, but its all null and not collecting value, may be your suggestion will work for me.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Beena K M
Member
 
Total Posts:  50
Joined:  2009-01-06
Cochin, Kerala, India
 

This may be becuase of you forgot to define your new entity table in config.xml file in your custom module inside <models> tag

<yourcustommodule_mysql4>
<class>Yournamespace_modulename_Model_Mysql4</class>
<entities>

<catalogrule_entity><table>your database table name</table></catalogrule_entity>
</entities>
</yourcustommodule_mysql4>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Portal WebGP
Jr. Member
 
Total Posts:  18
Joined:  2010-03-12
 

You can find a great tutorial here (http://alanstorm.com/magento_advanced_orm_entity_attribute_value_part_1).

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top