diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index 1be7d39f3..369c8919d 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -29,33 +29,23 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $this->context = Context::getContext(); parent::__construct(); - - $objHotelBranchInformation = new HotelBranchInformation(); - $hotelBranchesInfo = $objHotelBranchInformation->hotelBranchesInfo(false, 1); - // filter hotels as per accessed hotels - $hotelBranchesInfo = HotelBranchInformation::filterDataByHotelAccess($hotelBranchesInfo, $this->context->employee->id_profile, 1); - - if ($hotelBranchesInfo) { - $this->initCart(); - } } - public function initCart() + public function init() { - if (!isset($this->context->cookie->id_guest)) { - Guest::setNewGuest($this->context->cookie); - } + parent::init(); - if (!isset($this->context->cookie->id_cart)) { - $objCart = $this->createNewCart(); - $this->context->cookie->id_cart = (int) $objCart->id; - } else { - // use previous cart - if (!validate::isLoadedObject($objCart = new Cart($this->context->cookie->id_cart))) { - $objCart = $this->createNewCart(); + if (isset($this->context->cookie->id_cart)) { + $objCart = new Cart($this->context->cookie->id_cart); + if (Validate::isLoadedObject($objCart) && !$objCart->orderExists()) { + $this->context->cart = $objCart; + } else { + $this->context->cookie->id_cart = 0; // remove invalid id_cart + $this->context->cart = new Cart(); } + } else { + $this->context->cart = new Cart(); } - $this->context->cart = $objCart; $objCustomer = new Customer(); $objCustomer->id_gender = 0; @@ -74,7 +64,11 @@ class AdminHotelRoomsBookingController extends ModuleAdminController protected function createNewCart() { - // create a new cart + // Create a new guest first if needed + if (!isset($this->context->cookie->id_guest)) { + Guest::setNewGuest($this->context->cookie); + } + $objCart = new Cart(); $objCart->recyclable = 0; $objCart->gift = 0; @@ -87,8 +81,9 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $objCart->id_guest = (int) $this->context->cookie->id_guest; $objCart->setNoMultishipping(); - $objCart->save(); - return $objCart; + $this->context->cart = $objCart; + $this->context->cart->save(); + $this->context->cookie->id_cart = (int) $this->context->cart->id; } public function postProcess() @@ -145,8 +140,8 @@ class AdminHotelRoomsBookingController extends ModuleAdminController // $booking_product = Tools::getValue('booking_product'); // } - $this->id_cart = $this->context->cart->id; - $this->id_guest = $this->context->cookie->id_guest; + $this->id_cart = (int) $this->context->cart->id; + $this->id_guest = (int) $this->context->cookie->id_guest; $this->id_hotel = $id_hotel; $this->id_room_type = $id_room_type; $this->date_from = $date_from; @@ -241,13 +236,10 @@ class AdminHotelRoomsBookingController extends ModuleAdminController public function initContent() { - // $this->show_toolbar = false; $this->toolbar_title = $this->l('Book Now'); $this->display = 'view'; parent::initContent(); - // $this->content = $this->renderView(); - // $this->context->smarty->assign('content', $this->content); } public function initSearchFormData() @@ -296,8 +288,8 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $hotelBranchesInfo = HotelBranchInformation::filterDataByHotelAccess($hotelBranchesInfo, $this->context->employee->id_profile, 1); if ($hotelBranchesInfo) { - $this->tpl_view_vars['id_cart'] = $this->context->cart->id; - $this->tpl_view_vars['id_guest'] = $this->context->cookie->id_guest; + $this->tpl_view_vars['id_cart'] = (int) $this->context->cart->id; + $this->tpl_view_vars['id_guest'] = (int) $this->context->cookie->id_guest; $this->initSearchFormData(); if (count($hotelBranchesInfo)) { if ($this->booking_product) { @@ -680,6 +672,11 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $direction = 'down'; } + // Create new cart if needed + if (!Validate::isLoadedObject($this->context->cart) && $direction == 'up') { + $this->createNewCart(); + } + $id_cart = $this->context->cart->id; $id_guest = $this->context->cookie->id_guest;