0

I created custom eav type:

/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer = $this;

$installer->startSetup();

$installer->addEntityType('av_photo_type', array(
    'entity_model' => 'av_photo/eav_photo'
));

$installer->addAttribute('av_photo_type', 'name', array(
    'label'        => 'Type Name'
));

$installer->addAttribute('av_photo_type', 'code', array(
    'label'         => 'Unique Code',
    'unique'        => 1,
    'note'          => 'For internal using'
));

$installer->addAttribute('av_photo_type', 'order', array(
    'label'         => 'Order'
));

$installer->addAttribute('av_photo_type', 'active', array(
    'label'         => 'Active',
    'type'          => 'int',
    'input'          => 'boolean',
));

I've created file /model/eav/Photo.php:

class Company_Photo_Model_Eav_Photo extends Mage_Eav_Model_Entity
{
    public function __construct()
    {
        $resource = Mage::getSingleton('core/resource');
        $this->setType('av_photo_type')->setConnection(
            $resource->getConnection('sales_read'),
            $resource->getConnection('sales_write')
        );
    }
}

I would like to get collection by type "av_photo_type" now. I should create resource file to get collection but I haven't custom tables. Magento eav module hasn't resource model for eav_entity table. How to get eav_entity collection then?

1 Answer 1

0

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

$installer->createEntityTables(
    $this->getTable('complexworld/eavblogpost')
);

The article is really long...

If the tables exist, you can use a collection extended from EAV collection

class Magentotutorial_Complexworld_Model_Resource_Eavblogpost_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
{
    protected function _construct()
    {
        $this->_init('complexworld/eavblogpost');
    }
}
4
  • I mean how to do that using only mage class without extending course I'm using native functionality.
    – Anthony
    Commented Dec 3, 2013 at 20:51
  • I don't understand Commented Dec 3, 2013 at 22:53
  • Your way you described is correct, but you create custom class Magentotutorial_Complexworld_Model_Resource_Eavblogpost_Collection. I would like to get collection using only smth like Mage_Eav_Model_Entity_Collection, but there are not such class. I would not create custom classes.
    – Anthony
    Commented Dec 4, 2013 at 0:11
  • You have a custom entity, you create a custom class, that's the magento way. Even if the class only defined its main_table and the primary key column. Commented Dec 4, 2013 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.