Exemple #1
0
 public function checkpromotionAction()
 {
     $code = $this->getRequest()->getParam('code');
     $room_id = $this->getRequest()->getParam('room_id');
     $index = $this->getRequest()->getParam('index');
     $response['code'] = 'ERROR';
     $booking = self::getBooking();
     if ($room_id === 'hotel') {
         $Promotion = Promotion::checkPromotion($code, $booking['hotels_id'], date('Y-m-d'), 'hotel');
         if ($Promotion) {
             $booking['payment']['promo_hotel'] = $Promotion->price;
             $response['code'] = 'SUCCESS';
         } else {
             $booking['payment']['promo_hotel'] = 0;
         }
     } else {
         if (array_key_exists($room_id, $booking['rooms'])) {
             $Promotion = Promotion::checkPromotion($code, $room_id, date('Y-m-d'));
             if ($Promotion) {
                 $booking['rooms'][$room_id][$index]['promotion_id'] = $Promotion->id;
                 $booking['rooms'][$room_id][$index]['discount'] = $Promotion->price;
                 $discount = 0;
                 foreach ($booking['rooms'] as $rooms) {
                     foreach ($rooms as $room) {
                         $discount = $discount + $room['discount'];
                     }
                 }
                 $booking['payment']['promo_price'] = $discount;
                 $response['code'] = 'SUCCESS';
             }
         }
     }
     $booking['payment']['grand_total'] = $booking['payment']['total_price'] - (int) $booking['payment']['promo_price'] - (int) $booking['payment']['promo_hotel'] + $booking['payment']['payment_fee_price'];
     $this->setBooking($booking);
     echo json_encode($response);
 }