/** * @Route("/product/set_photo") * @Method({"POST", "GET"}) * */ public function setProductPhotoAction(Request $request) { $db = $this->getDoctrine()->getManager(); try { # 1. get product $product = $db->getRepository('ProductBundle:Product')->findOneById($request->get('product_id')); # 2. get photo $photo = $db->getRepository('ProductBundle:Photo')->findOneById($request->get('photo_id')); # 3. add photo for product $product_photo = new Product_Photo(); $product_photo->setProductId($product->getId()); $product_photo->setPhotoId($photo->getId()); $db->persist($product_photo); $db->flush(); $message = 'New photo was added for current product'; } catch (\Exception $e) { $message = 'Error: ' . $e->getMessage(); } return new JsonResponse(array('message' => $message)); }
/** * {@inheritDoc} */ public function setProductId($productId) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setProductId', array($productId)); return parent::setProductId($productId); }