Skip to content

Commit

Permalink
Merge pull request #44 from FosterCommerce/feat/improve-handling-of-s…
Browse files Browse the repository at this point in the history
…hipping-method

feat: improve shipping method handling
  • Loading branch information
nedu64 authored Oct 11, 2024
2 parents be608ee + cf679d8 commit 519d962
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/templates/checkout/shipping.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@
{% set availableShippingMethodOptions = cart.availableShippingMethodOptions ?? null %}
{% set onlyMethod = null %}
{% if cart is defined %}
{# If there's only 1 shipping method available then set it on the cart #}
{% if cart.availableShippingMethodOptions|length == 1 %}
{% for handle, option in cart.availableShippingMethodOptions %}
{% if option.price == 0 %}
{% redirect(craft.fostercheckout.getPath('checkout') ~ '/payment') %}
{% else %}
{% if currentStore.requireShippingMethodSelectionAtCheckout == false %}
{# If there's 1 or more shipping method available then set it on the cart #}
{% if cart.availableShippingMethodOptions|length == 1 or cart.availableShippingMethodOptions|length > 1 %}
{% for handle, option in cart.availableShippingMethodOptions %}
{% set onlyMethod = handle %}
{% endif %}
{% endfor %}
{% elseif cart.availableShippingMethodOptions|length == 1 %}
{# If there are no available shipping methods, then just redirect to the payment page #}
{% redirect(craft.fostercheckout.getPath('checkout') ~ '/payment') %}
{% endfor %}
{% elseif cart.availableShippingMethodOptions|length == 0 %}
{# If requireShippingMethodSelectionAtCheckout is false and there are no available shipping methods, then just redirect to the payment page #}
{% redirect(craft.fostercheckout.getPath('checkout') ~ '/payment') %}
{% endif %}
{% else %}
{# If there's 1 or more shipping method available then set it on the cart #}
{% if cart.availableShippingMethodOptions|length == 1 or cart.availableShippingMethodOptions|length > 1 %}
{% for handle, option in cart.availableShippingMethodOptions %}
{% set onlyMethod = handle %}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}

Expand All @@ -44,7 +49,12 @@

{{ csrfInput() }}
{{ actionInput('commerce/cart/update-cart') }}
{{ redirectInput(craft.fostercheckout.getPath('checkout') ~ '/payment') }}

{% if cart.availableShippingMethodOptions|length >= 1 %}
{{ redirectInput(craft.fostercheckout.getPath('checkout') ~ '/payment') }}
{% else %}
{{ redirectInput(craft.fostercheckout.getPath('checkout') ~ '/shipping') }}
{% endif %}

<div class="border border-gray-250 rounded-lg overflow-hidden">

Expand Down

0 comments on commit 519d962

Please sign in to comment.