0

See the edit please

I'm doing this:

                /* @var $attributeModel Mage_Catalog_Model_Entity_Attribute */
                $attributeModel = Mage::getModel('catalog/entity_attribute');
                $attributeModel->setEntityTypeId($entityTypeId);
                $attributeModel->setAttributeCode($propName);
                $attributeModel->setBackendType('varchar');
                $attributeModel->setName($propName);

                $description = $this->attributes[$propName];
                $attributeModel->setFrontendLabel($description);

                $attributeModel->save();

and I'm getting this nasty error whose origin I can't figure out:

Fatal error: Call to undefined method Mage_Eav_Model_Resource_Entity_Attribute::isUsedBySuperProducts() in /var/www/html/app/code/core/Mage/Catalog/Model/Entity/Attribute.php on line 86

So apparently, this function does not exist. Well, I saw it and my IDE even found it with code completion, so it definitely exists. What could this be?

Maybe I'm missing something while creating the attribute? Can't guess what though, I'm really stuck...

EDIT: Okay, I was using the model catalog/entity_attribute, but I'm supposed to use catalog/resource_eav_attribute, then it works.

Well, why do I have to use a resource there, though? Shouldn't a model be able to create the attribute and use the resource rather than me using the resource directly? Is it me or is this not really consequent behavior? I don't get it

1 Answer 1

1

isUsedBySuperProducts is a method of Mage_Catalog_Model_Resource_Attribute. Methods that interact with data in Magento are in resource models. So, even if you had model methods to create attributes, it really invokes resource model methods, so why not just use it directly? That's what the installation scripts do.

2
  • Well why do models exist then if you can just as well use the resource instead?
    – Yorrd
    Commented Mar 15, 2015 at 8:39
  • 1
    It's just the software pattern of the platform. Why have helper, blocks, models, etc. when you can just have them all in one directory and call them something else? Alan Storm wrote a summary of the differences here: stackoverflow.com/questions/13074867/…
    – laketuna
    Commented Mar 15, 2015 at 17:10

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.