[TYPO3-mvc] Repository->add()

Daniel Dimitrov danielsd_bg at yahoo.fr
Thu Jul 1 14:52:11 CEST 2010


Ok, I don't understand what is wrong. When I invoke the repository add() 
method, then I have a new entry in the database, but everything is empty.
As I said I've decided to drop the use of exit and rely on page types.

My AddtoCart action looks like this:

	public function addToCartAction() {
		$sessionId = $this->cartModel->getUserSessionId();
		$this->cartModel->setSessionId($sessionId);
		$this->cartModel->setProduct($this->productId);
                                var_dump($this->cartModel);
		$this->cartRepository->add($this->cartModel);

		$this->view->assign('test',$sessionId);
	}

the var_dump for $this->cartModel generates this:
object(Tx_BwShop_Domain_Model_Cart)#66 (7) {
  ["sessionId:protected"]=>
  string(32) "72805c8d100a7cf31e353a0e869607d9"
  ["product:protected"]=>
  int(81)
  ["_cleanProperties:private"]=>
  NULL
  ["uid:protected"]=>
  NULL
  ["_localizedUid:protected"]=>
  NULL
  ["_languageUid:protected"]=>
  NULL
  ["_isClone:private"]=>
  bool(false)
}

why are there no cleanProperties? And are the cleanProperties what gets 
inserted in the database?

Kind Regards,
Daniel

"Daniel Dimitrov" <danielsd_bg at yahoo.fr> wrote in message 
news:mailman.1.1276683923.12642.typo3-project-typo3v4mvc at lists.typo3.org...
> Hey Guys,
> I'm back from holiday and I have to start to annoy you again :D
>
> 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.
>
> Here is what I do:
> I have a form like this:
> <form id="myForm" 
> action="index.php?id=47448&tx_bwshop_pi2[action]=addToCart&tx_bwshop_pi2[controller]=Cart" 
> method="post">
> <div id="form_box">
> <input type="hidden" name="product_id" value="{product.uid}" />
> <input type="submit" name="button" id="submit" />
> </div>
> </form>
> <div id="addToCart" class="pointer">Add to cart</div>
>
> When I click on add to cart I make an ajax request to the Cart controller:
> $('submit').addEvent( 'click', function(evt){
> // Stops the submission of the form.
> new Event(evt).stop();
>
> // Sends the form to the action path,
> // which is 'script.php'
> $('myForm').send();
> } );
> (mootools 1.11)
>
> 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?
>
> Here is my CartModel:
> class Tx_BwShop_Domain_Model_Cart extends 
> Tx_Extbase_DomainObject_AbstractEntity {
> /**
> *
> * @var string
> */
> protected $sessionId;
>
> protected $quantity;
>
> /**
> * @var Tx_BwShop_Domain_Model_Product
> */
> protected $product;
>
> public function getSessionId() {
> $this->sessionId = $GLOBALS["TSFE"]->fe_user->id;
> return $this->sessionId;
> }
>
> public function getQuantity() {
> return $this->quantity;
> }
>
> /**
> * Getter for supplier
> *
> * @return Tx_BwShop_Domain_Model_Product
> */
> public function getProduct() {
> return $this->product;
> }
>
> public function setSessionId($sessionId) {
> $this->sessionId = $sessionId;
> }
>
> public function setProduct($product) {
> $this->product = $product;
> }
>
> public function setQuantity($quantity) {
> $this->quantity = $quantity;
> }
> }
>
> Thank you in advance!
> Daniel 



More information about the TYPO3-project-typo3v4mvc mailing list