Fixed: added stock wise restrictions on standalone service products
This commit is contained in:
@@ -474,7 +474,7 @@ class CartControllerCore extends FrontController
|
||||
$finalQuantity += $quantityInCart;
|
||||
}
|
||||
if ($product->max_quantity && $finalQuantity > $product->max_quantity) {
|
||||
$this->errors[] = Tools::displayError(sprintf('You can now add more than %d quantity for this product in the cart.', $product->max_quantity));
|
||||
$this->errors[] = Tools::displayError(sprintf('You cannot add more than %d quantity for this product in the cart.', $product->max_quantity));
|
||||
}
|
||||
} else {
|
||||
if ($id_cart) {
|
||||
@@ -517,7 +517,7 @@ class CartControllerCore extends FrontController
|
||||
$finalQuantity += $productCartDetail['quantity'];
|
||||
}
|
||||
if ($product->max_quantity && $finalQuantity > $product->max_quantity) {
|
||||
$this->errors[] = Tools::displayError(sprintf('You can not add more than %d quantity for this product in the cart.', $product->max_quantity));
|
||||
$this->errors[] = Tools::displayError(sprintf('You cannot add more than %d quantity for this product in the cart.', $product->max_quantity));
|
||||
}
|
||||
} elseif ($productCartDetail) {
|
||||
$this->errors[] = Tools::displayError('You can only order one quantity for this product.');
|
||||
|
||||
@@ -496,6 +496,15 @@ class ProductControllerCore extends FrontController
|
||||
$this->context->smarty->assign('error', Tools::getValue('error'));
|
||||
}
|
||||
} else {
|
||||
if ($this->product->allow_multiple_quantity) {
|
||||
if ($products = $this->context->cart->getProducts()) {
|
||||
$products = array_column($products, 'cart_quantity', 'id_product');
|
||||
if (isset($products[$this->product->id])) {
|
||||
$this->product->quantity -= $products[$this->product->id];
|
||||
$this->product->max_quantity -= $products[$this->product->id];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assignServiceProductVars();
|
||||
}
|
||||
|
||||
|
||||
@@ -432,6 +432,10 @@ var ajaxCart = {
|
||||
|
||||
resetRoomtypeServices();
|
||||
|
||||
if (parseInt($('#product_page_booking_product').val()) == 0) {
|
||||
$('#service_product_qty').val(1);
|
||||
}
|
||||
|
||||
BookingForm.refresh(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -245,16 +245,25 @@
|
||||
{/if}
|
||||
{/block}
|
||||
{block name='booking_form_service_product_quantity'}
|
||||
{assign var='is_out_of_stock' value=false}
|
||||
{assign var='max_qty_reached' value=false}
|
||||
{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE}
|
||||
{assign var='is_out_of_stock' value=true}
|
||||
{else if $product->allow_multiple_quantity && !$product->max_quantity}
|
||||
{assign var='max_qty_reached' value=true}
|
||||
{/if}
|
||||
|
||||
{if $product->allow_multiple_quantity}
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6" id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
|
||||
<div class="form-group col-sm-6" id="quantity_wanted_p"{if $is_out_of_stock || $max_qty_reached} style="display: none;"{/if}>
|
||||
<label for="quantity_wanted_p">{l s='Quantity'}</label>
|
||||
{* {block name='quantity_field'}
|
||||
{include file="./quantity_field.tpl"}
|
||||
{/block} *}
|
||||
|
||||
<div class="qty_container">
|
||||
<input type="hidden" class="service_product_qty" id="service_product_qty" name="service_product_qty" data-id-product="{$product->id}" data-max_quantity="{if isset($product->max_quantity) && $product->max_quantity}{$product->max_quantity|escape:'html':'UTF-8'}{else}{$product->quantity}{/if}" value="{if isset($quantity)}{$quantity|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}">
|
||||
<input type="hidden" class="stock_qty" id="stock_qty" name="stock_qty" data-id-product="{$product->id}" data-stock_quantity="{$product->quantity}" >
|
||||
<input type="hidden" class="service_product_qty" id="service_product_qty" name="service_product_qty" data-id-product="{$product->id}" data-max_quantity="{if isset($product->max_quantity)}{$product->max_quantity|escape:'html':'UTF-8'}{else}{$product->quantity}{/if}" value="{if isset($quantity)}{$quantity|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}">
|
||||
<div class="qty_count pull-left">
|
||||
<span>{if isset($quantity)}{$quantity|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}</span>
|
||||
</div>
|
||||
@@ -266,7 +275,7 @@
|
||||
<span class="clearfix"></span>
|
||||
</div>
|
||||
</div>
|
||||
{if $product->available_for_order}
|
||||
{if !$is_out_of_stock || !$max_qty_reached}
|
||||
<hr class="separator-hr-mg-10">
|
||||
{/if}
|
||||
{else}
|
||||
@@ -301,7 +310,14 @@
|
||||
{/block}
|
||||
</div>
|
||||
<div>
|
||||
{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE}
|
||||
{if $is_out_of_stock}
|
||||
<div class="sold_out_alert">
|
||||
<span>{l s='Product is out of stock!'}</span>
|
||||
</div>
|
||||
{else if $max_qty_reached}
|
||||
<div class="sold_out_alert">
|
||||
<span>{l s='Max quantity reached!'}</span>
|
||||
</div>
|
||||
{else}
|
||||
{block name='booking_form_book_now_button'}
|
||||
<p id="add_to_cart" class="buttons_bottom_block no-print">
|
||||
|
||||
@@ -432,6 +432,10 @@ var ajaxCart = {
|
||||
|
||||
resetRoomtypeServices();
|
||||
|
||||
if (parseInt($('#product_page_booking_product').val()) == 0) {
|
||||
$('#service_product_qty').val(1);
|
||||
}
|
||||
|
||||
BookingForm.refresh(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1206,13 +1206,23 @@ $(document).ready(function() {
|
||||
e.preventDefault();
|
||||
qtyfield = $(this).closest('.qty_container').find('input.service_product_qty');
|
||||
var newQuantity = parseInt(qtyfield.val()) + 1;
|
||||
if (qtyfield.data('max_quantity') && qtyfield.data('max_quantity') < newQuantity) {
|
||||
// if max quantity is reached
|
||||
newQuantity = qtyfield.data('max_quantity');
|
||||
|
||||
showErrorMessage(max_service_product_qty_txt+' '+qtyfield.data('max_quantity'));
|
||||
let hasStockError = false;
|
||||
if (parseInt($('#product_page_booking_product').val()) == 0) {
|
||||
let stockQty = parseInt($(this).closest('.qty_container').find('.stock_qty').data('stock_quantity'));
|
||||
if (stockQty < newQuantity) {
|
||||
showErrorMessage(out_of_stock_text);
|
||||
newQuantity = stockQty;
|
||||
}
|
||||
}
|
||||
if (!hasStockError) {
|
||||
if (qtyfield.data('max_quantity') && qtyfield.data('max_quantity') < newQuantity) {
|
||||
// if max quantity is reached
|
||||
newQuantity = qtyfield.data('max_quantity');
|
||||
|
||||
showErrorMessage(max_service_product_qty_txt+' '+qtyfield.data('max_quantity'));
|
||||
}
|
||||
$(this).closest('.qty_container').find('.qty_count span').text(newQuantity);
|
||||
}
|
||||
$(this).closest('.qty_container').find('.qty_count span').text(newQuantity);
|
||||
qtyfield.val(newQuantity);
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function() {
|
||||
|
||||
@@ -877,6 +877,7 @@
|
||||
{addJsDefL name=service_removed_txt}{l s='Service removed' js=1}{/addJsDefL}
|
||||
{addJsDefL name=service_updated_txt}{l s='Service updated' js=1}{/addJsDefL}
|
||||
{addJsDefL name=max_service_product_qty_txt}{l s='Maximum allowed quantity in the cart is' js=1}{/addJsDefL}
|
||||
{addJsDefL name=out_of_stock_text}{l s='Requested quantitity is out of stock' js=1}{/addJsDefL}
|
||||
{/strip}
|
||||
{/block}
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user