From 4b15085cb5d8eb730db85879bcf4cda351005fe8 Mon Sep 17 00:00:00 2001 From: bj-anas <93322743+bj-anas@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:16:12 +0100 Subject: [PATCH] refactoring skip cart feature --- themes/harmony/sections/product.liquid | 6 ------ themes/harmony/snippets/add-to-cart.liquid | 16 +++++++++------- themes/harmony/snippets/product-preview.liquid | 2 +- themes/harmony/snippets/product-slider.liquid | 2 +- .../snippets/single-product-placeholder.liquid | 2 +- themes/harmony/snippets/single-product.liquid | 2 +- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/themes/harmony/sections/product.liquid b/themes/harmony/sections/product.liquid index 14225ad1..2048cad4 100644 --- a/themes/harmony/sections/product.liquid +++ b/themes/harmony/sections/product.liquid @@ -186,12 +186,6 @@ "type": "checkbox", "default": true }, - { - "type": "checkbox", - "id": "skip_cart", - "label": "Skip cart", - "default": false - }, { "label": "Background color", "id": "background_color", diff --git a/themes/harmony/snippets/add-to-cart.liquid b/themes/harmony/snippets/add-to-cart.liquid index 221922eb..4ea76769 100644 --- a/themes/harmony/snippets/add-to-cart.liquid +++ b/themes/harmony/snippets/add-to-cart.liquid @@ -30,18 +30,20 @@ class='spinner hidden' id='loading__cart' > - - {% render 'icon', name: 'bag' %} - {{ block_settings.text_content }} - + {% if skip_cart %} + {{ 'snippets.product_preview.cta_button' | t }} + {% else %} + + {% render 'icon', name: 'bag' %} + {{ block_settings.text_content }} + + {% endif %} {% javascript %} - const TRANSLATED_TEXT = { empty_inventory: "{{ 'errors.empty_inventory' | t }}" } - - const IS_CART_SKIPED = "{{ block_settings.skip_cart }}"; + const IS_CART_SKIPED = Boolean("{{ skip_cart }}"); {% endjavascript %} diff --git a/themes/harmony/snippets/product-preview.liquid b/themes/harmony/snippets/product-preview.liquid index 977840b4..1c0f11f0 100644 --- a/themes/harmony/snippets/product-preview.liquid +++ b/themes/harmony/snippets/product-preview.liquid @@ -35,7 +35,7 @@ {% endif %}
- {% if settings.direct_add_to_cart and item.variants.size <= 1 %} + {% if settings.direct_add_to_cart and item.variants.size <= 1 and item.skip_to_checkout == false %} diff --git a/themes/harmony/snippets/product-slider.liquid b/themes/harmony/snippets/product-slider.liquid index 08a0818d..7fe427e3 100644 --- a/themes/harmony/snippets/product-slider.liquid +++ b/themes/harmony/snippets/product-slider.liquid @@ -69,7 +69,7 @@ {{ block.settings.product.price | money }} {% endif %}
- {% if settings.direct_add_to_cart and block.settings.product.variants.size <= 1 %} + {% if settings.direct_add_to_cart and block.settings.product.variants.size <= 1 and block.settings.product.skip_to_checkout == false %} diff --git a/themes/harmony/snippets/single-product-placeholder.liquid b/themes/harmony/snippets/single-product-placeholder.liquid index f15f4e4c..7a0f584c 100644 --- a/themes/harmony/snippets/single-product-placeholder.liquid +++ b/themes/harmony/snippets/single-product-placeholder.liquid @@ -39,7 +39,7 @@ {%- when 'product_description' -%}

This is a placeholder description for the product.

{%- when 'add_to_cart' -%} - {% render 'add-to-cart', block_settings: block.settings, snippetId: snippetId, is_placeholder: is_placeholder %} + {% render 'add-to-cart', block_settings: block.settings, snippetId: snippetId, is_placeholder: is_placeholder, skip_cart: product.skip_to_checkout %} {%- when 'accordion' -%} {%- render 'accordion', accordion_title: block.settings.accordion_title, accordion_details: block.settings.accordion_details, background_color: block.settings.background_color, text_color: block.settings.text_color, space_bottom: block.settings.space_bottom -%} {%- when 'express_checkout' -%} diff --git a/themes/harmony/snippets/single-product.liquid b/themes/harmony/snippets/single-product.liquid index d1328c0c..bd36f8ea 100644 --- a/themes/harmony/snippets/single-product.liquid +++ b/themes/harmony/snippets/single-product.liquid @@ -74,7 +74,7 @@ {%- when 'stock' -%} {% render 'stock', stock_title: block.settings.stock_title, stock_items_left: block.settings.stock_items_left, total_stock_items: block.settings.total_stock_items %} {%- when 'add_to_cart' -%} - {% render 'add-to-cart', block_settings: block.settings, snippetId: snippetId %} + {% render 'add-to-cart', block_settings: block.settings, snippetId: snippetId, skip_cart: product.skip_to_checkout %} {%- when 'accordion' -%} {%- render 'accordion', accordion_title: block.settings.accordion_title, accordion_details: block.settings.accordion_details, background_color: block.settings.background_color, text_color: block.settings.text_color, space_bottom: block.settings.space_bottom -%} {%- when 'express_checkout' -%}