/**
  * @Route("/stock/api/variation/update/qty")
  * @Method("POST")
  */
 public function updateStockItemsByApiAction(Request $request)
 {
     $response = new Response();
     $response->headers->set('Content-Type', 'application/json');
     $id = (int) $request->get('id');
     $newQty = (int) $request->get('qtyStock');
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('HypersitesStockBundle:ProductVariation')->find($id);
     if ($entity === null) {
         $response->setStatusCode(204, "The requested variation did not exist");
         return $response;
     }
     $oldQtyStock = $entity->getQtyStock();
     if ($oldQtyStock > $newQty) {
         $diference = $oldQtyStock - $newQty;
         $items = $entity->getItems();
     } else {
         $diference = $newQty - $oldQtyStock;
         for ($interations = 0; $interations < $diference; $interations++) {
             $item = new Item();
             $item->setProductVariation($entity);
             $em->persist($item);
         }
     }
     $entity->setQtyStock($newQty);
     $em->persist($entity);
     $em->flush();
     $response->setContent("New quantity is {$entity->getQtyStock()}");
     return $response;
 }