[TYPO3-mvc] Repository->add()

Daniel Dimitrov danielsd_bg at yahoo.fr
Wed Jun 16 12:20:50 CEST 2010


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