Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/js/components/useQuantityInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,32 @@ const updateQuantity = async (qtyInputGroup: Theme.QuantityInput.InputGroup, cha
const errors = data.errors as string;

if (errors) {
useToast(errors, {type: 'warning', autohide: false}).show();
useToast(errors, {type: 'danger', autohide: false}).show();
}
prestashop.emit(events.updateCart, {
reason: qtyInput.dataset,
resp: data,
});
}

// we check if the quantity is more than wanted and if oosp is disabled
// to recall with the correct number we can have
if (data.cart?.products?.length > 0) {
const productData = data.cart.products.find(
(product: Record<string, unknown>) => data.id_product === Number(product.id_product)
&& data.id_product_attribute === Number(product.id_product_attribute));

if (productData) {
if (productData.availability === 'unavailable'
&& productData.allow_oosp === 0
&& Number(productData.quantity_wanted) > Number(productData.stock_quantity)) {
const diff = Number(productData.stock_quantity) - Number(productData.quantity_wanted);
await sendUpdateCartRequest(productData.update_quantity_url as string, diff);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (productData) {
if (productData.availability === 'unavailable'
&& productData.allow_oosp === 0
&& Number(productData.quantity_wanted) > Number(productData.stock_quantity)) {
const diff = Number(productData.stock_quantity) - Number(productData.quantity_wanted);
await sendUpdateCartRequest(productData.update_quantity_url as string, diff);
}
}
if (productData
&& productData.availability === 'unavailable'
&& productData.allow_oosp === 0
&& Number(productData.quantity_wanted) > Number(productData.stock_quantity)) {
const diff = Number(productData.stock_quantity) - Number(productData.quantity_wanted);
await sendUpdateCartRequest(productData.update_quantity_url as string, diff);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion, your solution looks more readable 🔥

}

prestashop.emit(events.updateCart, {
reason: qtyInput.dataset,
resp: data,
});

// Change the input value based on returned quantity
qtyInput.value = data.quantity;
// If user used the confirmation mode, need to update input value in the DOM
Expand Down
7 changes: 6 additions & 1 deletion src/js/pages/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,14 @@ const initCheckout = () => {

const setMaxHeightToActiveCarrierExtraContent = () => {
const activeExtraContent = document.querySelector(`${CheckoutMap.carrierExtraContentActive}`) as HTMLElement;

if (activeExtraContent === null) {
return;
}

const content = activeExtraContent.querySelector(CheckoutMap.carrierExtraContent) as HTMLElement;

if (activeExtraContent != null && content != null) {
if (content != null) {
activeExtraContent.style.maxHeight = `${content.clientHeight}px`;
}
};
Expand Down
12 changes: 9 additions & 3 deletions templates/checkout/_partials/cart-detailed-actions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
* file that was distributed with this source code.
*}
{block name='cart_detailed_actions'}
{$disableCheckout = false}
{foreach $cart.products as $product}
{if isset($product.availability) && $product.availability == 'unavailable' }
{$disableCheckout = true}
{/if}
{/foreach}
<div class="checkout cart-detailed__actions js-cart-detailed-actions card-footer">
{if $cart.minimalPurchaseRequired}
<div class="alert alert-warning" role="alert">
{$cart.minimalPurchaseRequired}
</div>
<div class="text-sm-center">
<div class="text-sm-center d-grid">
<button type="button" class="btn btn-primary disabled" disabled>{l s='Proceed to checkout' d='Shop.Theme.Actions'}</button>
</div>
{elseif empty($cart.products) }
<div class="text-sm-center">
{elseif empty($cart.products) || $disableCheckout === true}
<div class="text-sm-center d-grid">
<button type="button" class="btn btn-primary disabled" disabled>{l s='Proceed to checkout' d='Shop.Theme.Actions'}</button>
</div>
{else}
Expand Down