public function assignFeaturesToHotel($id_hotel, $features)
 {
     if ($features) {
         foreach ($features as $feature) {
             $obj_htl_features = new HotelBranchFeatures();
             $obj_htl_features->id_hotel = $id_hotel;
             $obj_htl_features->feature_id = $feature;
             $obj_htl_features->save();
         }
     }
     return true;
 }
 public function processSave()
 {
     if (Tools::getValue('addfeatures')) {
     } else {
         $edit_id = Tools::getValue('edit_hotel_id');
         if ($edit_id) {
             $delete_existing_vals = Db::getInstance()->delete('htl_branch_features', 'id_hotel=' . $edit_id);
         }
         $id_hotel = Tools::getValue('id_hotel');
         if ($id_hotel) {
             $hotel_features = Tools::getValue('hotel_fac');
             $obj_hotel_features = new HotelBranchFeatures();
             $assigned = $obj_hotel_features->assignFeaturesToHotel($id_hotel, $hotel_features);
             if (!$assigned) {
                 $this->errors[] = Tools::displayError('Some problem occure while assigning Features to the hotel.');
             }
             if (empty($this->errors)) {
                 if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
                     Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $id_hotel . '&update' . $this->table . '&conf=3&token=' . $this->token);
                 } else {
                     if ($edit_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';
                 }
             }
         } else {
             $this->errors[] = Tools::displayError('Please select a hotel first.');
             $this->display = 'add';
         }
     }
 }
 protected function processBulkDelete()
 {
     if (is_array($this->boxes) && !empty($this->boxes)) {
         foreach ($this->boxes as $key => $value) {
             $obj_branch_features = new HotelBranchFeatures();
             $obj_htl_cart_data = new HotelCartBookingData();
             $obj_htl_img = new HotelImage();
             $obj_htl_rm_info = new HotelRoomInformation();
             $obj_htl_rm_type = new HotelRoomType();
             $ids_product = $obj_htl_rm_type->getIdProductByHotelId($value);
             if (isset($ids_product) && $ids_product) {
                 foreach ($ids_product as $key_prod => $value_prod) {
                     $delete_cart_data = $obj_htl_cart_data->deleteBookingCartDataNotOrderedByProductId($value_prod['id_product']);
                     $delete_room_info = $obj_htl_rm_info->deleteByProductId($value_prod['id_product']);
                     $delete_room_type = $obj_htl_rm_type->deleteByProductId($value_prod['id_product']);
                     $obj_product = new Product($value_prod['id_product']);
                     $delete_product = $obj_product->delete();
                 }
             }
             $delete_branch_features = $obj_branch_features->deleteBranchFeaturesByHotelId($object->id);
             $htl_all_images = $obj_htl_img->getAllImagesByHotelId($object->id);
             foreach ($htl_all_images as $key_img => $value_img) {
                 $path_img = _PS_MODULE_DIR_ . 'hotelreservationsystem/views/img/hotel_img/' . $value_img['hotel_image_id'] . '.jpg';
                 @unlink($path_img);
             }
             $delete_htl_img = $obj_htl_img->deleteByHotelId($object->id);
         }
         parent::processBulkDelete();
     } else {
         $this->errors[] = Tools::displayError('You must select at least one element to delete.');
     }
 }
 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;
 }