[TYPO3-mvc] Repository->add()
Jochen Rau
jochen.rau at typoplanet.de
Wed Jun 16 12:37:46 CEST 2010
Hi.
On 2010-06-16, Daniel Dimitrov <danielsd_bg at yahoo.fr> wrote:
> As you can see from the title I'm trying to use the Repository add method,
> but for some unknown to me reason it doesn't work.
> My addToCartAction looks like this:
>
> public function addToCartAction() {
> $sessionId = $this->cartModel->getSessionId();
>
> $cart = t3lib_div::makeInstance('Tx_BwShop_Domain_Model_Cart');
> $cart->setSessionId($sessionId);
> $cart->setProduct($_POST['product_id']);
> $cart->setQuantity(1);
> $this->cartRepository->add($cart);
> exit();
> }
> I don't get any error messages on this, but the cart object is also not
> inserted in the database? Any ideas what could be wrong?
You have to omit the exit() statement. Otherwise the Dispatcher cannot invoke persistAll().
> Here is my CartModel:
> class Tx_BwShop_Domain_Model_Cart extends
> Tx_Extbase_DomainObject_AbstractEntity {
> public function getSessionId() {
> $this->sessionId = $GLOBALS["TSFE"]->fe_user->id;
> return $this->sessionId;
> }
BTW Accessing global variable like $GLOBALS["TSFE"]->fe_user->id inside a model is probably not a good idea. You might want to set it from "outside".
Regards
Jochen
More information about the TYPO3-project-typo3v4mvc
mailing list