Skip to content

The Concept of Default Source and Domain Driven Design

Ievgen Shakhsuvarov edited this page Jul 16, 2019 · 17 revisions

Installing Magento 2 with Multi-Source Inventory on board should introduce neither performance nor usability difficulties for Magento Merchants and Administrators.

That's why we still should support existing admin UI for product configuration where there is the only field Quantity, which does not expose a knowledge about physical Sources used under the hood. The main goal is to prevent from overwhelming Admin UI with different Source options for those merchants who have the only Source and not going to use Multi-Source possibilities.

But introducing the Default as a Role for Sources, which leads to adding isDefault attribute to SourceInterface, will violate Domain Driven Design (DDD) principles because there is no such Business Concept in Inventory Domain as Default Source.

The Default Source is a part of Catalog Bounded Context, but not Inventory One. It is Magento Catalog wants to add a "special case" for installations with single source/stock to simplify Admin UI for those merchants. Thus, Inventory bounded context (read Inventory module and APIs declared as a part of its Service Contracts) should be agnostic to the Default Role Concept.

Thus, what we end up with.

As Inventory can't add awareness about Default Role of the Source. This business invariant should be added to the Catalog bounded context (but not to the Catalog module as it's demanded to prevent a formation of God-modules). Thus, it's recommended to introduce a dedicated module - InventoryCatalog where this logic would be placed. Doing so - both Domain Logic and Modularity would be respected.

There are two possible ways of adding this Business Rule in Magento 2:

  1. Adding Extension Attribute (isDefault) for SourceInterface from InventoryCatalog module.
  2. Introduce dedicated Services getDefaultSource() and setDefaultSource(int $sourceId)

It's proposed to go with option 2 to make APIs more operation/command oriented.

Story Tasks on GitHub

GitHub Story Label for current Story is "Default Source Concept" Thus, you can find all the tickets related to the story following Story Label

MSI Documentation:

  1. Technical Vision. Catalog Inventory
  2. Installation Guide
  3. List of Inventory APIs and their legacy analogs
  4. MSI Roadmap
  5. Known Issues in Order Lifecycle
  6. MSI User Guide
  7. DevDocs Documentation
  8. User Stories
  9. User Scenarios:
  10. Technical Designs:
  11. Admin UI
  12. MFTF Extension Tests
  13. Weekly MSI Demos
  14. Tutorials
Clone this wiki locally