Answer the question
In order to leave comments, you need to log in
How to use DDD approach to catalog implementation?
Hey!
On a small pet project, I'm learning the tricks of DDD. So, there is a certain analogue of a store: a catalog, a product page, a basket, etc. Reflecting, I came to the conclusion that the concept of "Goods" in the system clearly has at least two meanings. In the context of a catalog, this is more of a representative model - title, description, pictures, etc. In the context of the purchase, these are already prices, all sorts of loyalty programs, discounts, and so on. By and large, the first context is generally more like a regular blog with a set of pages. Therefore, I decided to single out two independent contexts (Bounded Context):
1. Catalog
2. Shop
In both contexts there is the concept of Product, implemented by the class of the same name
namespace Acme\Catalog;
class Product {
private $id; // Это идентификатор продукта в контексте каталога
private $name;
private $description;
private $poster;
// ...
}
namespace Acme\Shop;
class Product {
private $id; // Это идентификатор продукта в контексте продаж
private $sku;
private $price;
// ...
}
namespace Acme\Shop
class ShopService {
public function fromCatalogProduct($id) {
// тут строим идентификатор на основе каталожного
}
}
class ProductPageController
{
// ...
public function pageAction($id) {
$catalogProduct = $catalogRepo->get($id);
$shopId = $shopService->fromCatalogProduct($id);
$shopProduct = $shopRepo->get($shopId);
// Дальше рендерим страницу, опираясь на оба контекста
}
}
Answer the question
In order to leave comments, you need to log in
The DDD domain model is purely for organizing business logic, and concepts such as Aggregate, Entity, Value Object serve exclusively these purposes.
To display data in a graphical interface, you can, or even need to, create a second model for reading.
Those. the result should be two models, in many ways they will duplicate themselves in simple areas.
The context must be one.
The essence of the goods must be one.
In your case, Shop\Product - this will be a commodity item, but it must be associated with Catalog\Product so as not to duplicate entities. You just need to use an aggregate that is either from Product or from some other entity (that is, a service related to the entity), such as ProdcutCatalog, PriceList, Reporter, or something else like that.
For example, the service will have the PriceList.GetPriceList(from, to) method, and it already makes the necessary aggregate with queries, but when building the aggregate, the method will access tables related to the Product entity
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question