[TYPO3-mvc] repository->add => persistenceManager->persistAll => repository->findBy
Daniel Dimitrov
danielsd_bg at yahoo.fr
Mon Jul 12 12:37:28 CEST 2010
Hey Franz,
"Franz Koch" <typo3.RemoveForMessage at elements-net.de> wrote in message
news:mailman.1.1278925023.11980.typo3-project-typo3v4mvc at lists.typo3.org...
> Hey Daniel,
>
>>> I'm kind of confused by your domain structure and naming, so I'm not
>>> sure where the problem could come from. As it seems, your cart can
>>> only have one product? If so, then the class name of the model feels
>>> odd as it implicates plural - or might this be misspelled and be the
>>> error?
>>
>> Ok, I slowly start to see why we need good names :)
>> products is the model that I use in list view
>> product is the model that I use in single view
>>
>> They both map the same table, but the first one (products) has just 2
>> properties - name and author.
>> and Product on the other side has around 20-30 properties.
>
> Just curious - did you have memory issues to do this, or what was the
> reason for this decision? I think I remember some older post of you (or
> somebody else) where has been asked if one can drop unneeded properties in
> queries so that they don't get loaded mapped.
It was me that made that post about performance. Well everything was running
fine
on our test server, but I think that if you don't need a property, then your
object should
not have it.
>
>
>>> If you on the other hand allow multiple products (which I assume) in
>>> your cart, then you don't need a "product" property, but a "products"
>>> (plural) and make it a objectStorage:
>>>
>>> /**
>>> * The products currently in the cart
>>> * @var
>>> Tx_Extbase_Persistence_ObjectStorage<Tx_BwShop_Domain_Model_Product>
>>> */
>>> protected $products;
>>>
>>>
>>> Maybe there is the error?
>>
>> My cart stores the date and the product_id. The product id is not an
>> mm_relation, but 1:1 relation.
>
> So, the "cart" with the $products property is actually a cartItem then,
> right?
>
> ...
>> and I use the same code to get my products in addToCartAction.
>> The only difference is that the AddToCartAction function is called in
>> the context of an ajax call(using page type for this).
>>
>> As I said after the ajax call the right data is saved in the cart, but
>> no mapping for the inserted row is made.
>
> I just had a look at the code in your initial posting:
>
>> $sessionId = $this->cartModel->getUserSessionId();
>> $this->cartModel->setSessionId($sessionId);
>
> OT: I think it's not nice to have the cartModel determine the
> userSessionId and then set it for the same model. From my understandings
> of your domain, fetching the userSession is in my eyes out of the domain
> of the cartModel - I'd rather move that to a service.
What do you call a service in the context of extbase? Helper class or what?
A small question rises in my head here: the model in extbase should only
get and set Data and do nothing else?
>
>> $this->cartModel->setProduct($this->getParametersSafely('product_id'));
>
> I think here is your problem. What does $this->getParametersSafely()
> return? Does it return the correct object, or just the UID? I it's just
> the UID, which is the issue in this case.
> After persistence, your cartModel will NOT be created from scratch again,
> as it's still in the identityMap of the persistenceManager. So the
> repository will always return the object from the identityMap.
>
> To solve this, you can either assign the product to the model (which is
> the cleanest solution) or delete the new cartModel from the identityMap
> before you fetch it again from the repository.
Man I'm so happy!!! That was it! I didn't know that I have to actually get
the product object and
set it to the cart. I thought that I had to just put the ID of the object in
this field.
Thank you very, very much!!!
>
> --
> kind regards,
> Franz Koch
Kind Regards,
The happy Daniel from Karlsruhe :)
More information about the TYPO3-project-typo3v4mvc
mailing list