1

I'm trying to fetch information of certain products, just not sure what function is available. I was wondering if there is a list of all magento 2 functions, like getName(), getPrice() etc.., then I can choose which I can use easily. thanks

1

Its unclear to me what you are asking for If you want to know what a product model functions are available to use you can refer to

<Magento Dir>/vendor/magento/module-catalog/Model/Product.php

See in Git

1

All Magento Models extend the \Magento\Framework\DataObject class. This class has the magic method __call implemented.

Long story short, it means that models don't necessarily have to have all the methods defined. Every column's getter and setter is already defined in the model. So for example, if there's a model Phone defined for a table my_phones having columns phone_id, model, and price, then the Phone class would have functions getPhoneId(), getModel(), getPrice(), setPhoneId($id), setModel($model), and setPrice($price) functions predefined, without us explicity defining it (notice the snake_case to CamelCase transformation while forming the method names).

This becomes more complicated when we deal with EAV models (like the Product model), since we don't know all the "columns" that it's fetching.

For an EAV collection, we can use the addFieldToSelect() method to add "columns" to retrieve.

And for models, we can always call the getData() method to fetch all the data values.

So to answer your question, no there isn't any list of methods, because even Magento doesn't know all the methods required, since the admin can add new attributes later on. Still to get all the columns fetched, we could do something like print_r(array_keys($product->getData())); to print all the columns in the screen, for that model

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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