Skip to content

Commit

Permalink
Merge pull request #51 from FosterCommerce/fix/more-regression-bug-fi…
Browse files Browse the repository at this point in the history
…xes-and-refactor

Fix/more regression bug fixes and refactor
  • Loading branch information
nedu64 authored Nov 12, 2024
2 parents 02c15d0 + bcfa517 commit d86b782
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/templates/_components/app/summary-cart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@
</button>
</form>
</dd>
{% if cart.storedItemTotal - voucherCurrentAmount > 0 %}
{% set estimatedTotal = cart.storedItemTotal + cart.storedTotalShippingCost + cart.totalTax %}
{% if estimatedTotal - voucherCurrentAmount > 0 %}
{% set voucherAmountApplied = voucherAmountApplied + voucherCurrentAmount %}
{% set appliedAmount = (cart.storedItemTotal - voucherAmountApplied) <= 0 ? voucherAmountApplied - cart.storedItemTotal : voucherCurrentAmount %}
{% set totalVoucherAmountApplied = voucherAmountApplied %}
{% else %}
{% set appliedAmount = (totalVoucherAmountApplied - cart.storedItemTotal)|abs %}
{% set appliedAmount = (totalVoucherAmountApplied - estimatedTotal)|abs %}
{% endif %}
<dd class="text-right text-red-500">- {{ appliedAmount | currency }}</dd>
</div>
Expand Down
12 changes: 7 additions & 5 deletions src/templates/checkout/order.twig
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@
<dd>
{% for voucher in order.orderAdjustments %}
{# Get redeemed voucher code from description #}
{% set voucherCode = voucher.description|split('code ')[1] %}
{% set voucherCode = voucher.description|split('code ')[1] is defined ? voucher.description|split('code ')[1] : false %}
{# Get voucher remaining amount #}
{% set amountRemaining = craft.giftVoucher.codes().codeKey(voucherCode).one().currentAmount %}
{% set appliedVoucherAmount = (order.storedItemTotal - (voucher.amount|abs)) < 0 ? order.storedItemTotal : voucher.amount|abs %}
{% set appliedVoucherDescription = voucher.description|split('code ')[1] ~ ' (' ~ appliedVoucherAmount|currency ~ ' applied, ' ~ amountRemaining|currency ~ ' remaining)' %}
<p>{{ appliedVoucherDescription }}</p>
{% if voucherCode %}
{% set amountRemaining = craft.giftVoucher.codes().codeKey(voucherCode).one().currentAmount %}
{% set appliedVoucherAmount = (order.storedItemTotal - (voucher.amount|abs)) < 0 ? order.storedItemTotal : voucher.amount|abs %}
{% set appliedVoucherDescription = voucher.description|split('code ')[1] ~ ' (' ~ appliedVoucherAmount|currency ~ ' applied, ' ~ amountRemaining|currency ~ ' remaining)' %}
<p>{{ appliedVoucherDescription }}</p>
{% endif %}
{% endfor %}
</dd>
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/templates/checkout/payment.twig
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@
<div class="border-gray-400 border-b flex flex-col space-y-2 py-4 px-4 xl:px-0">
{% if voucherCodes|length == 1 %}
{% set currentAmount = craft.giftVoucher.codes().codeKey(voucherCodes[0]).one().currentAmount %}
{% set appliedAmount = cart.storedItemTotal < currentAmount ? cart.storedItemTotal : currentAmount %}
{% set estimatedTotal = cart.storedItemTotal + cart.storedTotalShippingCost + cart.totalTax %}
{% set appliedAmount = estimatedTotal < currentAmount ? estimatedTotal : currentAmount %}
<div class="flex justify-between items-center">
<p class="text-gray-500">{{ 'Gift cards currently applied to your order'|t('foster-checkout') }}: {{ voucherCodes[0] }} ({{ appliedAmount | currency }})</p>
</div>
Expand All @@ -269,12 +270,13 @@
<ul class="text-gray-500 m-0 list-disc">
{% for code in voucherCodes %}
{% set voucherCurrentAmount = craft.giftVoucher.codes().codeKey(code).one().currentAmount %}
{% if cart.storedItemTotal - voucherCurrentAmount > 0 %}
{% set estimatedTotal = cart.storedItemTotal + cart.storedTotalShippingCost + cart.totalTax %}
{% if estimatedTotal - voucherCurrentAmount > 0 %}
{% set voucherAmountApplied = voucherAmountApplied + voucherCurrentAmount %}
{% set appliedAmount = (cart.storedItemTotal - voucherAmountApplied) <= 0 ? voucherAmountApplied - cart.storedItemTotal : voucherCurrentAmount %}
{% set totalVoucherAmountApplied = voucherAmountApplied %}
{% else %}
{% set appliedAmount = (totalVoucherAmountApplied - cart.storedItemTotal)|abs %}
{% set appliedAmount = (totalVoucherAmountApplied - estimatedTotal)|abs %}
{% endif %}
<li class="ml-5">{{ code }} ({{ appliedAmount | currency }})</li>
{% endfor %}
Expand Down

0 comments on commit d86b782

Please sign in to comment.