Fixed: Added cart booking ID to specific cart rules to apply price rules based on individual cart bookings.

This commit is contained in:
vishalsingh.qlo325
2025-07-03 13:23:49 +05:30
parent 569c093b00
commit 031f1e9824
7 changed files with 88 additions and 24 deletions

View File

@@ -44,11 +44,18 @@
</thead>
<tbody>
{foreach $serviceProducts as $product}
{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}
{assign var='serviceSelected' value=true}
{$product.price_tax_incl = $selectedRoomServiceProduct['selected_service'][$product['id_product']]['unit_price_tax_incl']}
{$product.price_tax_exc = $selectedRoomServiceProduct['selected_service'][$product['id_product']]['unit_price_tax_excl']}
{else}
{assign var='serviceSelected' value=false}
{/if}
<tr class="room_demand_block">
<td>
<input data-id_cart_booking="{$selectedRoomServiceProduct['id']}" value="{$product['id_product']|escape:'html':'UTF-8'}" type="checkbox" class="change_room_type_service_product" {if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}checked{/if}/>
<input data-id_cart_booking="{$selectedRoomServiceProduct['id']}" value="{$product['id_product']|escape:'html':'UTF-8'}" type="checkbox" class="change_room_type_service_product" {if $serviceSelected}checked{/if}/>
<input id="selected_service_product_{$product['id_product']}" type="hidden" value="{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}1{else}0{/if}" name="selected_service_product[{$product.id_product}]"/>
<input id="selected_service_product_{$product['id_product']}" type="hidden" value="{if $serviceSelected}1{else}0{/if}" name="selected_service_product[{$product.id_product}]"/>
</td>
<td>
<p>{$product['name']|escape:'html':'UTF-8'}</p>
@@ -64,9 +71,9 @@
<td>
{if $product.allow_multiple_quantity}
<div class="qty_container">
<input type="number" class="form-control room_type_service_product_qty qty" id="qty_{$product.id_product}" name="service_qty[{$product.id_product}]" data-id-product="{$product.id_product}" min="1" data-max-quantity="{$product.max_quantity}" value="{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}{$selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity']}{else}1{/if}" name="service_qty[{$product['id_product']|escape:'html':'UTF-8'}]">
<input type="number" class="form-control room_type_service_product_qty qty" id="qty_{$product.id_product}" name="service_qty[{$product.id_product}]" data-id-product="{$product.id_product}" min="1" data-max-quantity="{$product.max_quantity}" value="{if $serviceSelected}{$selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity']}{else}1{/if}" name="service_qty[{$product['id_product']|escape:'html':'UTF-8'}]">
<p style="display:{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity'] > $product.max_quantity}block{else}none{/if}; margin-top: 4px;">
<p style="display:{if $serviceSelected && $selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity'] > $product.max_quantity}block{else}none{/if}; margin-top: 4px;">
<span class="label label-warning">{l s='Maximum allowed quantity: %s' sprintf=$product.max_quantity}</span>
</p>
</div>

View File

@@ -3042,7 +3042,7 @@ class ProductCore extends ObjectModel
public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null,
$only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null,
$id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, ?Context $context = null,
$use_customer_price = true, $id_hotel = false, $id_product_room_type = false, $id_group = null)
$use_customer_price = true, $id_hotel = false, $id_product_room_type = false, $id_group = null, $id_cart_booking_data = 0)
{
if (!$context) {
$context = Context::getContext();
@@ -3177,7 +3177,8 @@ class ProductCore extends ObjectModel
$id_cart,
$cart_quantity,
$id_hotel,
$id_product_room_type
$id_product_room_type,
$id_cart_booking_data
);
return $return;
@@ -3211,7 +3212,7 @@ class ProductCore extends ObjectModel
**/
public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency,
$id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction,
$id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_hotel = false, $id_product_room_type = false)
$id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_hotel = false, $id_product_room_type = false, $id_cart_booking_data = 0)
{
static $address = null;
static $context = null;
@@ -3246,7 +3247,8 @@ class ProductCore extends ObjectModel
$cache_id = (int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.$id_state.'-'.$zipcode.'-'.(int)$id_group.
'-'.(int)$quantity.'-'.(int)$id_product_attribute.
'-'.(int)$with_ecotax.'-'.(int)$id_customer.'-'.(int)$use_group_reduction.'-'.(int)$id_cart.'-'.(int)$real_quantity.
'-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.($use_tax?'1':'0').'-'.(int)$decimals.'-'.($id_hotel?(int)$id_hotel:'0').'-'.($id_product_option?(int)$id_product_option:'0'.'-'.($id_product_room_type?(int)$id_product_room_type:'0'));
'-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.($use_tax?'1':'0').'-'.(int)$decimals.'-'.($id_hotel?(int)$id_hotel:'0')
.'-'.($id_product_option?(int)$id_product_option:'0'.'-'.($id_product_room_type?(int)$id_product_room_type:'0').'-'.(int)$id_cart_booking_data);
// reference parameter is filled before any returns
$specific_price = SpecificPrice::getSpecificPrice(
@@ -3259,7 +3261,8 @@ class ProductCore extends ObjectModel
$id_product_option,
$id_customer,
$id_cart,
$real_quantity
$real_quantity,
$id_cart_booking_data
);
if (isset(self::$_prices[$cache_id])) {
@@ -6815,7 +6818,9 @@ class ProductCore extends ObjectModel
$dateTo = null,
$idCart = false,
$idAddress = null,
$useReduc = 1
$useReduc = 1,
$idGroup = null,
$idCartBooking = 0
) {
if ($useTax === null) {
$useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true;
@@ -6840,7 +6845,9 @@ class ProductCore extends ObjectModel
null,
true,
(int)$idHotel,
(int)$idProductRoomType
(int)$idProductRoomType,
$idGroup,
$idCartBooking
);
Hook::exec('actionServiceProductPricePriceModifier',
@@ -6854,7 +6861,8 @@ class ProductCore extends ObjectModel
'date_to' => $dateTo,
'use_tax' => $useTax,
'id_cart' => $idCart,
'use_reduc' => $useReduc
'use_reduc' => $useReduc,
'id_cart_booking_data' => $idCartBooking
)
);

View File

@@ -43,6 +43,7 @@ class SpecificPriceCore extends ObjectModel
public $reduction_type;
public $from;
public $to;
public $id_cart_booking_data;
/**
* @see ObjectModel::$definition
@@ -68,6 +69,7 @@ class SpecificPriceCore extends ObjectModel
'reduction_type' => array('type' => self::TYPE_STRING, 'validate' => 'isReductionType', 'required' => true),
'from' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'required' => true),
'to' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'required' => true),
'id_cart_booking_data' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
),
);
@@ -345,7 +347,7 @@ class SpecificPriceCore extends ObjectModel
}
}
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null, $id_customer = 0, $id_cart = 0, $real_quantity = 0, $id_room = 0)
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null, $id_customer = 0, $id_cart = 0, $real_quantity = 0, $id_cart_booking_data = 0)
{
if (!SpecificPrice::isFeatureActive()) {
return array();
@@ -355,7 +357,7 @@ class SpecificPriceCore extends ObjectModel
** The price must not change between the top and the bottom of the page
*/
$key = ((int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.(int)$id_group.'-'.(int)$quantity.'-'.(int)$id_product_attribute.'-'.(int)$id_cart.'-'.(int)$id_customer.'-'.(int)$real_quantity);
$key = ((int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.(int)$id_group.'-'.(int)$quantity.'-'.(int)$id_product_attribute.'-'.(int)$id_cart.'-'.(int)$id_customer.'-'.(int)$real_quantity.'-'.(int) $id_cart_booking_data);
if (!array_key_exists($key, SpecificPrice::$_specificPriceCache)) {
$query_extra = self::computeExtraConditions($id_product, $id_product_attribute, $id_customer, $id_cart);
$query = '
@@ -365,6 +367,7 @@ class SpecificPriceCore extends ObjectModel
`id_shop` '.self::formatIntInQuery(0, $id_shop).' AND
`id_currency` '.self::formatIntInQuery(0, $id_currency).' AND
`id_country` '.self::formatIntInQuery(0, $id_country).
' AND `id_cart_booking_data`='.(int)$id_cart_booking_data.' '.
(Group::isFeatureActive() ? ' AND `id_group` '.self::formatIntInQuery(0, $id_group) : '').' '.$query_extra.'
AND IF(`from_quantity` > 1, `from_quantity`, 0) <= ';

View File

@@ -1663,8 +1663,10 @@ class AdminCartsControllerCore extends AdminController
0,
1,
0,
$objCart->id_customer,
$objCart->id
0,
$objCart->id,
0,
$objHotelCartBookingData->id
)) {
$objSpecificPrice = new SpecificPrice($specificPriceInfo['id_specific_price']);
} else {
@@ -1676,12 +1678,13 @@ class AdminCartsControllerCore extends AdminController
$objSpecificPrice->id_currency = $objCart->id_currency;
$objSpecificPrice->id_country = 0;
$objSpecificPrice->id_group = 0;
$objSpecificPrice->id_customer = $objCart->id_customer;
$objSpecificPrice->id_customer = 0;
$objSpecificPrice->id_product = $idServiceProduct;
$objSpecificPrice->id_product_attribute = 0;
$objSpecificPrice->price = $unitPrice;
$objSpecificPrice->from_quantity = 1;
$objSpecificPrice->reduction = 0;
$objSpecificPrice->id_cart_booking_data = $objHotelCartBookingData->id;
$objSpecificPrice->reduction_type = 'amount';
$objSpecificPrice->reduction_tax = 0;
$objSpecificPrice->from = '0000-00-00 00:00:00';

View File

@@ -1888,6 +1888,7 @@ CREATE TABLE `PREFIX_specific_price` (
`id_country` INT UNSIGNED NOT NULL,
`id_group` INT UNSIGNED NOT NULL,
`id_customer` INT UNSIGNED NOT NULL,
`id_cart_booking_data` INT UNSIGNED NOT NULL,
`id_product_attribute` INT UNSIGNED NOT NULL,
`price` DECIMAL(20, 6) NOT NULL,
`from_quantity` mediumint(8) UNSIGNED NOT NULL,

View File

@@ -237,7 +237,11 @@ class ServiceProductCartDetail extends ObjectModel
$qty,
$product['date_from'],
$product['date_to'],
$idCart
$idCart,
null,
1,
null,
$product['htl_cart_booking_id']
);
} else {
$numDays = 1;
@@ -257,7 +261,11 @@ class ServiceProductCartDetail extends ObjectModel
1,
$product['date_from'],
$product['date_to'],
$idCart
$idCart,
null,
1,
null,
$product['htl_cart_booking_id']
)/$numDays;
$priceTaxExcl = Product::getServiceProductPrice(
$objProduct->id,
@@ -268,7 +276,11 @@ class ServiceProductCartDetail extends ObjectModel
1,
$product['date_from'],
$product['date_to'],
$idCart
$idCart,
null,
1,
null,
$product['htl_cart_booking_id']
)/$numDays;
$optionDetails = false;
@@ -527,6 +539,29 @@ class ServiceProductCartDetail extends ObjectModel
return true;
}
public function delete()
{
$objCart = new Cart($this->id_cart);
if ($specificPriceInfo = SpecificPrice::getSpecificPrice(
(int)$this->id_product,
0,
$objCart->id_currency,
0,
0,
1,
0,
0,
$objCart->id,
0,
$this->htl_cart_booking_id
)) {
$objSpecificPrice = new SpecificPrice($specificPriceInfo['id_specific_price']);
$objSpecificPrice->delete();
}
return parent::delete();
}
public static function validateServiceProductsInCart()
{
$context = Context::getContext();

View File

@@ -26,7 +26,7 @@
<li class="active"><a href="#room_type_demands_desc" data-toggle="tab">{l s='Facilities'}</a></li>
{/if}
{if isset($roomTypeServiceProducts) && $roomTypeServiceProducts}
<li{if !isset($selectedRoomDemands) || !$selectedRoomDemands} class="active"{/if}><a href="#room_type_service_product_desc" data-toggle="tab">{l s='Services'}</a></li>
<li {if !isset($selectedRoomDemands) || !$selectedRoomDemands} class="active"{/if}><a href="#room_type_service_product_desc" data-toggle="tab">{l s='Services'}</a></li>
{/if}
</ul>
{/block}
@@ -113,13 +113,20 @@
<div id="accordion_service_{$key|escape:'html':'UTF-8'}" class=" col-sm-12 room_demand_detail accordion-section-content {if $roomCount == 1}open{/if}" {if $roomCount == 1}style="display: block;"{/if}>
{if isset($roomTypeServiceProducts) && $roomTypeServiceProducts}
{foreach $roomTypeServiceProducts as $product}
{if isset($cartRoom['selected_service']) && $cartRoom['selected_service'] && ($product['id_product']|array_key_exists:$cartRoom['selected_service'])}
{assign var='serviceSelected' value=true}
{$product.price_tax_incl = $cartRoom['selected_service'][$product['id_product']]['unit_price_tax_incl']}
{$product.price_tax_exc = $cartRoom['selected_service'][$product['id_product']]['unit_price_tax_excl']}
{else}
{assign var='serviceSelected' value=false}
{/if}
<div class="row room_demand_block">
<div class="col-xs-8">
<div class="row">
<div class="col-xs-2">
{if $product.available_for_order}
<p class="checkbox">
<input data-id_cart_booking="{$cartRoom['id']}" value="{$product['id_product']|escape:'html':'UTF-8'}" type="checkbox" class="change_room_type_service_product" {if isset($cartRoom['selected_service']) && $cartRoom['selected_service'] && ($product['id_product']|array_key_exists:$cartRoom['selected_service'])}checked{/if} />
<input data-id_cart_booking="{$cartRoom['id']}" value="{$product['id_product']|escape:'html':'UTF-8'}" type="checkbox" class="change_room_type_service_product" {if $serviceSelected}checked{/if} />
</p>
{/if}
</div>
@@ -127,8 +134,8 @@
<p>{$product['name']|escape:'html':'UTF-8'}</p>
{if $product.allow_multiple_quantity}
<div class="qty_container">
<input type="text" class="form-control qty" id="qty_{$product.id_product}" name="room_service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" data-max_quantity="{$product.max_quantity}" value="{if isset($cartRoom['selected_service']) && $cartRoom['selected_service'] && ($product['id_product']|array_key_exists:$cartRoom['selected_service'])}{$cartRoom['selected_service'][$product['id_product']]['quantity']}{else}1{/if}">
<input type="hidden" class="qty_hidden" id="qty_{$product.id_product}_hidden" value="{if isset($cartRoom['selected_service']) && $cartRoom['selected_service'] && ($product['id_product']|array_key_exists:$cartRoom['selected_service'])}{$cartRoom['selected_service'][$product['id_product']]['quantity']}{else}0{/if}">
<input type="text" class="form-control qty" id="qty_{$product.id_product}" name="room_service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" data-max_quantity="{$product.max_quantity}" value="{if $serviceSelected}{$cartRoom['selected_service'][$product['id_product']]['quantity']}{else}1{/if}">
<input type="hidden" class="qty_hidden" id="qty_{$product.id_product}_hidden" value="{if $serviceSelected}{$cartRoom['selected_service'][$product['id_product']]['quantity']}{else}0{/if}">
<div class="qty_controls">
<a href="#" class="qty_up"><span><i class="icon-plus"></i></span></a>
<a href="#" class="qty_down"><span><i class="icon-minus"></i></span></a>