php - Doctrine shopping cart after add order: undefined index -
i program shopping cart in doctrine , nette framework. there additem
method: (add session cart)
public function additem($item) { $cart = $this->getcartsection(); $product = $this->product_facade->getproduct($item['voucher_id']); if (isset($cart->cart_items[$product->getid()])) { $cart->cart_items[$product->getid()]['amount'] += $item['amount']; } else { $cart->cart_items[$product->getid()] = array( 'voucher' => $product, 'amount' => $item['amount'] ); } }
and there method add order db
public function add($creator, $data) { $order = new orders(); $order->setprice($data['price']); $order->setstatus($this->status_facade->getstatus(self::new_status_id)); $order->setpayment($this->payment_facade->getpayment($data->payment)); $order->setdate(new datetime()); $order->setuser($creator); foreach ($data['cart'] $item) { $order_product = new ordersproduct(); $order_product->setquantity($item['amount']); $order_product->setproduct($item['voucher']); $order->additem($order_product); } $this->em->persist($order); $this->em->flush(); }
i error after click button 'add order'
undefined index: 00000000659576f8000000004032b93e
but know error. there method add
, method gets product entity session.
$order_product->setproduct($item['voucher']);
i need product entity in session becuase want count total price in cart. if call in add method setproduct
number or $item['voucher']->getid()
(this variable entity product
)
$order_product->setproduct( $this->product_facade->getproduct(4) );
it's ok, don't know, why call product entity session wronk. same method same result.
can me problem? know why wronk?
thank you, hope understand me.
you can't save entities session. doctrine uses identity map.
save entity id session , read entity database before working it. if need more data in session, don't use entity that. reather implement dto.
Comments
Post a Comment