From eba386d0a02497bf3ef72954450e45a1ce673e41 Mon Sep 17 00:00:00 2001 From: runrog Date: Mon, 17 Jun 2024 22:29:57 -0500 Subject: [PATCH] fix removing items from cart if setting to 0 count --- src/tools/slide-checkout/plugin.js | 12 ++++++++++-- src/tools/slide-checkout/themes/default/styles.less | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/tools/slide-checkout/plugin.js b/src/tools/slide-checkout/plugin.js index e1ec9f5..177786c 100644 --- a/src/tools/slide-checkout/plugin.js +++ b/src/tools/slide-checkout/plugin.js @@ -422,7 +422,7 @@ // is greater than or equalt to minimum allowed or greater than or // equal to step amount const removeStepTwo = !noMinLimit && (newCount >= minAllowed || newCount >= step); - // no minimum purchase limit and desired count is les than step amount + // no minimum purchase limit and desired count is less than step amount const makeStepOne = noMinLimit && newCount < step; // item HAS a minimum quantity purchase limit and desired count // is less than the minimum allowed or less than the step amount @@ -431,6 +431,7 @@ if (removeStepOne || removeStepTwo) { item.count -= step; } else if (makeStepOne || makeStepTwo) { + // TODO will this need to show trash can eventually on remove item item.count = 0; } methods.buildCart(cartItems); @@ -648,6 +649,9 @@ productOptions = `${productOptions}`; lastOptions = `${lastOptions}`; } + const step = parseInt(data.product.countStep, 10); + const newCount = data.count - step; + const trashCount = newCount <= 0 ? ' drzSlideCheckout-cart-removeTrash' : ''; // attach to final cart $finalList.append(`
@@ -692,7 +696,7 @@
@@ -746,11 +750,15 @@ $.each(list, (index, value) => { const $cartItem = $(methods.buildCartItem(value, index)); const $removeItemBtn = $cartItem.find('.drzSlideCheckout-cart-itemRemoveBtn'); + const $removeItemTrash = $cartItem.find('.drzSlideCheckout-cart-removeTrash'); const $addCountBtn = $cartItem.find('.drzSlideCheckout-cart-add'); const $removeCountBtn = $cartItem.find('.drzSlideCheckout-cart-remove'); $removeItemBtn.click(methods.onRemoveItemClick); $addCountBtn.click(methods.onAddCount); $removeCountBtn.click(methods.onRemoveCount); + if ($removeItemTrash.length) { + $removeItemTrash.click(methods.onRemoveItemClick); + } // dynamic option listeners $cartItem.find('select') .change(methods.onSelectChange) diff --git a/src/tools/slide-checkout/themes/default/styles.less b/src/tools/slide-checkout/themes/default/styles.less index 057c76c..df1e9b6 100644 --- a/src/tools/slide-checkout/themes/default/styles.less +++ b/src/tools/slide-checkout/themes/default/styles.less @@ -418,6 +418,13 @@ } } +.drzSlideCheckout-cart-removeTrash { + + &:after { + content: '\e857'; + } +} + .drzSlideCheckout-step-grid { display: grid; grid-template-columns: 1fr 350px;