[TYPO3-mvc] DataMapper: relations with custom constraint?
Franz Koch
typo3.RemoveForMessage at elements-net.de
Wed Jan 27 11:29:42 CET 2010
Hi Lienhart,
> I need the prices attached to the products as I want to traverse the products with<f:for /> viewhelper and display prices with products. On the other hand Products will sometimes be referenced by BasketItems or the like, so calling the service manually where needed seems tedious (traversing all BasketItems and adding Prices for example).
Where is the problem on that? Just let your product model call the
service in the getter as you already mentioned it - then you don't have
any problems at all. (and maybe cache the result somewhere - either in
the service or the model)
> I'll give it a try these days and report back, Franz is probably interested in the results.
Sure I am, but actually I already implemented a simple service in my
extension by now (was a loooong night though). I've placed the service
call inside the getter method of my model - and it's working like a
charm so far. In my case I have products consisting of multiple articles
(variants of a product) - so when teasing such a product I determine the
price for the promoted article. In the detail view I'm traversing the
articles then and directly fetch their price using the same method of
the article.
--------- product ---------------------------------------
/**
* return the price of the product
* @return Tx_EbWebcatalog_Domain_Model_Price
*/
public function getPrice() {
return $this->getPromotedArticle()->getPrice();
}
---------------------------------------------------------
Inside my articles I invoke the priceService then, as only the articles
have a relation to prices.
--------- article ---------------------------------------
/** Returns the price of the article respecting all given constraints by
using the PriceService
* @return Tx_EbDatamodel_Domain_Model_Price
*/
public function getPrice() {
if(!is_object($this->price)) {
$priceService =
t3lib_div::makeInstance('Tx_EbWebcatalog_Domain_Service_PriceService');
$this->price = $priceService->getPriceForArticle($this);
}
return $this->price;
}
---------------------------------------------------------
In my case the property "price" is not persistable, because there is no
such db-field. The prices themselves are stored/persisted in "prices"
(as there can be more prices in the relation due to the constraints) -
but I don't use "prices" in my case.
Oh, and each price(object) itself can have multiple priceValues due to
scaled pricing. Quite complex, but I hope it turns out to work like
expected.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list