[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 11:12:52 CET 2013


Hi Jan,

I read some of your previous mails regarding the extension you are building.
First of all: great to see your freedom in asking questions! That's a great
thing!

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?
Or - and that's an aproach I am taking in a current project - create an
order with a status that is not yet finished?

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 ;-)

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...

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 2:47 AM, Jan Kornblum <jan.kornblum at gmx.de> wrote:

> Hi again,
>
> some more explanations about this (i hope i don't get on your nerves):
>
>
>  how can i add  "unique/primary/required"-like property to a manually
>> created domain model. the model was not created using extensionbuilder and
>> the model doesn't own a underlaying database.
>>
>> The domain model extends AbstractEntity, and when i vardump the object i
>> see that there is a uid, but it is NULL.
>>
>> Do i have to implement the unique/primary/required logic myself or can
>> this be done by any @validate oder similar notations?
>>
>
> Is it possible at all to automatically give non-database-persistable
> objects an identity, like they were real db-persistable objects? In my case
> these objects are session-stored BasketItems and i want to use their
> identity to access / restore the objects in controller actions
> (show/remove/etc).
>
> Another approach i've tried was to store ProductModel objets itself into a
> fe_user-session-stored BasketObject. Adding products works fine, showing
> the baskets items and other things also, but i'm not able to remove
> products.
>
> When i call $this->products->detach($**product) it seems that the
> $product passed as param to the method cannot be found in
> $basket->products. I've vardumped both the $product passed to the
> BasketControllers removeProduct()-action and the (in this case single)
> Product in $basket->products - I couldn't find any difference...
>
> What am i doing wrong? Maybe it's just too late, but maybe there is a
> deeper misunderstand of anything...
>
> Good night, Jan
>
> ---
>
> class Basket extends \TYPO3\CMS\Extbase\**DomainObject\AbstractEntity{
>
>         /**
>          * products
>          *
>          * @var \TYPO3\CMS\Extbase\**Persistence\ObjectStorage<\XX\**
> Ext\Domain\Model\Product>
>          */
>         protected $products;
>
>         /**
>          * __construct
>          *
>          * @return Basket
>          */
>         public function __construct() {
>                 //Do not remove the next line: It would break the
> functionality
>                 $this->initStorageObjects();
>         }
>
>         /**
>          * Initializes all ObjectStorage properties.
>          *
>          * @return void
>          */
>         protected function initStorageObjects() {
>                 /**
>                  * Do not modify this method!
>                  * It will be rewritten on each save in the extension
> builder
>                  * You may modify the constructor of this class instead
>                  */
>                 $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 The Product to be
> removed
>          * @return void
>          */
>         public function removeProduct(\XX\Ext\Domain\**Model\Product
> $product) {
>                 $this->products->detach($**product);
>
>         }
>
> }
>
>
> ______________________________**_________________
> 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