public function renderForm()
 {
     //tinymce setup
     $this->context->smarty->assign('path_css', _THEME_CSS_DIR_);
     $this->context->smarty->assign('ad', __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_));
     $this->context->smarty->assign('autoload_rte', true);
     $this->context->smarty->assign('lang', true);
     $this->context->smarty->assign('iso', $this->context->language->iso_code);
     $obj_countries = new Country();
     $countries_var = Country::getCountries($this->context->language->id);
     if ($this->display == 'add') {
         $this->context->smarty->assign('country_var', $countries_var);
     } elseif ($this->display == 'edit') {
         $this->context->smarty->assign('edit', 1);
         $hotel_id = Tools::getValue('id');
         $hotel_branch_info_obj = new HotelBranchInformation();
         $hotel_branch_info = $hotel_branch_info_obj->hotelBranchInfoById($hotel_id);
         $country_id = $hotel_branch_info['country_id'];
         $statesbycountry = State::getStatesByIdCountry($country_id);
         if ($statesbycountry) {
             $states = array();
             foreach ($statesbycountry as $key => $value) {
                 $states[$key]['id'] = $value['id_state'];
                 $states[$key]['name'] = $value['name'];
             }
         }
         $this->context->smarty->assign('country_var', $countries_var);
         $this->context->smarty->assign('state_var', $states);
         $this->context->smarty->assign('hotel_info', $hotel_branch_info);
     }
     $this->fields_form = array('submit' => array('title' => $this->l('Save')));
     return parent::renderForm();
 }
 public function hookDisplayLeftColumn()
 {
     if ($this->context->controller->php_self == 'category') {
         if (Tools::isSubmit('filter_search_btn')) {
             $hotel_cat_id = Tools::getValue('hotel_cat_id');
             $check_in = Tools::getValue('check_in_time');
             $check_out = Tools::getValue('check_out_time');
             $error = false;
             if ($hotel_cat_id == '') {
                 $error = 1;
             } elseif ($check_in == '' || !Validate::isDate($check_in)) {
                 $error = 1;
             } elseif ($check_out == '' || !Validate::isDate($check_out)) {
                 $error = 1;
             } elseif ($check_out <= $check_in) {
                 $error = 1;
             }
             if (!$error) {
                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                     $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '?date_from=' . $check_in . '&date_to=' . $check_out;
                 } else {
                     $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '&date_from=' . $check_in . '&date_to=' . $check_out;
                 }
             } else {
                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                     $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '?error=' . $error;
                 } else {
                     $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '&error=' . $error;
                 }
             }
             Tools::redirect($redirect_link);
         }
         if (Tools::getValue('error')) {
             $this->context->smarty->assign('error', Tools::getValue('error'));
         }
         $location_enable = Configuration::get('WK_HOTEL_LOCATION_ENABLE');
         $hotel_branch_obj = new HotelBranchInformation();
         $htl_id_category = Tools::getValue('id_category');
         $category = new Category((int) $htl_id_category);
         $parent_dtl = $hotel_branch_obj->getCategoryDataByIdCategory((int) $category->id_parent);
         if (!($date_from = Tools::getValue('date_from'))) {
             $date_from = date('Y-m-d');
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         if (!($date_to = Tools::getValue('date_to'))) {
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         $search_data['parent_data'] = $parent_dtl;
         $search_data['date_from'] = $date_from;
         $search_data['date_to'] = $date_to;
         $search_data['htl_dtl'] = $hotel_branch_obj->hotelBranchInfoById(HotelBranchInformation::getHotelIdByIdCategory($htl_id_category));
         $hotel_info = $hotel_branch_obj->getActiveHotelBranchesInfo();
         $this->context->smarty->assign(array('search_data' => $search_data, 'all_hotels_info' => $hotel_info, 'location_enable' => $location_enable));
         $this->context->controller->addCSS(_PS_MODULE_DIR_ . $this->name . '/views/css/wkhotelfiltersearchblock.css');
         return $this->display(__FILE__, 'htlfiltersearchblock.tpl');
     }
 }
 /**
  * @param Product $obj
  * @throws Exception
  * @throws PrestaShopException
  * @throws SmartyException
  */
 public function initFormConfiguration($obj)
 {
     $data = $this->createTemplate($this->tpl_form);
     if ($obj->id) {
         if ($this->product_exists_in_shop) {
             $obj_htl_info = new HotelBranchInformation();
             $htl_info = $obj_htl_info->hotelsNameAndId();
             if ($htl_info) {
                 $obj_room_status = new HotelRoomStatus();
                 $rm_status = $obj_room_status->getAllRoomStatus();
                 $obj_room_type = new HotelRoomType();
                 $htl_room_type = $obj_room_type->getRoomTypeInfoByIdProduct($obj->id);
                 if ($htl_room_type) {
                     $data->assign('htl_room_type', $htl_room_type);
                     $htl_full_info = $obj_htl_info->hotelBranchInfoById($htl_room_type['id_hotel']);
                     $data->assign('htl_full_info', $htl_full_info);
                     $obj_room_info = new HotelRoomInformation();
                     $htl_room_info = $obj_room_info->getHotelRoomInfo($obj->id, $htl_room_type['id_hotel']);
                     if ($htl_room_info) {
                         $data->assign('htl_room_info', $htl_room_info);
                     }
                 }
                 $data->assign(array('product' => $obj, 'htl_info' => $htl_info, 'rm_status' => $rm_status));
             } else {
                 $this->displayWarning($this->l('Add Hotel Before configurate this product.'));
             }
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before managing hotel configuration.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before managing hotel configuration.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (!$this->errors) {
         if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
             $this->product->quantity = 0;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
         $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
         $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
         if (Tools::isSubmit('submitCustomizedDatas')) {
             // If cart has not been saved, we need to do it so that customization fields can have an id_cart
             // We check that the cookie exists first to avoid ghost carts
             if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) {
                 $this->context->cart->add();
                 $this->context->cookie->id_cart = (int) $this->context->cart->id;
             }
             $this->pictureUpload();
             $this->textRecord();
             $this->formTargetFormat();
         } elseif (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.');
         }
         $pictures = array();
         $text_fields = array();
         if ($this->product->customizable) {
             $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
             foreach ($files as $file) {
                 $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value'];
             }
             $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true);
             foreach ($texts as $text_field) {
                 $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
             }
         }
         $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields));
         $this->product->customization_required = false;
         $customization_fields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false;
         if (is_array($customization_fields)) {
             foreach ($customization_fields as $customization_field) {
                 if ($this->product->customization_required = $customization_field['required']) {
                     break;
                 }
             }
         }
         // Assign template vars related to the category + execute hooks related to the category
         $this->assignCategory();
         // Assign template vars related to the price and tax
         $this->assignPriceAndTax();
         // Assign template vars related to the images
         $this->assignImages();
         // Assign attribute groups to the template
         $this->assignAttributesGroups();
         // Assign attributes combinations to the template
         $this->assignAttributesCombinations();
         // Pack management
         $pack_items = Pack::isPack($this->product->id) ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array();
         $this->context->smarty->assign('packItems', $pack_items);
         $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1));
         if (isset($this->category->id) && $this->category->id) {
             $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
         } else {
             $return_link = 'javascript: history.back();';
         }
         $accessories = $this->product->getAccessories($this->context->language->id);
         if ($this->product->cache_is_pack || count($accessories)) {
             $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'product_list.css');
         }
         if ($this->product->customizable) {
             $customization_datas = $this->context->cart->getProductCustomization($this->product->id, null, true);
         }
         // by webkul
         $htl_features = array();
         $obj_hotel_room_type = new HotelRoomType();
         $room_info_by_product_id = $obj_hotel_room_type->getRoomTypeInfoByIdProduct($this->product->id);
         $hotel_id = $room_info_by_product_id['id_hotel'];
         if (isset($hotel_id) && $hotel_id) {
             $obj_hotel_branch = new HotelBranchInformation();
             $hotel_info_by_id = $obj_hotel_branch->hotelBranchInfoById($hotel_id);
             $hotel_policies = $hotel_info_by_id['policies'];
             $hotel_name = $hotel_info_by_id['hotel_name'];
             $country = Country::getNameById($this->context->language->id, $hotel_info_by_id['country_id']);
             $state = State::getNameById($hotel_info_by_id['state_id']);
             $hotel_location = $hotel_info_by_id['city'] . ', ' . $state . ', ' . $country;
             $obj_hotel_feaures_ids = $obj_hotel_branch->getFeaturesOfHotelByHotelId($hotel_id);
             if (isset($obj_hotel_feaures_ids) && $obj_hotel_feaures_ids) {
                 foreach ($obj_hotel_feaures_ids as $key => $value) {
                     $obj_htl_ftr = new HotelFeatures();
                     $htl_info = $obj_htl_ftr->getFeatureInfoById($value['feature_id']);
                     $htl_features[] = $htl_info['name'];
                 }
             }
         }
         $date_from = Tools::getValue('date_from');
         $date_to = Tools::getValue('date_to');
         if (!($date_from = Tools::getValue('date_from'))) {
             $date_from = date('Y-m-d');
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         if (!($date_to = Tools::getValue('date_to'))) {
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         $obj_booking_detail = new HotelBookingDetail();
         $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to);
         $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id);
         if (!$priceDisplay || $priceDisplay == 2) {
             $price_tax = true;
         } elseif ($priceDisplay == 1) {
             $price_tax = false;
         }
         $price_tax_incl = Product::getPriceStatic($this->product->id, $price_tax);
         $total_price = $price_tax_incl * $num_days;
         $obj_booking_dtl = new HotelBookingDetail();
         $hotel_room_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $hotel_id, $this->product->id, 1);
         $obj_htl_cart_booking_data = new HotelCartBookingData();
         $num_cart_rooms = $obj_htl_cart_booking_data->getCountRoomsByIdCartIdProduct($this->context->cart->id, $this->product->id, $date_from, $date_to);
         if ($hotel_room_data) {
             $total_available_rooms = $hotel_room_data['stats']['num_avail'] - $num_cart_rooms;
         }
         //end
         $location_enable = Configuration::get('WK_HOTEL_LOCATION_ENABLE');
         $hotel_branch_obj = new HotelBranchInformation();
         $hotel_info = $hotel_branch_obj->getActiveHotelBranchesInfo();
         $search_data['date_from'] = $date_from;
         $search_data['date_to'] = $date_to;
         $search_data['htl_dtl'] = $hotel_branch_obj->hotelBranchInfoById($hotel_id);
         if (Tools::getValue('error')) {
             $this->context->smarty->assign('error', Tools::getValue('error'));
         }
         $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $customization_fields, 'id_customization' => empty($customization_datas) ? null : $customization_datas[0]['id_customization'], 'accessories' => $accessories, 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'ratting_img_path' => _MODULE_DIR_ . 'hotelreservationsystem/views/img/Slices/icons-sprite.png', 'num_reviews' => ProductComment::getCommentNumber($this->product->id), 'ratting' => ProductComment::getAverageGrade($this->product->id)['grade'], 'total_available_rooms' => $total_available_rooms, 'all_hotels_info' => $hotel_info, 'location_enable' => $location_enable, 'total_price' => $total_price, 'product_controller_url' => $this->context->link->getPageLink('product'), 'num_days' => $num_days, 'date_from' => $date_from, 'date_to' => $date_to, 'hotel_location' => $hotel_location, 'hotel_name' => $hotel_name, 'hotel_policies' => $hotel_policies, 'hotel_features' => $htl_features, 'ftr_img_src' => _PS_IMG_ . 'rf/', 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'), 'search_data' => $search_data));
     }
     $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
 }