[TYPO3-mvc] repository->add => persistenceManager->persistAll => repository->findBy
Daniel Dimitrov
danielsd_bg at yahoo.fr
Thu Jul 8 11:21:09 CEST 2010
Hey guys,
I'm making an Ajax request that saves a product and immediately after that
returns the saved product together with all other saved products for the
user. Sadly I have a small problem with the returned object one of the
properties is of type Tx_BwShop_Domain_Model_Products, but the ajax request
returns it as INT.
In my controller I have the following code:
public function addToCartAction() {
$sessionId = $this->cartModel->getUserSessionId();
$this->cartModel->setSessionId($sessionId);
$this->cartModel->setProduct($this->getParametersSafely('product_id'));
$this->cartRepository->add($this->cartModel);
$persistenceManager = Tx_Extbase_Dispatcher::getPersistenceManager();
$persistenceManager->persistAll();
$products = $this->cartRepository->findBySessionId($sessionId);
var_dump($products);
$this->view->assign('products',$products);
}
After using the repository add method I immediately call the persistence
manager to store the object, because I need it in my next database request.
The product is stored in the database and I retrieve it, the problem is that
the product is not mapped with the Tx_BwShop_Domain_Model_Products.
My Cart model is defining the product as follow:
/**
* @var Tx_BwShop_Domain_Model_Products
*/
protected $product;
but the var_dump shows:
array(1) {
[0]=>
object(Tx_BwShop_Domain_Model_Cart)#66 (7) {
["sessionId:protected"]=>
string(32) "8e5ae12d9b922b5e16a5e76bb75486ca"
["product:protected"]=>
int(903)
["_cleanProperties:private"]=>
array(3) {
["sessionId"]=>
string(32) "8e5ae12d9b922b5e16a5e76bb75486ca"
["product"]=>
int(903)
["uid"]=>
int(174)
}
["uid:protected"]=>
int(174)
["_localizedUid:protected"]=>
NULL
["_languageUid:protected"]=>
NULL
["_isClone:private"]=>
bool(false)
}
}
as you can see product is int and not a Tx_BwShop_Domain_Model_Products.
Any ideas? Must I somehow start the mapping for the product manually?
Kind regards,
Daniel
More information about the TYPO3-project-typo3v4mvc
mailing list