• Vendor/ModuleName/Model/TestModel.php
  • Vendor/ModuleName/Model/Data/TestModel.php
  • Vendor/ModuleName/Model/TestModelRepository.php

Interfaces are already created.

The Data Model contains for eg. these methods:

public function getFirstname() {};
public function getLastname() {};

the regular Model contains:

public function getName() {
    return $this->getDataModel()->getFirstname() . ' ' . $this->getDataModel()->getLastname();

The new Magento service contracts architecture recommend to seperate entity information methods (from data model) and "action" methods (regular model). The repository return an instance of data model, so how can i call the getName() method from regular model ? Should i create a new feactory for the regular model and add the data model data?

Magento 2.2.6

Maybe someone has a good example for me?

lots of thanks


Model in custom Magento module need 3 files:

  • Model

  • Resource Model

  • Resource Model Collection

About the Factory Object you don't need to create it, Magento do it automatically.

in Magento, the Factory class is composed in : name of Model class + "Factory" word.

Exemple : model class name is : Vendor\Module\Model\Test, the Factory class will be : Vendor\Module\Model\TestFactory

When Magento find a class name that ends in the "Factory" word, it automatically generate this Factory class in the var/generation.

| improve this answer | |
  • 1
    thanks, that's clear and wasn't my question. – sodiummd Oct 26 '18 at 6:19

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.