[TYPO3-mvc] Where to integrate logic for dependencies among objects - model or repository?

Jochen Rau jochen.rau at typoplanet.de
Tue Dec 22 23:40:15 CET 2009


Hi.

schrieb Franz Koch:
> The very same article can be part of different catalogs and can have
> different prices in each of the catalogs. The price can also vary based
> on the country the visitor comes from. So one article will have several
> prices assigned, but only one price is about to be displayed, based on
> the conditions that get matched (currently selected catalog, country of
> visitor). My question is now, where to put this logic and how to build
> up the models correctly for this.
>
>
> Currently I have this:
>
> Tx_..._article (entity, aggregate root)
> $title (@var string)
> $articlenumber (@var string)
> $xselling (@var
> Tx_Extbase_Persistence_ObjectStorage<Tx_..._Domain_Model_article>
>
>
> Tx_..._price (valueObject)
> $value (@var float)
> $article (@var Tx_..._Domain_Model_article)
> $country (@var string) #ISO-code and related to static_info_tables
>
>
>
> I created the models using the extbase_kickstarter, but the result looks
> wrong to me - I think I messed up the relations. My article objects
> somehow needs a price property I think, containing the correct price
> object. But where does it come from and at which stage does it have to
> be fetched?

I wouldn't fetch it from a Repository. You don't have to persist it for 
later reuse, because it depends on many factors and might change 
rapidly. I would determine the price on the fly calling a 
Tx_..._Domain_Service_PriceCalculationService->calculatePriceFor($article, 
$country). As the article could be aware of the catalog it is related 
to, you have all the information in place.

If you implement a "price" property inside your Article you could let 
the getPrice() call the service. But you can also decide to handle 
prices separate from articles.

> I assume that extbase automatically would fetch all price objects and
> assign it to the article if I built the dependency the other way around,
> but how would I tell extbase then to take the proper conditions into
> account?

That's obsolete if the price is calculated on the fly.

> If I would fetch the prices by hand, which repository would I have to
> use: a) extend the articleRepository or b) create a priceRepository? And
> how would I hand the values for the conditions over to the repository? I
> could write a method "findPriceByCategoryAndCountry" and hand the
> parameters over to it, but what if another condition comes into place
> (actually I simplified it and have two more conditions, so 4 in total)?
> I can't rewrite all the code only because one condition got added.

Same here, I think.

> Please point me to the right direction - all this DDD stuff new to me.

You're welcome.

Jochen

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list