[TYPO3-mvc] How to add a unique/primary key property to a manually created domain model?
Jan Kornblum
jan.kornblum at gmx.de
Sat Feb 16 13:25:55 CET 2013
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:
--
<f:link.action action="removeProduct" arguments="{product : product}"
controller="Basket" pluginName="Pi1">[remove]</f:link.action>
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
More information about the TYPO3-project-typo3v4mvc
mailing list