Skip to content

Commit

Permalink
Merge pull request #18 from FosterCommerce/fixes-for-line-item-qty-ad…
Browse files Browse the repository at this point in the history
…justments

fix removal when qty is 0
  • Loading branch information
peteeveleigh authored Aug 22, 2024
2 parents 402682b + a0799b6 commit ecde51c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/templates/_components/app/line-item-cart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
{{ actionInput('commerce/cart/update-cart') }}
<div class="inline-flex bg-white border border-gray-300 rounded-lg overflow-hidden">

<button type="button"
class="flex justify-center items-center w-[38px] h-[38px] text-[var(--brandColor)]"
@click="remove"
>
<button type="button"
class="flex justify-center items-center w-[38px] h-[38px] text-[var(--brandColor)]"
@click="decrement"
>
<span v-cloak v-if="qty <= 1">
<span class="sr-only">{{ 'Remove from cart'|t('foster-checkout') }}</span>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" viewBox="0 0 18 20" class="fill-current">
Expand Down Expand Up @@ -164,6 +164,7 @@
</button>

<button
type="button"
class="inline-flex justify-start items-center gap-2 text-sm underline text-gray-500 hover:no-underline hover:text-gray-700"
@click="remove"
>
Expand Down
8 changes: 6 additions & 2 deletions src/web/assets/checkout/dist/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ const LineItem = (props) => {
},
decrement() {
this.removeMessages()
this.qty = this.qty > 1 ? (this.qty - 1) : 1;
this.updateQty();
if(this.qty === 1) {
this.remove();
} else {
this.qty = this.qty > 1 ? (this.qty - 1) : 1;
this.updateQty();
}
},
async remove() {
const form = document.querySelector(`#lineItemQty-${props.id}`);
Expand Down

0 comments on commit ecde51c

Please sign in to comment.