public function processSave()
 {
     $hotel_id = Tools::getValue('hotel_id');
     $hotel_name = Tools::getValue('hotel_name');
     $phone = Tools::getValue('phone');
     $email = Tools::getValue('email');
     $check_in = Tools::getValue('check_in');
     $check_out = Tools::getValue('check_out');
     $short_description = Tools::getValue('short_description');
     $description = Tools::getValue('description');
     $rating = Tools::getValue('hotel_rating');
     $city = Tools::getValue('hotel_city');
     $state = Tools::getValue('hotel_state');
     $country = Tools::getValue('hotel_country');
     $policies = Tools::getValue('hotel_policies');
     $zipcode = Tools::getValue('hotel_postal_code');
     $address = Tools::getValue('address');
     $active = Tools::getValue('ENABLE_HOTEL');
     if ($hotel_name == '') {
         $this->errors[] = Tools::displayError('Hotel name is required field.');
     } else {
         if (!Validate::isGenericName($hotel_name)) {
             $this->errors[] = Tools::displayError($this->l('Hotel name must not have Invalid characters <>;=#{}'));
         }
     }
     if (!$phone) {
         $this->errors[] = Tools::displayError('Phone number is required field.');
     } else {
         if (!Validate::isPhoneNumber($phone)) {
             $this->errors[] = Tools::displayError('Please enter a valid phone number.');
         }
     }
     if ($email == '') {
         $this->errors[] = Tools::displayError('Email is required field.');
     } else {
         if (!Validate::isEmail($email)) {
             $this->errors[] = Tools::displayError('Please enter a valid email.');
         }
     }
     if ($check_in == '') {
         $this->errors[] = Tools::displayError('Check In time is required field.');
     }
     if ($check_out == '') {
         $this->errors[] = Tools::displayError('Check Out Time is required field.');
     }
     if ($zipcode == '') {
         $this->errors[] = Tools::displayError('Postal Code is required field.');
     } else {
         if (!Validate::isPostCode($zipcode)) {
             $this->errors[] = Tools::displayError('Enter a Valid Postal Code.');
         }
     }
     if (!$rating) {
         $this->errors[] = Tools::displayError('Rating is required field.');
     }
     if ($address == '') {
         $this->errors[] = Tools::displayError('Address is required field.');
     }
     if (!$country) {
         $this->errors[] = Tools::displayError('Country is required field.');
     }
     if (!$state) {
         $this->errors[] = Tools::displayError('State is required field.');
     }
     if ($city == '') {
         $this->errors[] = Tools::displayError('City is required field.');
     } else {
         if (!Validate::isCityName($city)) {
             $this->errors[] = Tools::displayError('Enter a Valid City Name.');
         }
     }
     //validate hotel main image
     if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']['name']) {
         $obj_htl_img = new HotelImage();
         $error = $obj_htl_img->validAddHotelMainImage($_FILES['hotel_image']);
         if ($error) {
             $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false);
         }
     }
     //validate Hotel's other images
     if (isset($_FILES['images']) && $_FILES['images']) {
         $obj_htl_img = new HotelImage();
         $error = $obj_htl_img->validAddHotelOtherImage($_FILES['images']);
         if ($error) {
             $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false);
         }
     }
     if (!count($this->errors)) {
         if ($hotel_id) {
             $obj_hotel_info = new HotelBranchInformation($hotel_id);
         } else {
             $obj_hotel_info = new HotelBranchInformation();
         }
         if ($obj_hotel_info) {
             if (!$active) {
                 $obj_htl_rm_info = new HotelRoomType();
                 $ids_product = $obj_htl_rm_info->getIdProductByHotelId($obj_hotel_info->id);
                 if (isset($ids_product) && $ids_product) {
                     foreach ($ids_product as $key_prod => $value_prod) {
                         $obj_product = new Product($value_prod['id_product']);
                         if ($obj_product->active) {
                             $obj_product->toggleStatus();
                         }
                     }
                 }
             }
         }
         $obj_hotel_info->active = $active;
         $obj_hotel_info->hotel_name = $hotel_name;
         $obj_hotel_info->phone = $phone;
         $obj_hotel_info->email = $email;
         $obj_hotel_info->check_in = $check_in;
         $obj_hotel_info->check_out = $check_out;
         $obj_hotel_info->short_description = $short_description;
         $obj_hotel_info->description = $description;
         $obj_hotel_info->rating = $rating;
         $obj_hotel_info->city = $city;
         $obj_hotel_info->state_id = $state;
         $obj_hotel_info->country_id = $country;
         $obj_hotel_info->zipcode = $zipcode;
         $obj_hotel_info->policies = $policies;
         $obj_hotel_info->address = $address;
         $obj_hotel_info->save();
         $new_hotel_id = $obj_hotel_info->id;
         $hotel_img_path = _PS_MODULE_DIR_ . 'hotelreservationsystem/views/img/hotel_img/';
         //upload hotel's image
         if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']) {
             $obj_htl_img = new HotelImage();
             $obj_htl_img->uploadMainImage($_FILES['hotel_image'], $new_hotel_id, $hotel_img_path);
         }
         //upload hotel's other images
         if (isset($_FILES['images']) && $_FILES['images']) {
             $obj_htl_img = new HotelImage();
             $obj_htl_img->uploadOtherImages($_FILES['images'], $new_hotel_id, $hotel_img_path);
         }
         if ($new_hotel_id) {
             $grp_ids = array();
             $obj_grp = new Group();
             $data_grp_ids = $obj_grp->getGroups(1, $id_shop = false);
             foreach ($data_grp_ids as $key => $value) {
                 $grp_ids[] = $value['id_group'];
             }
             $country_name = (new Country())->getNameById(Configuration::get('PS_LANG_DEFAULT'), $country);
             $cat_country = $this->addCategory($country_name, false, $grp_ids);
             if ($cat_country) {
                 $state_name = (new State())->getNameById($state);
                 $cat_state = $this->addCategory($state_name, $cat_country, $grp_ids);
             }
             if ($cat_state) {
                 $cat_city = $this->addCategory($city, $cat_state, $grp_ids);
             }
             if ($cat_city) {
                 $cat_hotel = $this->addCategory($hotel_name, $cat_city, $grp_ids, 1, $new_hotel_id);
             }
             if ($cat_hotel) {
                 $obj_hotel_info = new HotelBranchInformation($new_hotel_id);
                 $obj_hotel_info->id_category = $cat_hotel;
                 $obj_hotel_info->save();
             }
         }
         if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             if ($hotel_id) {
                 Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=4&token=' . $this->token);
             } else {
                 Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=3&token=' . $this->token);
             }
         } else {
             if ($hotel_id) {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token);
             } else {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=3&token=' . $this->token);
             }
         }
     } else {
         if ($hotel_id) {
             $this->display = 'edit';
         } else {
             $this->display = 'add';
         }
     }
 }
 public function createDummyDataForProject()
 {
     //delete privious products of prestashop
     $all_products = Product::getSimpleProducts(Configuration::get('PS_LANG_DEFAULT'));
     foreach ($all_products as $key_pro => $value_pro) {
         $obj_product = new Product($value_pro['id_product']);
         $obj_product->delete();
     }
     // first add a hotel.................
     $def_cont_id = Country::getDefaultCountryId();
     $obj_hotel_info = new HotelBranchInformation();
     $obj_hotel_info->active = 1;
     $obj_hotel_info->hotel_name = "The Hotel Prime";
     $obj_hotel_info->phone = 01234567;
     $obj_hotel_info->email = "*****@*****.**";
     $obj_hotel_info->check_in = '12:00';
     $obj_hotel_info->check_out = '12:00';
     $obj_hotel_info->short_description = $this->l('Nice place to stay');
     $obj_hotel_info->description = $this->l('Nice place to stay');
     $obj_hotel_info->rating = 3;
     $obj_hotel_info->city = 'Nainital';
     $states = State::getStatesByIdCountry($def_cont_id);
     $state_id = $states[0]['id_state'];
     $obj_hotel_info->state_id = $state_id;
     $obj_hotel_info->country_id = $def_cont_id;
     $obj_hotel_info->zipcode = 263001;
     $obj_hotel_info->policies = $this->l('1. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred. 2. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred. 3. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred. 4. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred.');
     $obj_hotel_info->address = 'Near post office, Mallital, Nainital';
     $obj_hotel_info->save();
     $htl_id = $obj_hotel_info->id;
     $grp_ids = array();
     $obj_grp = new Group();
     $data_grp_ids = $obj_grp->getGroups(1, $id_shop = false);
     foreach ($data_grp_ids as $key => $value) {
         $grp_ids[] = $value['id_group'];
     }
     $country_name = (new Country())->getNameById(Configuration::get('PS_LANG_DEFAULT'), $def_cont_id);
     $cat_country = $this->addCategory($country_name, false, $grp_ids);
     if ($cat_country) {
         $states = State::getStatesByIdCountry($def_cont_id);
         $state_name = $states[0]['name'];
         $cat_state = $this->addCategory($state_name, $cat_country, $grp_ids);
     }
     if ($cat_state) {
         $cat_city = $this->addCategory('DefCity', $cat_state, $grp_ids);
     }
     if ($cat_city) {
         $cat_hotel = $this->addCategory('The Hotel Prime', $cat_city, $grp_ids, 1, $htl_id);
     }
     if ($cat_hotel) {
         $obj_hotel_info = new HotelBranchInformation($htl_id);
         $obj_hotel_info->id_category = $cat_hotel;
         $obj_hotel_info->save();
     }
     $branch_ftr_ids = array(1, 2, 4, 7, 8, 9, 11, 12, 14, 16, 17, 18, 21);
     foreach ($branch_ftr_ids as $key_ftr => $value_ftr) {
         $htl_ftr_obj = new HotelBranchFeatures();
         $htl_ftr_obj->id_hotel = $htl_id;
         $htl_ftr_obj->feature_id = $value_ftr;
         $htl_ftr_obj->save();
     }
     $prod_arr = array('Delux Rooms', 'Executive Rooms', 'luxury Rooms');
     $img_num = 1;
     foreach ($prod_arr as $key_prod => $value_prod) {
         // Add Product
         $product = new Product();
         $product->name = array();
         $product->description = array();
         $product->description_short = array();
         $product->link_rewrite = array();
         foreach (Language::getLanguages(true) as $lang) {
             $product->name[$lang['id_lang']] = $value_prod;
             $product->description[$lang['id_lang']] = $this->l('Fashion axe kogi yuccie, ramps shabby chic direct trade before they sold out distillery bicycle rights. Slow-carb +1 quinoa VHS. +1 brunch trust fund, meggings chartreuse sustainable everyday carry tumblr hoodie tacos tilde ramps post-ironic fixie.');
             $product->description_short[$lang['id_lang']] = $this->l('Fashion axe kogi yuccie, ramps shabby chic direct trade before they sold out distillery bicycle rights. Slow-carb +1 quinoa VHS. +1 brunch trust fund, meggings chartreuse sustainable everyday carry tumblr hoodie tacos tilde ramps post-ironic fixie.');
             $product->link_rewrite[$lang['id_lang']] = Tools::link_rewrite('Super Delux Rooms');
         }
         $product->id_shop_default = Context::getContext()->shop->id;
         $product->id_category_default = 2;
         $product->price = 1000;
         $product->active = 1;
         $product->quantity = 99999999;
         $product->is_virtual = 1;
         $product->indexed = 1;
         $product->save();
         $product_id = $product->id;
         Search::indexation(Tools::link_rewrite($value_prod), $product_id);
         $product->addToCategories(2);
         StockAvailable::updateQuantity($product_id, null, 99999999);
         //image upload for products
         $count = 0;
         $have_cover = false;
         $old_path = _PS_MODULE_DIR_ . $this->name . '/views/img/prod_imgs/' . $img_num . '.png';
         $image_obj = new Image();
         $image_obj->id_product = $product_id;
         $image_obj->position = Image::getHighestPosition($product_id) + 1;
         if ($count == 0) {
             if (!$have_cover) {
                 $image_obj->cover = 1;
             }
         } else {
             $image_obj->cover = 0;
         }
         $image_obj->add();
         $new_path = $image_obj->getPathForCreation();
         $imagesTypes = ImageType::getImagesTypes('products');
         foreach ($imagesTypes as $image_type) {
             ImageManager::resize($old_path, $new_path . '-' . $image_type['name'] . '.jpg', $image_type['width'], $image_type['height']);
         }
         ImageManager::resize($old_path, $new_path . '.jpg');
         for ($k = 1; $k <= 5; $k++) {
             $htl_room_info_obj = new HotelRoomInformation();
             $htl_room_info_obj->id_product = $product_id;
             $htl_room_info_obj->id_hotel = $htl_id;
             $htl_room_info_obj->room_num = 'A' . $i . '-10' . $k;
             $htl_room_info_obj->id_status = 1;
             $htl_room_info_obj->floor = 'first';
             $htl_room_info_obj->save();
         }
         $htl_rm_type = new HotelRoomType();
         $htl_rm_type->id_product = $product_id;
         $htl_rm_type->id_hotel = $htl_id;
         $htl_rm_type->adult = 2;
         $htl_rm_type->children = 2;
         $htl_rm_type->save();
         $img_num++;
         // Add features to the product
         $ftr_arr = array(0 => 8, 1 => 9, 2 => 10, 3 => 11);
         $ftr_val_arr = array(0 => 34, 1 => 35, 2 => 36, 3 => 37);
         foreach ($ftr_arr as $key_htl_ftr => $val_htl_ftr) {
             $product->addFeaturesToDB($val_htl_ftr, $ftr_val_arr[$key_htl_ftr]);
         }
     }
     return true;
 }