[TYPO3-mvc] Storing an object from a repository into session and get it back

Jan Kornblum jan.kornblum at gmx.de
Fri Jun 26 11:31:19 CEST 2015


Hi Viktor,

>> Assuming there are only "productId" and "quantity" given as a 
>> "basketItem"s property, would it break DDD ideas if i would add a 
>> getter getProduct() to the "basketItem" model and inside this getter i 
>> fetch the "product" directly from the repository?

> Well, I don't see any OOP or DDD violation here =)
> You have a model, that gives back different model by getProduct() 
> method. Retrieveing of this model is internal and doesn't matter how it 
> was done: by Extbase or by yourself.

Thanks. But for any reasons my approach doesn't fetch the original (and 
maybe modified in between, compared to the product which had been put 
into basket before) product. I think my approach before was generally 
bad. So i modified it to just store product IDs:

class Basket {
	protected $basketItems;
	function getItems() {}
	function addItem() {}
	function removeItem() {}
	function getTotalAmount() {}
	function getTotalPrice() {}
}

class BasketItem {
	protected $productId;
	protected $quantity;
}

class BasketService {
	function getBasket() { //fetches the basket object from session and 
creates if not yet exists }
	function setBasket() { //stores the basket object back to session }
	function addItem() { //fetches from session, adds an item to basket, 
stores back to session }
	function removeItem() { //see above }
}

But *where* do i merge the stored product IDs with the real product 
objects now? I whish to be able to do something like this in controller:

$this->basketService->getBasket()->getTotalAmount(); // not possible as 
only product IDs are stored
$this->basketService->getBasket()->getItems(); // same as above

Should both methods getTotalAmount() and getItems() be rather 
implemented into the BasketService class instead of the basket 
directly? Doing all the repository operations in this service class 
instead of the (session stored) Basket object sounds better to me, but 
am i right? What would you do this like?

Kind regadrds, Jan



More information about the TYPO3-project-typo3v4mvc mailing list