Fixed: Cart quantity and Order edit issues

This commit is contained in:
Sumit Panwar
2025-04-01 21:03:30 +05:30
parent 4e6e0b494c
commit c49fd5a83e
8 changed files with 58 additions and 37 deletions

View File

@@ -213,7 +213,7 @@
{/if}
{/if}
<div class="panel-footer">
<a href="{$link->getAdminLink('AdminProducts')|escape:'html':'UTF-8'}{if isset($smarty.request.page) && $smarty.request.page > 1}&amp;submitFilterproduct={$smarty.request.page|intval}{/if}" class="btn btn-default"><i class="process-icon-cancel"></i> {l s='Cancel'}</a>
<a href="{$link->getAdminLink('AdminNormalProducts')|escape:'html':'UTF-8'}{if isset($smarty.request.page) && $smarty.request.page > 1}&amp;submitFilterproduct={$smarty.request.page|intval}{/if}" class="btn btn-default"><i class="process-icon-cancel"></i> {l s='Cancel'}</a>
<button type="submit" name="submitAddproduct" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i></i> {l s='Save'}</button>
<button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> {l s='Save and stay'}</button>
</div>

View File

@@ -3248,7 +3248,7 @@ class ProductCore extends ObjectModel
(int)$context->country->id,
$id_group,
$quantity,
$id_product_attribute,
$id_product_option,
$id_customer,
$id_cart,
$real_quantity
@@ -3335,7 +3335,10 @@ class ProductCore extends ObjectModel
$price = (float)$specific_price['price'];
}
if (isset($result['option_impact_price'])) {
// add option impact only if specific price is not set for this option
if ((!$specific_price || !$specific_price['id_product_attribute'] || $specific_price['price'] < 0)
&& isset($result['option_impact_price'])
) {
$price += (float)$result['option_impact_price'];
}
@@ -3356,9 +3359,6 @@ class ProductCore extends ObjectModel
}
}
// find and add if any auto_add services are attached
Hook::exec(
'actionProductPriceModifier',
array(

View File

@@ -5056,6 +5056,7 @@ class AdminOrdersControllerCore extends AdminController
$idOrder = (int) Tools::getValue('id_order');
$idProduct = $productInformations['product_id'];
$objOrder = new Order($idOrder);
$idProductOption = null;
$addressTax = new Address($objOrder->id_address_tax, $this->context->language->id);
if (!$this->tabAccess['edit'] == 1) {
$response['status'] = false;
@@ -5075,12 +5076,17 @@ class AdminOrdersControllerCore extends AdminController
} elseif (!Validate::isLoadedObject($objProduct = new Product($idProduct, false, $objOrder->id_lang))) {
$response['status'] = false;
$response['error'] = Tools::displayError('The product object cannot be loaded.');
} elseif ($objProduct->selling_preference_type != Product::SELLING_PREFERENCE_STANDALONE) {
if (!$addressTax->id_hotel
|| !Validate::isLoadedObject($objHotel = new HotelBranchInformation($addressTax->id_hotel))
) {
$response['status'] = false;
$response['error'] = Tools::displayError('The hotel object cannot be loaded.');
} elseif ($objProduct->selling_preference_type != Product::SELLING_PREFERENCE_STANDALONE
&& (!$addressTax->id_hotel
|| !Validate::isLoadedObject($objHotel = new HotelBranchInformation($addressTax->id_hotel)))
) {
$response['status'] = false;
$response['error'] = Tools::displayError('The hotel object cannot be loaded.');
} elseif (ServiceProductOption::productHasOptions($idProduct)) {
if (!$productInformations['product_option']) {
$this->errors[] = Tools::displayError('Cannot add service without a option.');
} else {
$idProductOption = $productInformations['product_option'];
}
}
@@ -5111,7 +5117,7 @@ class AdminOrdersControllerCore extends AdminController
$initialProductPriceTI = Product::getPriceStatic(
$idProduct,
$useTaxes,
null,
$idProductOption,
2,
null,
false,
@@ -5131,9 +5137,10 @@ class AdminOrdersControllerCore extends AdminController
$objSpecificPrice->id_currency = 0;
$objSpecificPrice->id_country = 0;
$objSpecificPrice->id_group = 0;
$objSpecificPrice->id_cart = $objCart->id;
$objSpecificPrice->id_customer = $objOrder->id_customer;
$objSpecificPrice->id_product = $idProduct;
$objSpecificPrice->id_product_attribute = 0;
$objSpecificPrice->id_product_attribute = $idProductOption;
$objSpecificPrice->price = $productInformations['product_price_tax_excl'];
$objSpecificPrice->from_quantity = 1;
$objSpecificPrice->reduction = 0;
@@ -6213,7 +6220,7 @@ class AdminOrdersControllerCore extends AdminController
$idOrder = Tools::getValue('id_order');
$idOrderDetail = Tools::getValue('id_order_detail');
$idProductOrderDetail = Tools::getValue('id_service_product_order_detail');
$idServiceProdOrderDetail = Tools::getValue('id_service_product_order_detail');
$objOrder = new Order($idOrder);
$objOrderDetail = new OrderDetail($idOrderDetail);
@@ -6227,7 +6234,7 @@ class AdminOrdersControllerCore extends AdminController
$response['status'] = false;
$response['error'] = Tools::displayError('Product information not found.');
} elseif (!Validate::isLoadedObject(
$objServiceProductOrderDetail = new ServiceProductOrderDetail($idProductOrderDetail)
$objServiceProductOrderDetail = new ServiceProductOrderDetail($idServiceProdOrderDetail)
)) {
$response['status'] = false;
$response['error'] = Tools::displayError('Product information not found.');
@@ -6255,26 +6262,26 @@ class AdminOrdersControllerCore extends AdminController
$objOrderDetail->reinjectQuantity($objOrderDetail, $qty, true);
} else {
$objOrderDetail->reinjectQuantity($objOrderDetail, $qty);
$objOrderDetail->total_paid_tax_excl -= $total_price_tax_excl;
$objOrderDetail->total_paid_tax_incl -= $total_price_tax_incl;
$objOrderDetail->total_price_tax_incl -= (float)$total_price_tax_incl;
$objOrderDetail->total_price_tax_excl -= (float)$total_price_tax_excl;
$objOrderDetail->product_quantity -= $qty;
$objOrderDetail->update();
}
$result &= $objServiceProductOrderDetail->delete();
if ($result &= $objServiceProductOrderDetail->delete()) {
// Update Order
$objOrder->total_paid = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_incl = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_excl = Tools::ps_round($objOrder->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
// Update Order
$objOrder->total_paid = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_incl = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_excl = Tools::ps_round($objOrder->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_products -= $total_price_tax_excl;
$objOrder->total_products = $objOrder->total_products > 0 ? $objOrder->total_products : 0;
$objOrder->total_products -= $total_price_tax_excl;
$objOrder->total_products = $objOrder->total_products > 0 ? $objOrder->total_products : 0;
$objOrder->total_products_wt -= $total_price_tax_incl;
$objOrder->total_products_wt = $objOrder->total_products_wt > 0 ? $objOrder->total_products_wt : 0;
$objOrder->total_products_wt -= $total_price_tax_incl;
$objOrder->total_products_wt = $objOrder->total_products_wt > 0 ? $objOrder->total_products_wt : 0;
$result &= $objOrder->update();
$result &= $objOrder->update();
}
if (!$result) {
$response['status'] = false;

View File

@@ -474,7 +474,7 @@ class CartControllerCore extends FrontController
$finalQuantity += $quantityInCart;
}
if ($product->max_quantity && $finalQuantity > $product->max_quantity) {
$this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $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));
}
} 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('cannot add more than %d quantity.', $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));
}
} elseif ($productCartDetail) {
$this->errors[] = Tools::displayError('You can only order one quantity for this product.');
@@ -536,7 +536,7 @@ class CartControllerCore extends FrontController
}
}
} else {
$this->errors[] = Tools::displayError('cannot add product without room in cart');
$this->errors[] = Tools::displayError('Can not add product without room in cart');
}
}

View File

@@ -425,8 +425,6 @@ function initProductEvents()
var tax_rate = current_product.tax_rate / 100 + 1;
console.log(current_product);
$('#add_product_product_price_tax_incl').val(ps_round(price_tax_excl * tax_rate, 2));
});

View File

@@ -219,7 +219,10 @@ class ServiceProductCartDetail extends ObjectModel
$product['id_hotel'],
false,
$useTax,
$qty
$qty,
null,
null,
$idCart
);
} else {
$context = Context::getContext();
@@ -228,15 +231,24 @@ class ServiceProductCartDetail extends ObjectModel
$product['id_product_option'],
$product['id_hotel'],
false,
true
true,
1,
null,
null,
$idCart
);
$priceTaxExcl = Product::getServiceProductPrice(
$objProduct->id,
$product['id_product_option'],
$product['id_hotel'],
false,
false
false,
1,
null,
null,
$idCart
);
$optionDetails = false;
if (ServiceProductOption::productHasOptions($product['id_product'])) {
$optionDetails = $objServiceProductOption->getProductOptions(

View File

@@ -1207,7 +1207,10 @@ $(document).ready(function() {
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'));
}
$(this).closest('.qty_container').find('.qty_count span').text(newQuantity);
qtyfield.val(newQuantity);

View File

@@ -860,6 +860,7 @@
{addJsDefL name=service_added_txt}{l s='Service added' js=1}{/addJsDefL}
{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}
{/strip}
{/block}
{/if}