/** * @Route("/billingDetails", name="billing-details") * @Template() */ public function billingDetailsAction(Request $request) { $order = new Booking(); $user = $this->getUser(); $data = $request->request; $em = $this->getDoctrine()->getManager(); $stadium = $em->find('SportFunBundle\\Entity\\Stadium', $data->get('stadiumId')); if ($stadium instanceof StadiumTennis) { $courtData = $data->get('sportfunbundle_stadiumtennis'); $numberOfPeople = $courtData['court']['maxpeople']; $unitCourtTotalPrice = 0; $numberOfCourt = 0; foreach ($stadium->getCourts() as $court) { if ($data->get('court-check-' . $court->getId())) { $unitCourtTotalPrice += $data->get('court-check-' . $court->getId()); $numberOfCourt++; } } $additionalPeople = $courtData['court']['addition']; $hiredPadPrice = 0; if ($stadium->getHirepad()) { $hiredPadPrice = $courtData['hirepad'] * $stadium->getHirepadPrice(); } $price = $unitCourtTotalPrice * $additionalPeople + $hiredPadPrice + ($numberOfPeople + $additionalPeople) * $stadium->getUnitPrice(); $order->setDatetimeCreated(new \DateTime('now', new \DateTimeZone('Australia/Melbourne'))); $order->setTotal($price); $order->setUser($user); $orderItemPeople = new BookingOrderItem(); $orderItemPeople->setName("Number of People"); $orderItemPeople->setQuantity($numberOfPeople + $additionalPeople); $orderItemPeople->setType(BookingOrderItem::TYPE_ALL); $orderItemPad = new BookingOrderItem(); $orderItemPad->setName("Number of Pad"); $orderItemPad->setQuantity($courtData['hirepad']); $orderItemPad->setType(BookingOrderItem::TYPE_ALL); $orderItemCourt = new BookingOrderItem(); $orderItemCourt->setName("Number of court"); $orderItemCourt->setQuantity($numberOfCourt); $orderItemCourt->setType(BookingOrderItem::TYPE_ALL); $order->addBookingOrderItem($orderItemPeople); $order->addBookingOrderItem($orderItemPad); $order->addBookingOrderItem($orderItemCourt); $order->setStatus(Booking::STATUS_AWAITING); } $em->persist($order); $em->flush(); //Credit card form section $creditCard = new CreditCard(); $ccForm = $this->createForm(new CreditCardType(), $creditCard, ['method' => 'POST', 'action' => $this->generateUrl('payment')]); $addressForm = $this->createForm(new AddressType()); return ['order' => $order, 'user' => $user, 'ccForm' => $ccForm->createView(), 'addressForm' => $addressForm->createView()]; }
/** * @param Booking $booking */ public function addBooking($booking) { $booking->setUser($this); $this->bookings->add($booking); }