Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Magento
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===PHP=== * follows [[PHP#PHP_Standard_Recommendation_.28PSR.29|PSR 1 to 4]] ====Patterns==== =====Factory===== * [https://devdocs.magento.com/guides/v2.2/extension-dev-guide/factories.html official documentation] Factories are strongly linked to [[#Repository|Repositories]]. Repositories are part of the Service Contracts (they are implementations of interfaces in Api), this means they are meant as public interface to other modules. Repositories do not come with methods to create a new entity, so in that case you will need a factory. But use the factory for the interface, such as Magento\Catalog\Api\Data\ProductInterfaceFactory - it will create the right implementation based on DI configuration. *create() $c = $this->objectManager->get('\Magento\Customer\Api\Data\CustomerInterfaceFactory')->create(); // or $c = $this->customerInterfaceFactory->create(); // or $c = $this->objectManager->create(\Magento\Customer\Api\Data\CustomerInterface::class); * load() $object = $this->customerRepositoryInterface->get("name"); // this is best but also possible $object = $this->myFactory->create(); $object->load($myId); * save() $c = $this->customerRepositoryInterface->save($c); // this is best, but also possible $object->setData('something', 'somethingDifferent')->save(); =====Repository===== A repository object is responsible for reading and writing your object information to an object store (i.e. a database, the file system, physical memory, etc.). Naming convention is <Entity>RepositoryInterface. Methods are: * save(../Api/Data/<Entity>Interface $object2Save) * get() * getById() * getList() * delete() * deleteById() * load $repo = $this->myRepository(); $object = $repo->getById($myId); * save $object->setData('something', 'somethingDifferent'); $repo->save($object);
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width