[TYPO3-mvc] How to add a unique/primary key property to a manually created domain model?

Henjo Hoeksma | Stylence me at henjohoeksma.nl
Sat Feb 16 14:17:49 CET 2013


Hi Jan,

you are updating the basket in your session, which is not the same as in
persistence. Make a choice to either save it to the session - or to the
persistence layer.
Since your basket is not run through the persistence layer in your code, it
is not persisted there. You are trying to mix both approaches here.
Stick with one of the two.

Summarising: Updating your basket in session is not the same as in
persistence.

Kind regards,

Henjo

Problems are small because we learned how to deal with them.
Problems are big because we need to learn how to deal with them.


On Sat, Feb 16, 2013 at 1:47 PM, Jan Kornblum <jan.kornblum at gmx.de> wrote:

> I've just seen that some parts of the post have been corrupted when
> watching it on forum.typo3.org instead of using a classical newsreader
> (I've just created a bugreport). Another try:
>
> ---
>
> Hi Henjo,
>
> thanks for spending time to my tries
>
>  Personally I won't add a cart in my domain object model at all. A cart is
>> a
>> temporary thing.
>> Why not save the uid's and the amount of products to a session and write a
>> service or utility class to do CRUD on the session cookie?
>>
>
> This is what i would try next as another approach.
>
>  Or - and that's an aproach I am taking in a current project - create an
>> order with a status that is not yet finished?
>>
>
> And maybe this as a third, certainly best approach
>
>  It seems to me you are giving yourself a hard time doing it the way you
>> do,
>> but I maybe misreading / misinterpreting your 'plan'... I have only
>> skipped
>> through some paragraphs
>>
>
> Maybe it it not the best example for me when still young with extbase
>
>  When you have a Basket Object with a relation to an ObjectStorage
>> containing your products, and you set your getters and setters correctly,
>> it should be perfectly possible to add/remove products by updating the
>> Cart
>> object with the use of a form...
>>
>
> First of all i would like to get it work with this approach. But i can't
> figure out my mistake.
>
> ---
> Parts from my BasketController:
> ---
>
> /**
> * The object repository
> * @var \XX\Ext\Service\UserSession
> * @inject
> */
> protected $userSession = NULL;
>
> /**
> * action addProduct
> * @param \XX\Ext\Domain\Model\Product $product
> * @return void
> */
> public function addProductAction(\XX\Ext\**Domain\Model\Product $product)
> {
>    $basket = $this->userSession->getBasket(**);
>    $basket->addProduct($product);
>    $this->userSession->**saveBasket($basket);
>    $this->redirect('list', 'Product');
> }
>
> /**
> * action removeProduct
> * @param \XX\Ext\Domain\Model\Product $product
> * @return void
> */
> public function removeProductAction(\XX\Ext\**Domain\Model\Product
> $product){
>    $basket = $this->userSession->getBasket(**);
>    $basket->removeProduct($**product);
>    $this->userSession->**saveBasket($basket);
>    $this->forward('list', 'Product');
> }
>
>
>
> --
> And parts from my BasketModel:
> --
>
> /**
> * products
> *
> * @var \TYPO3\CMS\Extbase\**Persistence\ObjectStorage<\XX\**
> Ext\Domain\Model\Product>
> */
> protected $products;
>
> /**
> * __construct
> *
> * @return Basket
> */
> public function __construct() {
>    $this->initStorageObjects();
> }
>
> /**
> * Initializes all ObjectStorage properties.
> *
> * @return void
> */
> protected function initStorageObjects() {
>    $this->products = new \TYPO3\CMS\Extbase\**Persistence\ObjectStorage();
> }
>
> /**
> * Adds a Product
> *
> * @param \XX\Ext\Domain\Model\Product $product
> * @return void
> */
> public function addProduct(\XX\Ext\Domain\**Model\Product $product) {
>    $this->products->attach($**product);
> }
>
> /**
> * Removes a Product
> *
> * @param \XX\Ext\Domain\Model\Product $product
> * @return void
> */
> public function removeProduct(\XX\Ext\Domain\**Model\Product $product) {
>    $this->products->detach($**product);
> }
>
> /**
> * Returns the Products
> *
> * @return \TYPO3\CMS\Extbase\**Persistence\ObjectStorage<\XX\**Ext\Domain\Model\Product>
> $products
> */
> public function getProducts() {
>    return clone $this->products;
> }
>
> /**
> * Sets the Products
> *
> * @param \TYPO3\CMS\Extbase\**Persistence\ObjectStorage<\XX\**Ext\Domain\Model\Product>
> $products
> * @return void
> */
> public function setProducts(\TYPO3\CMS\**Extbase\Persistence\**ObjectStorage
> $products) {
>    $this->products = $products;
> }
>
>
> --
> And the BasketView contains the following link:
> --
>
> [...] link.action action="removeProduct" arguments="{product : product}"
>  controller="Basket" pluginName="Pi1" [...]
>
>
>
> But calling this link doesn't remove the product. Argument-mapping seems
> to work correctly, as when i vardump the $product param inside
> BasketControllers removeProduct()-Action, the ProductObject seems to be as
> it should. But it doesn't get removed
>
> Can you see any mistake? Currently there seem to be to many trees and i
> can't can't see the forest
>
> Kind regards, Jan
>
>
> ______________________________**_________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc@**lists.typo3.org<TYPO3-project-typo3v4mvc at lists.typo3.org>
> http://lists.typo3.org/cgi-**bin/mailman/listinfo/typo3-**
> project-typo3v4mvc<http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc>
>


More information about the TYPO3-project-typo3v4mvc mailing list