/**
  * {@inheritDoc}
  */
 public function setProductId($productId)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setProductId', array($productId));
     return parent::setProductId($productId);
 }
 /**
  * @Route("/product/set_discount")
  * @Method({"POST", "GET"})
  *
  */
 public function setProductDiscountAction(Request $request)
 {
     $db = $this->getDoctrine()->getManager();
     try {
         # 1. get product
         $product = $db->getRepository('ProductBundle:Product')->findOneById($request->get('product_id'));
         # 2. get discount object
         $discount = $db->getRepository('ProductBundle:Discount')->findOneById($request->get('discount_id'));
         # 3. add discount for product
         $product_discount = new Product_Discount();
         $product_discount->setCount($request->get('count', 8));
         $product_discount->setProductId($product->getId());
         $product_discount->setDiscountId($discount->getId());
         $db->persist($product_discount);
         $db->flush();
         $message = 'New discount was added for current product';
     } catch (\Exception $e) {
         $message = 'Error: ' . $e->getMessage();
     }
     return new JsonResponse(array('message' => $message));
 }