Magento – Fatal error: Undefined class constant ‘ENTITY’

product-attribute

I'm doing a module with a new type of product using a helper/model for virtual product, and inserting a new attribute via SQL setup (in Module …)

My helper model:

class ItepCompany_Incomm_Model_Product_Virtual
    extends Mage_Catalog_Model_Product_Type_Virtual
{
}

My pro mysql-install-0.1.0.php code is:

<?php
$this->startSetup();
$this->addAttribute(ItepCompany_Incomm_Model_Product_Virtual::ENTITY, 'terms_of_use', array(
    'group'         => 'General',
    'input'         => 'textarea',
    'type'          => 'text',
    'sort_order' => 4,
    'label'         => 'Terms of use',
    'backend'       => '',
    'visible'       => true,
    'required'      => true,
    'wysiwyg_enabled' => true,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$this->endSetup();

Only when accessing the admin panel of the error:

Fatal error: Undefined class constant 'ENTITY' … \ sql \ add_product_attribute \ MySQL4-install-0.1.0.php on line 3

Did not generate anything in the log, which caused the problem?

Best Answer

ItepCompany_Incomm_Model_Product_Virtual::ENTITY 

you are trying to get the constant that are not define in your class.

Mage_Catalog_Model_Product::ENTITY

in this class ENTITY constant in define

const ENTITY                 = 'catalog_product';

so solution is that use the default product ENTITY or define in your custom class.