diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 066996e3d..c59d1757f 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -769,6 +769,10 @@ class AdminProductsControllerCore extends AdminController } } + // update lang fields + foreach (Language::getLanguages(true) as $language) { + $product->link_rewrite[$language['id_lang']] = Tools::str2url($product->name[$language['id_lang']]); + } if ($product->add() // && Category::duplicateProductCategories($id_product_old, $product->id) && Product::duplicateSuppliers($id_product_old, $product->id) @@ -802,6 +806,11 @@ class AdminProductsControllerCore extends AdminController )) { $this->errors[] = Tools::displayError('An error occurred while duplicating rooms.'); } + if (!HotelRoomTypeDemand::duplicateRoomTypeDemands($id_product_old, $product->id)) { + $this->errors[] = Tools::displayError( + 'An error occurred while duplicating additional facilities.' + ); + } } else { $this->errors[] = Tools::displayError('An error occurred while duplicating room type.'); } diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php b/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php index 4d7cbef3e..0a091aee4 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php @@ -50,6 +50,74 @@ class HotelRoomTypeDemand extends ObjectModel ), ); + public static function duplicateRoomTypeDemands($idProductOld, $idProductNew) + { + $idLang = Context::getContext()->language->id; + $roomTypeDemands = Db::getInstance()->executeS( + 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_demand` rd + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_global_demand` rgd + ON (rd.`id_global_demand` = rgd.`id_global_demand`) + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_global_demand_lang` rgdl + ON (rgd.`id_global_demand` = rgdl.`id_global_demand` AND rgdl.`id_lang` = '.(int)$idLang.') + WHERE rd.`id_product`='.(int)$idProductOld + ); + + if (is_array($roomTypeDemands) && count($roomTypeDemands)) { + $globalDemandOption = new HotelRoomTypeGlobalDemandAdvanceOption(); + foreach ($roomTypeDemands as $roomTypeDemand) { + $idGlobalDemand = $roomTypeDemand['id_global_demand']; + $objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand); + $hotelRoomTypeDemandPrice = new HotelRoomTypeDemandPrice(); + + $objHRTDemand = new self(); + $objHRTDemand->id_product = $idProductNew; + $objHRTDemand->id_global_demand = $idGlobalDemand; + if (!$objHRTDemand->save()) { + return false; + } + + $demandPrice = $roomTypeDemand['price']; + if (Validate::isPrice($demandPrice)) { + if ($objGlobalDemand->price != $demandPrice) { + $objHRTDemandPrice = new HotelRoomTypeDemandPrice(); + $objHRTDemandPrice->id_product = $idProductNew; + $objHRTDemandPrice->id_global_demand = $idGlobalDemand; + $objHRTDemandPrice->id_option = 0; + $objHRTDemandPrice->price = $demandPrice; + if (!$objHRTDemandPrice->save()) { + return false; + } + } + } + + $advOptions = $globalDemandOption->getGlobalDemandAdvanceOptions($idGlobalDemand, $idLang); + if (is_array($advOptions) && count($advOptions)) { + foreach ($advOptions as $option) { + $objAdvOption = new HotelRoomTypeGlobalDemandAdvanceOption($option['id'], $idLang); + $oldOptionPrice = $hotelRoomTypeDemandPrice->getRoomTypeDemandPrice( + $idProductOld, + $objAdvOption->id_global_demand, + $option['id'] + ); + if (Validate::isPrice($oldOptionPrice)) { + if ($oldOptionPrice != $objAdvOption->price) { + $objHRTDemandPrice = new HotelRoomTypeDemandPrice(); + $objHRTDemandPrice->id_product = $idProductNew; + $objHRTDemandPrice->id_global_demand = $idGlobalDemand; + $objHRTDemandPrice->id_option = $option['id']; + $objHRTDemandPrice->price = $oldOptionPrice; + if (!$objHRTDemandPrice->save()) { + return false; + } + } + } + } + } + } + } + return true; + } + public function getRoomTypeDemands($idProduct, $idLang = 0, $useTax = null) { if (!$idLang) {