[TYPO3-mvc] Repository->add()

Sebastian Fischer typo3 at fischer.im
Wed Jun 16 17:30:59 CEST 2010


On 16.06.2010 12:37, Jochen Rau wrote:
> 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
>

Hi Daniel, Hi Jochen,

would it be such a bad idea to invoke the persistAll manually, like

$persistenceManager = Tx_Extbase_Dispatcher::getPersistenceManager();
$persistenceManager->persistAll();

Then you'll be able to exit.

Just an idea

Greetings
Sebastian


More information about the TYPO3-project-typo3v4mvc mailing list