Skip to content

Commit

Permalink
Merge pull request #47 from FosterCommerce/chiedu/allow-gift-card-vou…
Browse files Browse the repository at this point in the history
…cher-codes

Chiedu/allow gift card voucher codes
  • Loading branch information
nedu64 authored Nov 11, 2024
2 parents 7caaceb + c6d9b31 commit 0c4aae3
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/templates/_components/app/summary-cart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,48 @@

{% include 'foster-checkout/_components/app/coupon-code' %}

{% if craft.giftVoucher is defined %}

{# Check for applied / redeemed gift card vouchers in orders #}

{% set voucherCodes = craft.giftVoucher.getVoucherCodes() %}

{% if voucherCodes|length >= 1 %}
<div class="border-gray-400 border-b flex flex-col space-y-2 pb-4">
<h3 class="font-semibold text-gray-800">{{ 'Gift cards applied'|t('foster-checkout') }}</h3>

{% for code in voucherCodes %}

<div class="flex justify-between items-center">
<dt class="text-gray-500">{{ code }}</dt>
<dd class="text-right text-red-500">
<form method="post">
{{ csrfInput() }}
{{ actionInput('gift-voucher/cart/remove-code') }}
<input type="hidden" name="voucherCode" value="{{ code }}">
<button
type="submit"
class="inline-flex justify-start items-center gap-2 text-sm underline text-gray-500 hover:no-underline hover:text-gray-700"
>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="14" viewBox="0 0 12 14"
class="fill-current">
<path
d="M2.31807 13.0996C2.01032 13.0996 1.74346 12.9871 1.51751 12.7619C1.29155 12.5367 1.17857 12.2708 1.17857 11.9641V2.5319H0.42749V1.39638H3.73221V0.824646H8.26372V1.39638H11.5724V2.5319H10.8213V11.9641C10.8213 12.2708 10.7084 12.5367 10.4824 12.7619C10.2565 12.9871 9.9896 13.0996 9.68184 13.0996H2.31807ZM4.06481 10.5627H5.13257V3.9127H4.06481V10.5627ZM6.86734 10.5627H7.93909V3.9127H6.86734V10.5627Z"
fill="#6B7280"/>
</svg>
<span class="inline">{{ 'Remove'|t('foster-checkout') }}</span>
</button>
</form>
</dd>
<dd class="text-right text-red-500">- {{ craft.giftVoucher.codes().codeKey(code).one().currentAmount | currency }}</dd>
</div>

{% endfor %}
</div>
{% endif %}

{% endif %}

{% if step|default('') != 'payment' %}
<div class="flex justify-between items-center gap-4">
<dt class="font-semibold text-black">{{ 'Estimated total'|t('foster-checkout') }}</dt>
Expand Down
11 changes: 11 additions & 0 deletions src/templates/checkout/order.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,21 @@
</dd>
</div>
{% endif %}

<div class="sm:grid sm:grid-cols-[90px_1fr] sm:gap-6">
<dt class="font-semibold">{{ 'Payment'|t('foster-checkout') }}</dt>
<dd>{{ order.gateway.name }}</dd>
</div>

{% if craft.giftVoucher is defined %}
{# Check for applied / redeemed gift card vouchers in orders #}

{% if order.orderAdjustments|length >= 1 %}
<div style="width: fit-content" class="p-5 border text-green-900 bg-green-100 border-green-100 inline-block">
<span>Gift Voucher Applied</span>
</div>
{% endif %}
{% endif %}
</dl>

<div class="flex justify-end items-center gap-6 mt-9 lg:mt-12">
Expand Down
82 changes: 82 additions & 0 deletions src/templates/checkout/payment.twig
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,88 @@
</div>
</div>

{% if craft.giftVoucher is defined %}

<div class="my-6" v-scope="{ sending: false }">

<h3 class="px-4 mb-4 font-semibold xl:px-0">
{{ 'Apply gift card'|t('foster-checkout') }}
</h3>

{% 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 %}
{% else %}
{% if voucherCodeSuccess %}
{% set voucherMessage = 'Gift voucher added' | t('Foster Checkout') %}
{% else %}
{% set voucherMessage = null %}
{% endif %}
{% endif %}


<div class="px-4 xl:px-0"
>
<form
class="grid grid-cols-[1fr,_120px] items-start gap-4"
:class="sending ? 'grid-cols-[1fr,_120px]' : 'grid-cols-[1fr,_90px]'"
method="post"
@submit="sending = true"
>
{{ csrfInput() }}
{{ actionInput('gift-voucher/cart/add-code') }}
{{ hiddenInput('successMessage', 'Gift card applied' | t('Foster Checkout') | hash) }}
{% include 'foster-checkout/_components/base/input-text-clearable' with {
label: 'Voucher code'|t('foster-checkout'),
hideLabel: true,
id: 'voucherCode',
name: 'voucherCode',
type: 'text',
autocomplete: 'off',
placeholder: 'Enter gift card code'|t('foster-checkout'),
errors: voucherCodeError ? [voucherMessage] : [],
success: false and voucherMessage ? [voucherMessage] : [],
value: '',
} %}
<button
type="submit"
class="h-[48px] flex justify-center items-center gap-2 px-4 text-white bg-[var(--brandColor)] rounded-xl"
:disabled="sending"
>
<svg v-show="sending" aria-hidden="true" role="status" class="inline-block w-4 h-4 me-3 text-gray-200 animate-spin dark:text-gray-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="#ffffff"/>
</svg>
<span class="inline-block">{{ 'Submit'|t('foster-checkout') }}</span>
</button>
</form>
</div>



{# Check for applied / redeemed gift card vouchers in orders #}

{% set voucherCodes = craft.giftVoucher.getVoucherCodes() %}

{% if voucherCodes|length >= 1 %}
<div class="border-gray-400 border-b flex flex-col space-y-2 py-4">

{% for code in voucherCodes %}

<div class="flex justify-between items-center">
<p class="text-gray-500">{{ 'Gift cards currently applied to your order'|t('foster-checkout') }}: {{ code }} ({{ craft.giftVoucher.codes().codeKey(code).one().currentAmount | currency }})</p>
</div>

{% endfor %}
</div>
{% endif %}
</div>
{% endif %}

<div
class="xl:border xl:border-b-0 xl:border-gray-250 xl:mt-8 xl:rounded-lg xl:overflow-hidden">
{% for gateway in gateways %}
Expand Down

0 comments on commit 0c4aae3

Please sign in to comment.