From b176206f857a2c2ad787865be6751d823f079b8e Mon Sep 17 00:00:00 2001 From: nedu64 Date: Sat, 9 Nov 2024 14:48:42 +0100 Subject: [PATCH 1/8] wip: gift voucher test code --- .../_components/app/gift-voucher-code.twig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/templates/_components/app/gift-voucher-code.twig diff --git a/src/templates/_components/app/gift-voucher-code.twig b/src/templates/_components/app/gift-voucher-code.twig new file mode 100644 index 0000000..54363c0 --- /dev/null +++ b/src/templates/_components/app/gift-voucher-code.twig @@ -0,0 +1,18 @@ +{% if cart.getFirstError('voucherCode') %} + {{ cart.getFirstError('voucherCode') }} + {{ dump(cart.getFirstError('voucherCode')) }} +{% endif %} + +
+ + {{ csrfInput() }} + {{ actionInput('commerce/cart/update-cart') }} + + + + + + +
+ +{{ dump(craft.giftVoucher.getVoucherCodes()) }} From 051510ee822970961b4bbc771a6914db975972cf Mon Sep 17 00:00:00 2001 From: nedu64 Date: Sat, 9 Nov 2024 14:49:15 +0100 Subject: [PATCH 2/8] test: include gift voucher test code in cart summary --- src/templates/_components/app/summary-cart.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/templates/_components/app/summary-cart.twig b/src/templates/_components/app/summary-cart.twig index 0be53ba..6306a8e 100644 --- a/src/templates/_components/app/summary-cart.twig +++ b/src/templates/_components/app/summary-cart.twig @@ -43,6 +43,7 @@ {% include 'foster-checkout/_components/app/coupon-code' %} + {% include 'foster-checkout/_components/app/gift-voucher-code' %} {% if step|default('') != 'payment' %}
From 50262820bc4b83771b0c1d054fb282b10825034a Mon Sep 17 00:00:00 2001 From: nedu64 Date: Sat, 9 Nov 2024 14:49:39 +0100 Subject: [PATCH 3/8] feat: mock ui for gift vouchers on payment page --- src/templates/checkout/payment.twig | 86 +++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/templates/checkout/payment.twig b/src/templates/checkout/payment.twig index 3e2b24f..f01db51 100644 --- a/src/templates/checkout/payment.twig +++ b/src/templates/checkout/payment.twig @@ -184,6 +184,92 @@
+ {# Gift Vouchers #} + {% if craft.giftVoucher is defined %} +
+ + + {% set voucherCodeError = cart.getFirstNotice(null, 'voucherCode') ?? null %} + {% set voucherCodeSuccess = craft.app.session.getFlash('success') ?? null %} + + {% if voucherCodeError %} + {% set voucherMessage = voucherCodeError.message %} + {% else %} + {% if voucherCodeSuccess + and voucherCodeSuccess == 'Gift voucher added' | t('Foster Checkout') + %} + {% set voucherMessage = voucherCodeSuccess %} + {% else %} + {% set voucherMessage = null %} + {% endif %} + {% endif %} + + +
+ {% endif %} + + {# End Gift Vouchers #} +
{% for gateway in gateways %} From 53396b8a86f8c4e19236a5efe0b6fe83d4fab55f Mon Sep 17 00:00:00 2001 From: nedu64 Date: Sun, 10 Nov 2024 11:39:24 +0100 Subject: [PATCH 4/8] fix: remove unused file --- .../_components/app/gift-voucher-code.twig | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/templates/_components/app/gift-voucher-code.twig diff --git a/src/templates/_components/app/gift-voucher-code.twig b/src/templates/_components/app/gift-voucher-code.twig deleted file mode 100644 index 54363c0..0000000 --- a/src/templates/_components/app/gift-voucher-code.twig +++ /dev/null @@ -1,18 +0,0 @@ -{% if cart.getFirstError('voucherCode') %} - {{ cart.getFirstError('voucherCode') }} - {{ dump(cart.getFirstError('voucherCode')) }} -{% endif %} - -
- - {{ csrfInput() }} - {{ actionInput('commerce/cart/update-cart') }} - - - - - - -
- -{{ dump(craft.giftVoucher.getVoucherCodes()) }} From c30b6c5d0d1a1dd3181d935e7b365a9c8f5349b9 Mon Sep 17 00:00:00 2001 From: nedu64 Date: Sun, 10 Nov 2024 11:40:56 +0100 Subject: [PATCH 5/8] feat: integrated gift voucher code redemption --- src/templates/checkout/payment.twig | 64 ++++++++++------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/src/templates/checkout/payment.twig b/src/templates/checkout/payment.twig index f01db51..efb41d1 100644 --- a/src/templates/checkout/payment.twig +++ b/src/templates/checkout/payment.twig @@ -184,45 +184,32 @@
- {# Gift Vouchers #} {% if craft.giftVoucher is defined %} -
- - - {% set voucherCodeError = cart.getFirstNotice(null, 'voucherCode') ?? null %} - {% set voucherCodeSuccess = craft.app.session.getFlash('success') ?? null %} + + +
+ +

+ {{ 'Apply gift card'|t('foster-checkout') }} +

+ + {% set voucherCodeError = cart.getFirstError('voucherCode') ?? null %} + + {# If there are no gift voucher code errors #} + {% set voucherCodeSuccess = craft.app.session.getFlash('success') ?? null %} {# Not working for now #} {% if voucherCodeError %} - {% set voucherMessage = voucherCodeError.message %} + {% set voucherMessage = voucherCodeError %} {% else %} - {% if voucherCodeSuccess - and voucherCodeSuccess == 'Gift voucher added' | t('Foster Checkout') - %} - {% set voucherMessage = voucherCodeSuccess %} + {% if voucherCodeSuccess %} + {% set voucherMessage = 'Gift voucher added' | t('Foster Checkout') %} {% else %} {% set voucherMessage = null %} {% endif %} {% endif %} - + + {% endfor %} +
+ {% endif %} + + {% endif %} + {% if not cart.shippingAddressId %} {% if craft.fostercheckout.getOption('enableEstimatedShipping') %} {% include 'foster-checkout/_components/app/estimated-shipping' %} @@ -43,7 +85,6 @@
{% include 'foster-checkout/_components/app/coupon-code' %} - {% include 'foster-checkout/_components/app/gift-voucher-code' %} {% if step|default('') != 'payment' %}
From 4b2b47eb98a65a6b8260e6e02db1b456642631d3 Mon Sep 17 00:00:00 2001 From: nedu64 Date: Sun, 10 Nov 2024 11:45:18 +0100 Subject: [PATCH 7/8] feat: ensure redeemed gift vouchers are visible on order confirmations --- src/templates/checkout/order.twig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/templates/checkout/order.twig b/src/templates/checkout/order.twig index eee394d..82e7919 100644 --- a/src/templates/checkout/order.twig +++ b/src/templates/checkout/order.twig @@ -67,10 +67,21 @@
{% endif %} +
{{ 'Payment'|t('foster-checkout') }}
{{ order.gateway.name }}
+ + {% if craft.giftVoucher is defined %} + {# Check for applied / redeemed gift card vouchers in orders #} + + {% if order.orderAdjustments|length >= 1 %} +
+ Gift Voucher Applied +
+ {% endif %} + {% endif %}
From c6d9b312e9fec6fa1b165527e92c22b9ac9036ba Mon Sep 17 00:00:00 2001 From: Stephen Callender Date: Sun, 10 Nov 2024 16:06:42 -0500 Subject: [PATCH 8/8] Update placement and text --- .../_components/app/summary-cart.twig | 68 +++++++++---------- src/templates/checkout/payment.twig | 20 +++++- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/templates/_components/app/summary-cart.twig b/src/templates/_components/app/summary-cart.twig index 65ff3ac..0a4a11e 100644 --- a/src/templates/_components/app/summary-cart.twig +++ b/src/templates/_components/app/summary-cart.twig @@ -16,6 +16,34 @@
{% endif %} + {% if not cart.shippingAddressId %} + {% if craft.fostercheckout.getOption('enableEstimatedShipping') %} + {% include 'foster-checkout/_components/app/estimated-shipping' %} + {% endif %} + + {% if craft.fostercheckout.getOption('enableFreeShippingMessage') %} +

+ {{ 'Add'|t('foster-checkout') }} + $24.15 + {{ 'for FREE shipping, or choose FREE Ship to Store.'|t('foster-checkout') }} +

+ {% endif %} + + {% else %} +
+
{{ 'Shipping & handling'|t('foster-checkout') }}
+
{{ cart.totalShippingCostAsCurrency }}
+
+ {% endif %} + + +
+
{{ 'Estimated tax'|t('foster-checkout') }}
+
{{ cart.totalTaxAsCurrency }}
+
+ + {% include 'foster-checkout/_components/app/coupon-code' %} + {% if craft.giftVoucher is defined %} {# Check for applied / redeemed gift card vouchers in orders #} @@ -24,7 +52,7 @@ {% if voucherCodes|length >= 1 %}
-

{{ 'Redeemed Gift Vouchers'|t('foster-checkout') }}

+

{{ 'Gift cards applied'|t('foster-checkout') }}

{% for code in voucherCodes %} @@ -36,14 +64,14 @@ {{ actionInput('gift-voucher/cart/remove-code') }} @@ -58,34 +86,6 @@ {% endif %} - {% if not cart.shippingAddressId %} - {% if craft.fostercheckout.getOption('enableEstimatedShipping') %} - {% include 'foster-checkout/_components/app/estimated-shipping' %} - {% endif %} - - {% if craft.fostercheckout.getOption('enableFreeShippingMessage') %} -

- {{ 'Add'|t('foster-checkout') }} - $24.15 - {{ 'for FREE shipping, or choose FREE Ship to Store.'|t('foster-checkout') }} -

- {% endif %} - - {% else %} -
-
{{ 'Shipping & handling'|t('foster-checkout') }}
-
{{ cart.totalShippingCostAsCurrency }}
-
- {% endif %} - - -
-
{{ 'Estimated tax'|t('foster-checkout') }}
-
{{ cart.totalTaxAsCurrency }}
-
- - {% include 'foster-checkout/_components/app/coupon-code' %} - {% if step|default('') != 'payment' %}
{{ 'Estimated total'|t('foster-checkout') }}
diff --git a/src/templates/checkout/payment.twig b/src/templates/checkout/payment.twig index efb41d1..62ae374 100644 --- a/src/templates/checkout/payment.twig +++ b/src/templates/checkout/payment.twig @@ -186,7 +186,6 @@ {% if craft.giftVoucher is defined %} -

@@ -245,6 +244,25 @@

+ + + + {# Check for applied / redeemed gift card vouchers in orders #} + + {% set voucherCodes = craft.giftVoucher.getVoucherCodes() %} + + {% if voucherCodes|length >= 1 %} +
+ + {% for code in voucherCodes %} + +
+

{{ 'Gift cards currently applied to your order'|t('foster-checkout') }}: {{ code }} ({{ craft.giftVoucher.codes().codeKey(code).one().currentAmount | currency }})

+
+ + {% endfor %} +
+ {% endif %}
{% endif %}