Merge branch 'develop' into gli-2241-2

This commit is contained in:
Shreesh Arora
2024-08-29 16:24:46 +05:30
204 changed files with 7042 additions and 5285 deletions

View File

@@ -373,36 +373,22 @@ class ProductCore extends ObjectModel
protected $webserviceParameters = array(
'objectMethods' => array(
'add' => 'addWs',
'update' => 'updateWs',
'add' => 'addWsRoomType',
'update' => 'updateWsRoomType',
'delete' => 'deleteWs'
),
'objectsNodeName' => 'room_types',
'objectNodeName' => 'room_type',
'retrieveData' => array(
'retrieveMethod' => 'getRoomTypesObjectList'
),
'fields' => array(
'id_hotel' => array(
'getter' => 'getWsHotel',
'setter' => 'setWsHotel',
'xlink_resource' => 'hotels'
),
'adults' => array(
'getter' => 'getWsAdults',
'setter' => 'setWsAdults',
),
'children' => array(
'getter' => 'getWsChildren',
'setter' => 'setWsChildren',
),
'id_manufacturer' => array(
'xlink_resource' => 'manufacturers'
),
'id_supplier' => array(
'xlink_resource' => 'suppliers'
),
'id_category_default' => array(
'xlink_resource' => 'categories'
),
'id_hotel' => array('getter' => 'getWsHotel','setter' => 'setWsHotel', 'xlink_resource' => 'hotels'),
'adults' => array('getter' => 'getWsAdults','setter' => 'setWsAdults'),
'children' => array('getter' => 'getWsChildren','setter' => 'setWsChildren'),
'id_manufacturer' => array('xlink_resource' => 'manufacturers'),
'id_supplier' => array('xlink_resource' => 'suppliers'),
'id_category_default' => array('xlink_resource' => 'categories'),
'new' => array(),
'cache_default_attribute' => array(),
'id_default_image' => array(
@@ -420,36 +406,28 @@ class ProductCore extends ObjectModel
// 'resourceName' => 'combinations'
// )
// ),
'id_tax_rules_group' => array(
'xlink_resource' => array(
'resourceName' => 'tax_rule_groups'
)
),
'position_in_category' => array(
'getter' => 'getWsPositionInCategory',
'setter' => 'setWsPositionInCategory'
),
'id_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')),
'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => 'setWsPositionInCategory'),
// 'manufacturer_name' => array(
// 'getter' => 'getWsManufacturerName',
// 'setter' => false
// ),
'quantity' => array(
'getter' => false,
'setter' => false
),
'type' => array(
'getter' => 'getWsType',
'setter' => 'setWsType',
),
'id_advance_paypent' => array(
'xlink_resource' => array(
'resourceName' => 'advance_payments'
),
'getter' => 'getWsRoomTypeAdvancePayment',
'setter' => false
),
'type' => array('getter' => 'getWsType', 'setter' => 'setWsType'),
),
'associations' => array(
'advance_payments' => array(
'resource' => 'advance_payment',
'getter' => 'getWsAdvancePayments',
'setter' => 'setWsAdvancePayments',
'fields' => array(
'id' => array(),
'payment_type' => array(),
'tax_include' => array(),
'value' => array(),
'active' => array(),
'calculate_from' => array(),
),
),
'categories' => array(
'resource' => 'category',
'fields' => array(
@@ -466,7 +444,8 @@ class ProductCore extends ObjectModel
'id' => array('required' => true),
)
),
'tags' => array('resource' => 'tag',
'tags' => array(
'resource' => 'tag',
'fields' => array(
'id' => array('required' => true),
)
@@ -484,13 +463,78 @@ class ProductCore extends ObjectModel
)
),
'extra_demands' => array(
'setter' => false,
'resource' => 'extra_demand',
'fields' => array(
'id' => array('required' => true),
'id_option' => array(),
'price' => array(),
)
),
'services' => array(
'resource' => 'service',
'fields' => array(
'id' => array('validate' => 'isUnsignedId', 'required' => true),
'price' => array('validate' => 'isPrice', 'required' => true),
'id_tax_rules_group' => array('validate' => 'isUnsignedId')
)
),
),
'hidden_fields' => array(
'booking_product',
'service_product_type'
),
);
protected $webserviceServicesParameters = array(
'objectMethods' => array(
'add' => 'addWsServices',
'update' => 'updateWsServices',
'delete' => 'deleteWs'
),
'objectsNodeName' => 'services',
'objectNodeName' => 'service',
'retrieveData' => array(
'retrieveMethod' => 'getServicesObjectList'
),
'fields' => array(
'id_manufacturer' => array('xlink_resource' => 'manufacturers'),
'id_supplier' => array('xlink_resource' => 'suppliers'),
'id_category_default' => array('xlink_resource' => 'categories'),
'new' => array(),
'cache_default_attribute' => array(),
'id_default_image' => array(
'getter' => 'getCoverWs',
'setter' => 'setCoverWs',
'xlink_resource' => array(
'resourceName' => 'images',
'subResourceName' => 'room_types'
)
),
'id_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')),
'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => 'setWsPositionInCategory'),
// 'manufacturer_name' => array(
// 'getter' => 'getWsManufacturerName',
// 'setter' => false
// ),
'quantity' => array('getter' => false, 'setter' => false),
'type' => array('getter' => 'getWsType', 'setter' => 'setWsType'),
),
'associations' => array(
'categories' => array(
'resource' => 'category',
'fields' => array('id' => array('required' => true))
),
'images' => array('resource' => 'image', 'fields' => array('id' => array())),
'feature_prices' => array(
'setter' => false, 'resource' => 'feature_price',
'fields' => array(
'id' => array('required' => true),
)
),
),
'hidden_fields' => array(
'booking_product',
),
);
const CUSTOMIZE_FILE = 0;
@@ -5709,8 +5753,11 @@ class ProductCore extends ObjectModel
*/
public function getCoverWs()
{
$result = $this->getCover($this->id);
return $result['id_image'];
if ($result = $this->getCover($this->id)) {
return $result['id_image'];
}
return false;
}
/**
@@ -5999,8 +6046,9 @@ class ProductCore extends ObjectModel
return true;
}
public function addWs($autodate = true, $null_values = false)
public function addWsRoomType($autodate = true, $null_values = false)
{
$this->booking_product = 1;
if ($success = $this->add($autodate, $null_values)) {
if (Configuration::get('PS_SEARCH_INDEXATION')) {
Search::indexation(false, $this->id);
@@ -6012,19 +6060,56 @@ class ProductCore extends ObjectModel
return $success;
}
public function updateWs($null_values = false)
public function updateWsRoomType($null_values = false)
{
$success = parent::update($null_values);
if ($success && Configuration::get('PS_SEARCH_INDEXATION')) {
Search::indexation(false, $this->id);
if (self::isBookingProduct($this->id)) {
$this->booking_product = 1; // Since there is nothing set from the API, it might get set as false
$success = parent::update($null_values);
if ($success && Configuration::get('PS_SEARCH_INDEXATION')) {
Search::indexation(false, $this->id);
}
$this->setWsRoomTypeInfo();
Hook::exec('updateProduct', array('id_product' => (int)$this->id));
return $success;
}
$this->setWsRoomTypeInfo();
WebserviceRequest::getInstance()->setError(500, Tools::displayError('Room type not found.'), 134);
return false;
}
public function addWsServices()
{
$this->booking_product = 0;
if ($success = $this->add()) {
if (Configuration::get('PS_SEARCH_INDEXATION')) {
Search::indexation(false, $this->id);
}
}
Hook::exec('updateProduct', array('id_product' => (int)$this->id));
return $success;
}
public function updateWsServices($null_values = false)
{
if (!self::isBookingProduct($this->id)) {
$this->booking_product = 0; // Since there is nothing set from the API.
$success = parent::update($null_values);
if ($success && Configuration::get('PS_SEARCH_INDEXATION')) {
Search::indexation(false, $this->id);
}
Hook::exec('updateProduct', array('id_product' => (int)$this->id));
return $success;
}
WebserviceRequest::getInstance()->setError(500, Tools::displayError('Service not found.'), 134);
return false;
}
/**
* For a given product, returns its real quantity
*
@@ -6384,6 +6469,20 @@ class ProductCore extends ObjectModel
return $cache_id;
}
public function getRoomTypesObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit)
{
$sql_filter .= ' AND main.`booking_product` = 1';
return parent::getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit);
}
public function getServicesObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit)
{
$sql_filter .= ' AND main.`booking_product` = 0';
return parent::getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit);
}
public static function setPackStockType($id_product, $pack_stock_type)
{
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product p
@@ -6408,10 +6507,55 @@ class ProductCore extends ObjectModel
public function getWsAdvancePayments()
{
return Db::getInstance()->executeS(
'SELECT `id` FROM `'._DB_PREFIX_.'htl_advance_payment` WHERE `id_product` = '.(int)$this->id.' ORDER BY `id` ASC'
'SELECT * FROM `'._DB_PREFIX_.'htl_advance_payment` WHERE `id_product` = '.(int)$this->id.' ORDER BY `id` ASC'
);
}
public function setWsAdvancePayments($adv_payment)
{
$obj_adv_pmt = new HotelAdvancedPayment();
if (!$adv_payment) {
if ($adv_pmt_info = $obj_adv_pmt->getIdAdvPaymentByIdProduct($this->id)) {
$obj_adv_pmt = new HotelAdvancedPayment((int) $adv_pmt_info['id']);
}
$obj_adv_pmt->payment_type = '';
$obj_adv_pmt->id_product = $this->id;
$obj_adv_pmt->value = '';
$obj_adv_pmt->id_currency = '';
$obj_adv_pmt->tax_include = '';
$obj_adv_pmt->calculate_from = 0;
$obj_adv_pmt->active = 0;
return $obj_adv_pmt->save();
} else if (is_array($adv_payment) && count($adv_payment) == 1) {
$fields = array_shift($adv_payment);
if (!Validate::isLoadedObject($obj_adv_pmt = new HotelAdvancedPayment($fields['id']))) {
if ($adv_pmt_info = $obj_adv_pmt->getIdAdvPaymentByIdProduct($this->id)) {
$obj_adv_pmt = new HotelAdvancedPayment((int) $adv_pmt_info['id']);
}
}
$obj_adv_pmt->id_product = $this->id;
$obj_adv_pmt->active = 1;
$obj_adv_pmt->payment_type = $fields['payment_type'];
$obj_adv_pmt->value = $fields['value'];
if ($fields['payment_type'] == 2) {
$obj_adv_pmt->id_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
} else {
$obj_adv_pmt->id_currency = '';
}
$obj_adv_pmt->tax_include = $fields['tax_include'];
$obj_adv_pmt->calculate_from = $fields['calculate_from'];
return $obj_adv_pmt->save();
}
return false;
}
public function getWsHotel()
{
return Db::getInstance()->getValue(
@@ -6435,8 +6579,41 @@ class ProductCore extends ObjectModel
public function getWsExtraDemands()
{
return Db::getInstance()->getValue(
'SELECT `id_global_demand` as `id` FROM `'._DB_PREFIX_.'htl_room_type_demand` WHERE `id_product` = '.(int)$this->id
$objHotelRoomTypeDemand = new HotelRoomTypeDemand();
$selectedDemands = Db::getInstance()->executeS(
'SELECT `id_global_demand` as `id` FROM `'._DB_PREFIX_.'htl_room_type_demand`
WHERE `id_product` = '.(int)$this->id
);
$res = array();
$demands = $objHotelRoomTypeDemand->getRoomTypeDemands($this->id);
if ($selectedDemands) {
foreach ($selectedDemands as $id_demand => $demand) {
$option['id'] = $demand['id'];
if (isset($demands[$demand['id']]['adv_option']) && count($demands[$demand['id']]['adv_option'])) {
foreach ($demands[$demand['id']]['adv_option'] as $id_option => $adv_option) {
$option['id_option'] = $id_option;
$option['price'] = $adv_option['price_tax_excl'];
$res[] = $option;
}
} else {
$option['id_option'] = false;
$option['price'] = $demand['price_tax_excl'];
$res[] = $option;
}
}
}
return $res;
}
public function getWsServices()
{
return Db::getInstance()->executeS(
'SELECT spp.`price`, spp.`id_tax_rules_group`, sp.`id_product` AS id
FROM `'._DB_PREFIX_.'htl_room_type_service_product` sp
LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp
ON (spp.`id_product` = sp.`id_product` AND spp.`id_element` = sp.`id_element` AND spp.`element_type` = sp.`element_type`)
WHERE sp.`id_element` = '.(int)$this->id
);
}
@@ -6490,4 +6667,106 @@ class ProductCore extends ObjectModel
{
return $this->delete();
}
public function setWsExtraDemands($demands)
{
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'htl_room_type_demand`
WHERE `id_product` = '.(int)$this->id
);
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'htl_room_type_demand_price`
WHERE `id_product` = '.(int)$this->id
);
$objAdvOption = new HotelRoomTypeGlobalDemandAdvanceOption();
$savedDemands = array();
foreach ($demands as $globalDemand) {
if (Validate::isLoadedObject($objGlobalDemand = new HotelRoomTypeGlobalDemand($globalDemand['id']))) {
if (!isset($savedDemands[$globalDemand['id']])) {
$objRoomTypeDemand = new HotelRoomTypeDemand();
$objRoomTypeDemand->id_product = $this->id;
$objRoomTypeDemand->id_global_demand = $objGlobalDemand->id;
$objRoomTypeDemand->save();
$savedDemands[$globalDemand['id']] = $objRoomTypeDemand->id;
}
if (isset($globalDemand['price'])) {
if ($objAdvOption->getGlobalDemandAdvanceOptions($objGlobalDemand->id)
&& isset($globalDemand['id_option'])
&& Validate::isLoadedObject($objAdvOption = new HotelRoomTypeGlobalDemandAdvanceOption($globalDemand['id_option']))
) {
if ($globalDemand['price'] != $objAdvOption->price) {
$objRoomTypeDemandPrice = new HotelRoomTypeDemandPrice();
$objRoomTypeDemandPrice->id_product = $this->id;
$objRoomTypeDemandPrice->id_global_demand = $objGlobalDemand->id;
$objRoomTypeDemandPrice->id_option = $objAdvOption->id;
$objRoomTypeDemandPrice->price = $globalDemand['price'];
$objRoomTypeDemandPrice->save();
}
} else {
// save selected demands prices for this room type
if ($objGlobalDemand->price != $globalDemand['price']) {
$objRoomTypeDemandPrice = new HotelRoomTypeDemandPrice();
$objRoomTypeDemandPrice->id_product = $this->id;
$objRoomTypeDemandPrice->id_global_demand = $objGlobalDemand->id;
$objRoomTypeDemandPrice->id_option = 0;
$objRoomTypeDemandPrice->price = $globalDemand['price'];
$objRoomTypeDemandPrice->save();
}
}
}
}
}
return true;
}
public function setWsServices($services)
{
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'htl_room_type_service_product`
WHERE `id_element` = '.(int)$this->id
);
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'htl_room_type_service_product_price`
WHERE `id_element` = '.(int)$this->id
);
if ($this->booking_product) {
if ($allServiceProducts = $this->getServiceProducts()) {
$formttedServiceProducts = array();
foreach ($allServiceProducts as $product) {
$formttedServiceProducts[$product['id_product']] = $product;
}
$allServiceProducts = $formttedServiceProducts;
foreach ($services as $service) {
if (isset($service['id'])
&& Validate::isLoadedObject($objServiceProduct = new Product($service['id']))
&& !$objServiceProduct->booking_product
&& isset($allServiceProducts[$objServiceProduct->id])
) {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$objRoomTypeServiceProduct->addRoomProductLink(
$objServiceProduct->id,
$this->id,
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
);
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
$objRoomTypeServiceProductPrice->id_product = $objServiceProduct->id;
$objRoomTypeServiceProductPrice->id_element = $this->id;
$objRoomTypeServiceProductPrice->element_type = RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE;
$objRoomTypeServiceProductPrice->price = isset($service['price']) ? $service['price'] : $allServiceProducts[$objServiceProduct->id]['price'];
$objRoomTypeServiceProductPrice->id_tax_rules_group = isset($service['id_tax_rules_group']) ? $service['id_tax_rules_group'] : $allServiceProducts[$objServiceProduct->id]['id_tax_rules_group'];
$objRoomTypeServiceProductPrice->save();
}
}
}
} else {
return false;
}
return true;
}
}