Need documentation for Magento Models (Mage::getModel()) - magento

I've read Alan Storm's guide here on Magento ORM principles and how to access the data. I'm writing a plugin to export data from magento.
Question
Where do I find documentation for the different types of models available in Magento?
For example,
Mage::getModel("catalog/categories");
What are the other allowable models in getModel?.
There's some information in the API documentation, like product.list, and if I were to guess, then I would say that this some how translates over to the getModel call, but i'm not sure how. Can anyone link me? google searches for "getModel documentation" and
"Magento models" produce no relevant results.
Here are the links I have looked at:
DB Diagram
SO Question
getModel and getData methods
Alan Storm's guide
So far, Alan's stuff has been the most helpful.
Help me, #Alan Storm :)

You should dig into code. Using getModel you're able to get an instance of each class of each module which is located in Models directories. In catalog/product_option_a_b_c expression, the fitst part (catalog) references to module and the second part references to Product/Option/A/B/C.php file in the Models directory of catalog module. So if you want to get an instance of Mage_Sales_Model_Quote_Address class, you need this: Mage::getModel('sales/quote_address')

you probably know that magento is comprised of several MVC modules so according to its standard each module has a Model directory. getModel() uses this structure to find which model you want to load. basically the call is in this format:
module/path_to_the_name_of_model_including_the_model_file_name
remember not to include model directory and use underscore to separate directories. also the name of the directories are in lowercase however in reality they start with uppercase.

Related

laravel 5.4, where to put controllers, models, views and routes?

Having gone through numerous laravel tutorials and examples, i have seen source code with controllers, models and views in very different directories.
The question is, where should they go, and how does the system (which presumably requires convention) work if they are put in a different place?
E.g. the official laravel quick-start project puts them in:
app/Http/Controllers/xxxControler.php
app/Http/routes.php
resources/views/xxx.blade.php
Cant find where it has put the models.
However, the simple laravel crud master tutorial puts them here:
app/controllers/xxxControler.php
app/models/xxx.php
app/routes.php
app/views/xxx/create.blade.php
app/views/xxx/edit.blade.php
Controllers
If you look in the 5.4 documentation here it says controllers should go in app/Http/Controllers.
If this is the case, how did the latter example work (as the controller files are in the "wrong" dir, and I assume that laravel, like grails, relies on convention over configuration)?
The latter example directories seem much more logical than the official place, as a controller has nothing to do with Http - its part of the app logic.
Models
The official documentation mentions that "models typically live in the app directory". This implies they can be put put in app/models, which is good.
views
Unfortunately, the official documentation says they have to go in resources/views. Again, this would be far more logical to have views, controllers and models all being together as sub directories of app, as per the second example above. Is it possible, and advisable, to use this logical, but unofficial structure? as a beginner, I have difficulty in finding the models, views and controllers as they are put in 3 different directory paths with no obvious logic.
routes
The official documentation says that routes should go in routes/web.php. I have not found an example project using this convention - I have seen them in app/routes.php, and app/http/routes.php. Assuming its ok to put them in random places under app, how does one configure where the routes definition files go?
For Laravel version ^5.4
Controllers should be in this directory
app/Http/Controllers/xxxController.php
Models should be in this directory
app/xxx.php
Views should be in this directory
resources/views/xxx.blade.php
Routes should be in this directory
routes/web.php // for web routes
routes/api.php // for api routes
These are all recommended places to put controllers, models, views and routes. You are free to modify everything of course!
Older versions of Laravel have different places for Controllers, Models, Views and Routes. Check the documentation where they should be.
The thing is that you must recognize the Laravel version because Laravel went through many changes between years 2011 and 2016...
That link in your question for example is from year 2013 which is very old.
And I strongly recommend you to follow the Laracasts tutorials at laracasts.com

Magento Module config.xml

I'm learning Magento extension developing, Already understand enough to start with PHP OOP, MVC and Zend framework.
Now i need to understand the concept of config.xml file in the /etc folder in my module, Already found table explain each entry like what is ,, .. etc.
But i need to understand in more details how it works.
An example of what in my mind is to add for example (new payment method) it will be easier to explain with example.
Already created my controllers, models, blocks .. etc folders.
Anybody can explain it in details or provide me with resources?
I found this quite useful as a starting point
http://coding.smashingmagazine.com/2012/03/01/basics-creating-magento-module/
I'm still learning module development but the module works

Magento custom model override

I'm new to Magento, so forgive my lack of knowledge. I am following a tutorial to integrate the contacts in Magento and import it to SugarCRM. The tutorial changes the core functions of Magento, but I would like to write a module and leave the core intact. I can easily find information about overriding controllers, models, helper, etc. But I have a question.
Imagining, for example, each time a user registers on my website, his contact information is exported to SugarCRM. In the save contact phase, in my module I know that I can write a specific code and tell that it would need to be run after or before some specific core-functions of Magento are done to save the contacts.What I really don't understand is, how will Magento know that I have a module that will perform me certain actions when I'm creating a new account?
The way magento handle this is by using events/observers. For instance, if you needed to send order information to another system after an order has been placed, you could create a custom module which observe sales_order_place_after.
Read more # http://codemagento.com/2011/04/observers-and-dispatching-events/
To get a list of events see https://magento.stackexchange.com/questions/153/where-can-i-find-a-complete-list-of-magento-events
For how to create an module with observer see https://stackoverflow.com/a/12696681/1191288

Magento adding set of attributes/properties to products

I need to add something similar to the Review system already available on Magento. I mean, I want to add a couple of texts, reviewing capacities and alike. It should have an administration side on the backend to be able to reject/accept/edit those texts. I still do not have all the things clear so I want to ask before I embark into a wrong/closed path.
Should I reuse the existing code by copying core files into local and modifying at will?
Or should I add my own tables and link to EAV model using product ID?
On this SO question the accepted answer posts a code on how to add a new custom attribute to all products. I could use this but I would still need to add the reviews part.
I've searched for a similar functionality but can not find anything.

Magento - local controller is not working

I have a question regarding Magento's local directory.
I am trying to override a core controller - Mage/Contacts/controllers/IndexController.php.
So I copied IndexController.php to /app/local/Mage/Contacts/controllers/
but Magento is still using core file. I can confirm it because I see 404 page when I rename Mage/Contacts/controllers/IndexController.php to IndexController.php_.
Please advise me.
Thanks!
Copying a controller into the app/code/local path doesn't work unfortunately due to Magento's autoload architecture. It does work with Blocks, Models and other objects, but not controllers.
There is a detailed walkthrough of how to override a controller on the wiki. And a blog post by #prattski
Try following those, then come back with any specific questions.
HTH,
JD

Resources