Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: What are the empty EAV setup classes for?

Tags:

php

magento

There are lots of descendants of Mage_Eav_Model_Entity_Setup for example

class Mage_Checkout_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
}

But all of them are empty.

What is the use of having all these empty classes?

Is it just for the sake of extensibiliy and to keep common functions that are shared in different setup scripts of the same module?

I was thinking there might be some kind of module autodetection triggered by these custom classes, but could not find any hints into this direction).

(Based on Magento Certification Study Guide: What are the advantages of using a custom setup class for manipulating EAV attributes in a custom module).

like image 507
Alex Avatar asked Jan 17 '23 00:01

Alex


1 Answers

First, you need to understand that Magento organizes it's code into modules. The idea behind a module is to both help and force a developer to write their code in such a way that their code doesn't interfere with other system code.

Second, when a module needs to create persistant data in the Magento database, you create a setup resource (self-link). A setup resource is an installer script that has access to special functions/methods via its parent class. These special functions/methods help the developer create and populate tables in the database for their data structures. Many of these methods can be found on the Mage_Eav_Model_Entity_Setup class.

When a developer creates a setup resource for their own module, they create a new class. By creating a new class they ensure that any special methods their setup resources need will have a place to live. The Mage_Checkout_Model_Resource_Setup class is the Mage_Checkout module's setup resource class. It just so happens that this module didn't need extra methods. Earlier versions of Magento forced (at least, I believe they did) module developers to create their own setup resource classes if they wanted to use the setup resource feature. This was done because, as mentioned in paragraph one, Magento's module system is there to help ensure code from Module A doesn't interfere with Module B.

like image 88
Alan Storm Avatar answered Jan 27 '23 20:01

Alan Storm