Add additional facilities to duplication
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user