コード例 #1
0
 /**
  * Ajax deleting dish from order
  * 
  * @Route("/delete/{order}/{dish}", name="dellFromOrder")
  * @Method("POST")
  * @Security("has_role('ROLE_ADMIN')")
  */
 public function dellDishFromOrderAction(DishInOrder $dish = null, Order $order = null)
 {
     $response = new JsonResponse();
     $em = $this->getDoctrine()->getManager();
     if ($dish && $order) {
         $dishes = $order->getDishesInOrder();
         if ($dishes->contains($dish)) {
             $em->remove($dish);
             $em->flush();
             if ($order->getDishesInOrder()->count() == 0) {
                 $em->remove($order);
             } else {
                 $newDishes = $order->getDishesInOrder();
                 $summ = $this->get('hedgehogs.order')->getSumm($order);
                 $order->setSumm($summ);
             }
             $em->flush();
             return $response->setData(array('deleted' => 1));
         }
     }
     return $response->setData(array('deleted' => 0));
 }
コード例 #2
0
 /**
  * Get summ of order
  *
  * @param $order
  * @return int
  */
 public function getSumm(Order $order)
 {
     $summ = 0;
     foreach ($order->getDishesInOrder() as $dishInOrder) {
         $price = $dishInOrder->getDish()->getPrice();
         $summ = $summ + $price * $dishInOrder->getCount();
     }
     return $summ;
 }