Merge pull request #1929 from amitsharma322/gli-3269

Fixed: Missing support for customer nationality, room selling, and property type in Web Services APIs
This commit is contained in:
Rohit Jain
2026-10-14 19:42:47 +05:30
committed by GitHub
9 changed files with 267 additions and 3 deletions

View File

@@ -147,6 +147,7 @@ class CustomerCore extends ObjectModel
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'id_country' => array('xlink_resource' => 'countries'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),

View File

@@ -427,6 +427,7 @@ class ProductCore extends ObjectModel
// )
// ),
'id_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')),
'id_tourism_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')),
'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => 'setWsPositionInCategory'),
// 'manufacturer_name' => array(
// 'getter' => 'getWsManufacturerName',
@@ -523,6 +524,7 @@ class ProductCore extends ObjectModel
)
),
'id_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')),
'id_tourism_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')),
'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => 'setWsPositionInCategory'),
// 'manufacturer_name' => array(
// 'getter' => 'getWsManufacturerName',

View File

@@ -37,11 +37,65 @@ class RoomTypeSellingObjectCore extends ObjectModel
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true),
'plural_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true),
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
'plural_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
),
);
protected $webserviceParameters = array(
'objectsNodeName' => 'room_type_selling_objects',
'objectNodeName' => 'room_type_selling_object',
'objectMethods' => array('update' => 'updateWs', 'delete' => 'deleteWs'),
'fields' => array(
'name' => array('required' => true),
'plural_name' => array('required' => true),
'active' => array('required' => false),
),
);
/**
* Webservice: update, refusing to disable a selling object that is in use.
*
* @param bool $nullValues
*
* @return bool
*
* @throws WebserviceException
*/
public function updateWs($nullValues = false)
{
if (!$this->active && $this->id) {
$objOld = new RoomTypeSellingObject((int) $this->id);
if (Validate::isLoadedObject($objOld) && $objOld->active && $objOld->isUsed()) {
throw new WebserviceException(
Tools::displayError('You cannot disable this selling object because it is currently assigned.'),
array(400, 400)
);
}
}
return $this->update($nullValues);
}
/**
* Webservice: delete, refusing to delete a selling object that is in use.
*
* @return bool
*
* @throws WebserviceException
*/
public function deleteWs()
{
if ($this->isUsed()) {
throw new WebserviceException(
Tools::displayError('You cannot delete this selling object because it is currently assigned.'),
array(400, 400)
);
}
return $this->delete();
}
public function isUsed()
{
return (bool) Db::getInstance()->getValue(

View File

@@ -40,6 +40,9 @@ class TaxConfigurationCore extends ObjectModel
public $has_multiple_valid_ranges;
public $special_days;
/** @var string Tax name, webservice only (stored in tax_lang) */
public $name;
public static $definition = array(
'table' => 'tax_configuration',
'primary' => 'id_tax',
@@ -57,6 +60,145 @@ class TaxConfigurationCore extends ObjectModel
),
);
protected $webserviceParameters = array(
'objectsNodeName' => 'tourism_taxes',
'objectNodeName' => 'tourism_tax',
'objectMethods' => array(
'add' => 'addWs',
'update' => 'updateWs',
'delete' => 'deleteWs',
),
'fields' => array(
'name' => array('i18n' => false, 'getter' => 'getWsName'),
),
'associations' => array(
'price_tiers' => array(
'resource' => 'price_tier',
'fields' => array('min_amount' => array(), 'max_amount' => array(), 'tax_value' => array()),
),
'child_ranges' => array(
'resource' => 'child_range',
'fields' => array('min_age' => array(), 'max_age' => array(), 'tax_value' => array()),
),
'validity_ranges' => array(
'resource' => 'validity_range',
'fields' => array('valid_from' => array(), 'valid_to' => array()),
),
),
);
/**
* Webservice: add a tourism tax. The tax row is created first, the configuration reuses its id.
*
* @return bool
* @throws WebserviceException
*/
public function addWs()
{
$tax = new Tax();
$tax->is_tourism_tax = 1;
$tax->rate = 0;
$tax->active = 1;
foreach (Language::getIDs(false) as $idLang) {
$tax->name[$idLang] = (string) $this->name;
}
if (($error = $tax->validateFieldsLang(false, true)) !== true) {
throw new WebserviceException(sprintf(Tools::displayError('Validation error: "%s"'), $error), array(400, 400));
}
if (!$tax->add()) {
return false;
}
$this->id = (int) $tax->id;
return $this->add();
}
/**
* Webservice: update the configuration. Like in the admin, Tax::update() historizes a tax already used in
* orders; the tax then gets a new id, so the configuration and its ranges move to it.
*
* @param bool $nullValues
* @return bool
*/
public function updateWs($nullValues = false)
{
$idOldTax = (int) $this->id;
$tax = new Tax($idOldTax);
if (!$tax->update()) {
return false;
}
if ((int) $tax->id === $idOldTax) {
return $this->update($nullValues);
}
$this->id = (int) $tax->id;
$tiers = TaxPriceTier::getByTaxId($idOldTax);
TaxPriceTier::saveAll($this->id, array_column($tiers, 'min_amount'), array_column($tiers, 'max_amount'), array_column($tiers, 'tax_value'));
$childRanges = TaxChildRange::getByTaxId($idOldTax);
TaxChildRange::saveAll($this->id, array_column($childRanges, 'min_age'), array_column($childRanges, 'max_age'), array_column($childRanges, 'tax_value'));
$validityRanges = TaxValidityRange::getByTaxId($idOldTax);
TaxValidityRange::saveAll($this->id, array_column($validityRanges, 'valid_from'), array_column($validityRanges, 'valid_to'));
return $this->add();
}
/**
* Webservice: delete the tax. Tax::delete() only historizes a tax used in orders, so keep its configuration then.
*
* @return bool
*/
public function deleteWs()
{
$tax = new Tax((int) $this->id);
$isUsed = $tax->isUsed();
return $tax->delete() && ($isUsed || $this->delete());
}
/**
* @return string tax name in the default language
*/
public function getWsName()
{
return (new Tax((int) $this->id, (int) Configuration::get('PS_LANG_DEFAULT')))->name;
}
public function getWsPriceTiers()
{
return TaxPriceTier::getByTaxId((int) $this->id);
}
public function setWsPriceTiers($rows)
{
TaxPriceTier::saveAll((int) $this->id, array_column($rows, 'min_amount'), array_column($rows, 'max_amount'), array_column($rows, 'tax_value'));
return true;
}
public function getWsChildRanges()
{
return TaxChildRange::getByTaxId((int) $this->id);
}
public function setWsChildRanges($rows)
{
TaxChildRange::saveAll((int) $this->id, array_column($rows, 'min_age'), array_column($rows, 'max_age'), array_column($rows, 'tax_value'));
return true;
}
public function getWsValidityRanges()
{
return TaxValidityRange::getByTaxId((int) $this->id);
}
public function setWsValidityRanges($rows)
{
TaxValidityRange::saveAll((int) $this->id, array_column($rows, 'valid_from'), array_column($rows, 'valid_to'));
return true;
}
/**
* Override add() because id_tax is a FK-as-PK — the base ObjectModel::add() never writes the primary key column, which would default to 0 and create phantom rows.
*

View File

@@ -267,6 +267,7 @@ class WebserviceRequestCore
'contacts' => array('description' => 'Shop contacts','class' => 'Contact'),
'countries' => array('description' => 'The countries','class' => 'Country'),
'currencies' => array('description' => 'The currencies', 'class' => 'Currency'),
'room_type_selling_objects' => array('description' => 'The room type selling objects', 'class' => 'RoomTypeSellingObject'),
'customers' => array('description' => 'The e-shop\'s customers','class' => 'Customer'),
'customer_threads' => array('description' => 'Customer services threads','class' => 'CustomerThread'),
'customer_messages' => array('description' => 'Customer services messages','class' => 'CustomerMessage'),
@@ -306,6 +307,7 @@ class WebserviceRequestCore
'shops' => array('description' => 'Shops from multi-shop feature', 'class' => 'Shop'),
'shop_groups' => array('description' => 'Shop groups from multi-shop feature', 'class' => 'ShopGroup'),
'taxes' => array('description' => 'The tax rate', 'class' => 'Tax'),
'tourism_taxes' => array('description' => 'The tourism taxes with their configuration, price tiers, child ranges and validity ranges', 'class' => 'TaxConfiguration'),
'stock_movements' => array('description' => 'Stock movements', 'class' => 'StockMvtWS', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
'stock_movement_reasons' => array('description' => 'Stock movement reason', 'class' => 'StockMvtReason'),
'warehouses' => array('description' => 'Warehouses', 'class' => 'Warehouse', 'forbidden_method' => array('DELETE')),

View File

@@ -106,6 +106,10 @@ class HotelBranchInformation extends ObjectModel
'required' => true,
'xlink_resource'=> 'countries',
),
'id_property_type' => array(
'required' => true,
'xlink_resource'=> 'hotel_property_types',
),
'id_state' => array(
'xlink_resource'=> 'states',
),

View File

@@ -36,10 +36,63 @@ class HotelPropertyType extends ObjectModel
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true),
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
),
);
protected $webserviceParameters = array(
'objectsNodeName' => 'property_types',
'objectNodeName' => 'property_type',
'objectMethods' => array('update' => 'updateWs', 'delete' => 'deleteWs'),
'fields' => array(
'name' => array('required' => true),
'active' => array('required' => false),
),
);
/**
* Webservice: update, refusing to disable a property type that is in use.
*
* @param bool $nullValues
*
* @return bool
*
* @throws WebserviceException
*/
public function updateWs($nullValues = false)
{
if (!$this->active && $this->id) {
$objOld = new HotelPropertyType((int) $this->id);
if (Validate::isLoadedObject($objOld) && $objOld->active && $objOld->isUsed()) {
throw new WebserviceException(
Tools::displayError('You cannot disable this property type because it is currently assigned.'),
array(400, 400)
);
}
}
return $this->update($nullValues);
}
/**
* Webservice: delete, refusing to delete a property type that is in use.
*
* @return bool
*
* @throws WebserviceException
*/
public function deleteWs()
{
if ($this->isUsed()) {
throw new WebserviceException(
Tools::displayError('You cannot delete this property type because it is currently assigned.'),
array(400, 400)
);
}
return $this->delete();
}
/**
* Check if this property type is currently assigned to any property.
*

View File

@@ -72,6 +72,11 @@ class HotelRoomType extends ObjectModel
'resourceName' => 'hotels',
)
),
'id_selling_object' => array(
'xlink_resource' => array(
'resourceName' => 'room_type_selling_objects',
)
),
),
'associations' => array(
'hotel_rooms' => array(

View File

@@ -48,6 +48,7 @@ class HotelReservationSystem extends Module
$resources = array(
'hotels' => array('description' => 'Hotel Branch Information','class' => 'HotelBranchInformation'),
'hotel_room_types' => array('description' => 'Hotel room types','class' => 'HotelRoomType'),
'property_types' => array('description' => 'Hotel property types', 'class' => 'HotelPropertyType'),
'hotel_amenities' => array('description' => 'The hotel amenities', 'class' => 'HotelAmenities'),
'hotel_refund_rules' => array('description' => 'The hotel refund rules','class' => 'HotelOrderRefundRules'),
'hotel_rooms' => array('description' => 'The hotel rooms','class' => 'HotelRoomInformation'),