From c5e64f507478d91ceb8d93db313e32219beb1cfa Mon Sep 17 00:00:00 2001 From: Axel Date: Thu, 30 Apr 2026 01:47:44 +0800 Subject: [PATCH] first commit --- sections/livesearch.liquid | 119 +++++ snippets/product-item.liquid | 916 +++++++++++++++++++++++++++++++++ snippets/product-labels.liquid | 91 ++++ 3 files changed, 1126 insertions(+) create mode 100644 sections/livesearch.liquid create mode 100644 snippets/product-item.liquid create mode 100644 snippets/product-labels.liquid diff --git a/sections/livesearch.liquid b/sections/livesearch.liquid new file mode 100644 index 0000000..796e021 --- /dev/null +++ b/sections/livesearch.liquid @@ -0,0 +1,119 @@ +{% comment %}theme-check-disable ImgLazyLoading{% endcomment %} +{%- if predictive_search.performed -%} +
+

{{ 'search.results_plus_term' | t: term: predictive_search.terms }}

+

{{ 'search.view_all_results' | t }} 

+
+ {%- liquid + if settings.search_drawer_enable_suggestions + assign all_suggestions = predictive_search.resources.queries + endif + if settings.search_drawer_enable_collections + if all_suggestions + assign all_suggestions = all_suggestions | concat: predictive_search.resources.collections + else + assign all_suggestions = predictive_search.resources.collections + endif + endif + -%} + {%- if all_suggestions.size > 0 and all_suggestions.first.text != predictive_search.terms -%} + {%- if settings.search_drawer_enable_suggestions -%}

{{ 'search.suggestions' | t }}

{%- endif -%} + + {%- endif -%} + {%- if settings.search_drawer_enable_products and predictive_search.resources.products.size > 0 -%} + + {%- endif -%} +

{{ 'search.view_all_results' | t }} 

+ {%- liquid + assign all_articles = '' + if settings.search_drawer_enable_pages + assign all_articles = predictive_search.resources.pages + endif + if settings.search_drawer_enable_articles + assign all_articles = all_articles | concat: predictive_search.resources.articles + endif + -%} + {%- if all_articles.size > 0 -%} +

{{ 'search.questions_and_advice' | t }}

+ + {%- endif -%} +{%- endif -%} diff --git a/snippets/product-item.liquid b/snippets/product-item.liquid new file mode 100644 index 0000000..6a6393d --- /dev/null +++ b/snippets/product-item.liquid @@ -0,0 +1,916 @@ +{% comment %}theme-check-disable ImgLazyLoading{% endcomment %} +{%- liquid + assign container = 'li' + assign placeholder_int = placeholder_int | default: 1 + assign width_class = width_class | default: '' + assign sizes = sizes | default: false + assign slider = slider | default: false + assign type = type | default: 'grid' + assign no_lazyload = no_lazyload | default: false + assign enable_image_choice = enable_image_choice | default: false + assign img_view = img_view | default: 'first' + if fill_images == null + assign fill_images = settings.fill_product_images + endif + if quick_buy_compact == null + assign quick_buy_compact = false + endif + if enable_quick_buy_drawer == null + if settings.layout_productcard == 'quickshop' + assign enable_quick_buy_drawer = true + else + assign enable_quick_buy_drawer = false + endif + endif + if enable_quick_buy_desktop == null + assign enable_quick_buy_desktop = true + endif + if enable_quick_buy_mobile == null + assign enable_quick_buy_mobile = true + endif + if enable_quick_buy_qty_selector == null + assign enable_quick_buy_qty_selector = false + endif + if enable_variant_picker == null + assign enable_variant_picker = true + endif + if enable_color_picker == null + assign enable_color_picker = settings.show_color_swatches + endif + if show_image == null + assign show_image = true + assign show_labels = true + assign show_title = true + assign show_price = true + assign show_stock = true + assign show_vendor = settings.show_vendor + assign show_rating = settings.show_product_rating + endif + if layout == 'list-compact' + assign show_labels = false + assign show_stock = false + assign show_vendor = false + assign show_rating = false + endif + if layout == 'hotspot' + assign show_labels = false + assign show_image = false + assign container = 'div' + if product.variants.size > 1 or product.available == false + assign enable_quick_buy_drawer = true + endif + endif + assign current_variant = product.selected_or_first_available_variant + if custom_height_ratio == null + assign custom_height_ratio = settings.custom_product_image_ratio + endif + assign custom_height_ratio = custom_height_ratio | divided_by: 100.0 + assign image_width = 430 + assign image_height = image_width | times: custom_height_ratio | round + assign image_width_2 = image_width | times: 1.5 + assign image_height_2 = image_height | times: 1.5 + assign image_width_small = image_width | divided_by: 3 + assign image_height_small = image_height | divided_by: 3 + if product == blank + assign vendor = 'Vendor name' + assign title = 'Product title' + assign price = 0 | money + else + assign vendor = product.vendor + if vendor == 'vendor-unknown' or vendor == shop.name + assign show_vendor = false + endif + assign title = product.title + if layout == 'list-compact' + assign price = current_variant.price | money + else + assign price = product.price | money + endif + endif + assign total_stock = 0 + for variant in product.variants + if variant.matched and variant.inventory_quantity > 0 + assign total_stock = total_stock | plus: variant.inventory_quantity + endif + endfor + if total_stock <= 0 + assign total_stock = current_variant.inventory_quantity + endif + if total_stock <= 0 and current_variant.inventory_management != null and current_variant.inventory_policy == 'continue' and current_variant.available and current_variant.inventory_quantity <= 0 and settings.preorder + assign preorder = true + unless settings.show_preorder_inventory + assign show_stock = false + endunless + endif + assign static_color_picker = false + if settings.layout_productcard == 'variant_picker' or settings.layout_productcard == 'quickshop' or settings.layout_productcard == 'add_to_cart' + assign static_color_picker = true + elsif settings.color_swatch_behavior == 'static' and settings.layout_productcard == 'standard' + assign static_color_picker = true + endif + assign overlay_static = false + if settings.quickshop_behavior == 'static' + if settings.layout_productcard == 'quickshop' or settings.layout_productcard == 'add_to_cart' + assign overlay_static = true + endif + elsif settings.color_swatch_behavior == 'static' and settings.layout_productcard == 'standard' + assign overlay_static = true + endif + assign collection_page = false + if origin == 'collection' or origin == 'search' + assign collection_page = true + endif + assign quickshop = false + if settings.layout_productcard == 'quickshop' + assign quickshop = true + elsif settings.layout_productcard != 'standard' + if layout == 'list' or layout == 'hotspot' or layout == 'grid' + assign quickshop = true + endif + endif + assign fixed_text_alignment_left = false + if layout == 'list' + assign fixed_text_alignment_left = true + endif + + assign color_triggers = settings.color_swatch_name | newline_to_br | strip_newlines | replace: '
', '|' | split: '|' + assign color_option = false + if enable_color_picker + if settings.enable_color_swatches + for option in product.options_with_values + if color_triggers contains option.name + assign color_option = option + break + endif + endfor + endif + assign colors_size = color_option.values | size + if settings.color_swatches_single and colors_size < 2 + assign color_option = false + endif + endif + + assign size_triggers = settings.variant_picker_name | newline_to_br | strip_newlines | replace: '
', '|' | split: '|' + assign size_option = false + if settings.layout_productcard == 'variant_picker' + for option in product.options_with_values + if size_triggers contains option.name + assign size_option = option + assign size_option_index = forloop.index0 + break + endif + endfor + endif + + if product.options_with_values.first.values.first.product_url + assign size_option = false + endif + if product.variants.size == 250 + assign quickshop = true + assign enable_color_picker = false + assign size_option = false + endif + + assign rating_value = false + assign rating_count = false + if product.metafields.syncer.reviews + assign locale_ratings = product.metafields.syncer.reviews.value.reviews[localization.language.iso_code] + if locale_ratings + assign rating_value = locale_ratings.rating + assign rating_count = locale_ratings.count + else + assign rating_value = product.metafields.syncer.reviews.value.cumulative_rating + assign rating_count = product.metafields.syncer.reviews.value.total_reviews + endif + elsif product.metafields.reviews.rating + assign rating_value = product.metafields.reviews.rating.value + assign rating_count = product.metafields.reviews.rating_count + endif +-%} +{%- if enable_quick_buy_desktop or enable_quick_buy_mobile -%} + {%- liquid + assign product_form_class = 'f8pr form-card ' | append: settings.productcards_text_alignment + if settings.layout_productcard == 'variant_picker' and layout != 'list-compact' + assign product_form_class = product_form_class | append: ' no-border' + endif + assign product_form_id = 'quick-add-' | append: section.id | append: product.id | append: '-quick-add-form_x' + -%} + {%- capture quick_buy -%} + {%- if layout == 'list-compact' -%} + {%- form 'product', product, id: product_form_id, class: product_form_class, novalidate: 'novalidate' -%} + {%- assign available_variants = product.variants | where: "available" -%} + {%- if enable_variant_picker and available_variants.size > 1 and product.variants.size < 250 -%} +

+ +

+ {%- else -%} + + {%- endif -%} +

+ +

+ {%- endform -%} + {%- else -%} + {% if quickshop %} + + {% elsif settings.layout_productcard == 'add_to_cart' and product.id %} + + {% if current_variant.available or preorder %} + {% unless collection_page %} + {% assign product_form_class = product_form_class %} + {% endunless %} + {%- form 'product', product, id: product_form_id, class: product_form_class, novalidate: 'novalidate' -%} + {%- assign available_variants = product.variants | where: "available" -%} + {%- if available_variants.size > 1 -%} +
+

+ + + + +

+
+ {%- else -%} +

+ + +

+ {%- endif -%} + {%- endform -%} + {% else %} + + {% endif %} + {% elsif settings.layout_productcard == 'variant_picker' %} + + + {% if size_option %} + {%- assign product_form_class = product_form_class | append: ' hidden' -%} + {% if size_option.values %} + {% comment %}Redirect to product if it has a third option or color swatch is disabled and there is a second option{% endcomment %} + {%- liquid + assign go_to_product = false + if color_option and product.options.size < 3 + assign go_to_product = true + elsif color_option == false and product.options.size < 2 + assign go_to_product = true + endif + if enable_color_picker + if settings.color_swatches_single and colors_size < 2 + assign go_to_product = false + endif + endif + if go_to_product + assign product_form_class = product_form_class | append: ' product-options' + endif + %} + {% assign product_form_class = product_form_class | append: ' mobile-hide' %} + {%- form 'product', product, id: product_form_id, class: product_form_class, novalidate: 'novalidate' -%} + +

+ {%- if current_variant.available -%} + + {%- else -%} + + {%- endif -%} +

+ {%- endform -%} + + + + {% endif %} + {% endif %} + {% endif %} + {%- endif -%} + {%- endcapture %} +{%- endif -%} + +{%- capture color_picker -%} + {%- if enable_color_picker -%} + {% if color_option %} + + {% endif %} + {%- endif -%} +{%- endcapture %} + +<{{ container }} + class=" + product-card {{ width_class }}{% if quick_buy %} has-form{% endif %} + {% unless current_variant.available %}unavailable{% endunless %} + {% unless layout contains 'list' or layout == 'hotspot' %}{% if settings.productcards_text_alignment == 'left' or fixed_text_alignment_left %}text-start{% elsif settings.productcards_text_alignment == 'center' %}text-center{% elsif settings.productcards_text_alignment == 'right' %}text-end{% endif %}{% endunless %} + {% if settings.image_behaviour != 'slider' and product.media[1] != nil %}second-img-hover{% endif %} + {% if collection_img_view != 'first' and product.media[1] != nil and collection_page %}second-img-first{% endif %} + {% if settings.layout_productcard == 'add_to_cart' or settings.layout_productcard == 'variant_picker' %}update-variants dynamic-quickshop{% endif %} + {% if product == blank %}placeholder-product{% endif %} + " + {% if layout == 'list-compact' %} + data-product-id="{{ product.id }}" + {% endif %} + style="--ratio:{{ custom_height_ratio }};{% if settings.layout_productcard == 'variant_picker' %} --check_plain_bg: var(--{{ settings.variant_color_palette }}_bg); --check_plain_fg: var(--{{ settings.variant_color_palette }}_fg); --check_plain_o: {{ settings.background_opacity | divided_by: 100.0 }};{% endif %}" +> + {%- if show_image -%} +
+ {% if show_labels %}{%- render 'product-labels', product: product, origin: 'productitem' -%}{% endif %} + {%- liquid + if layout == 'list-compact' and current_variant.featured_image + assign product_image = current_variant.featured_image + else + assign product_image = product.featured_media + endif + assign first_image = product_image + assign second_image = product.media[1] + if collection_page and img_view == 'last' + assign second_image = product.media | last + elsif collection_page == false and settings.image_behaviour == 'last_image' + assign second_image = product.media | last + endif + if settings.layout_productcard == 'variant_picker' and size_option + elsif second_image != null and settings.image_behaviour != 'slider' and layout != 'list-compact' + assign show_secondary_image = true + elsif second_image != null and enable_image_choice + assign show_secondary_image = true + endif + -%} + {%- if product != blank and first_image -%} + {%- if collection_page and settings.image_behaviour == 'slider' -%} + + {% if collection_img_view != 'first' and product.media[1] != null %} + {% assign show_product = false %} + {%- for image in product.media -%} + {% if img_view == 'last' %} + {% if forloop.last == true %} + {% assign show_product = true %} + {% endif %} + {% else %} + {% if forloop.index == 2 %} + {% assign show_product = true %} + {% else %} + {% assign show_product = false %} + {% endif %} + {% endif %} + {% unless show_product %}{% continue %}{% endunless %} + {% unless layout == 'list-compact' -%} + + {%- endunless %} + {{ image.alt | default: product.title | escape }} + {% unless layout == 'list-compact' %}{% endunless %} + {%- endfor -%} + {% endif %} + {% assign show_product = true %} + {% if img_view == 'last' and collection_img_view == 'first' %} + {% assign product_images_size = product.media | size | minus: 1 %} + {% assign product_image_first = product.media | slice: 0 %} + {% assign product_image_last = product.media | slice: product_images_size %} + {% assign product_images_new = product_image_first | concat: product_image_last %} + {% if product_images_size > 1 %} + {% assign product_rest_size = product_images_size | minus: 1 %} + {% assign product_image_rest = product.media | slice: 1, product_rest_size %} + {% assign product_images_new = product_images_new | concat: product_image_rest %} + {% endif %} + {% else %} + {% assign product_images_new = product.media %} + {% endif %} + {%- for image in product_images_new -%} + {% if collection_img_view != 'first' %} + {% if img_view == 'last' %} + {% if forloop.last == true %} + {% assign show_product = false %} + {% endif %} + {% elsif img_view == 'second' %} + {% if forloop.index == 2 %} + {% assign show_product = false %} + {% else %} + {% assign show_product = true %} + {% endif %} + {% endif %} + {% elsif img_view == 'last' %} + + {% endif %} + {% unless show_product %}{% continue %}{% endunless %} + {% unless layout == 'list-compact' %}{% endunless %} + {{ image.alt | default: product.title | escape }} + {% unless layout == 'list-compact' %}{% endunless %} + {%- endfor -%} + + {%- else -%} + {% unless layout == 'list-compact' %}{% endunless %} + + {{ first_image.alt | default: product.title | escape }} + + {% if show_secondary_image and settings.image_behaviour != 'slider' %} + + {{ second_image.alt | default: product.title | escape }} + + {% endif %} + {% unless layout == 'list-compact' %}{% endunless %} + {%- endif -%} + {%- elsif product.media[0].media_type == 'video' or product.media[0].media_type == 'external_video' -%} + {% unless layout == 'list-compact' %}{% endunless %} + + {{ product.title }} + + {% unless layout == 'list-compact' %}{% endunless %} + {% else %} + + {{- 'product-' | append: placeholder_int | placeholder_svg_tag: 'placeholder-svg' -}} + + {%- endif -%} + {%- if static_color_picker == false -%} + {{ color_picker }} + {%- endif -%} + + {% comment %} {%- if quick_buy + and layout != 'list-compact' + and settings.layout_productcard != 'standard' + and layout != 'list' + -%} + {{ quick_buy | replace: '-quick-add-form_x', '1' }} + {%- endif -%} {% endcomment %} +
+ {%- endif -%} + {% if layout == 'list-compact' %}
{% else %}
{% endif %} + {%- if show_title or show_vendor -%} +

+ {%- if show_vendor -%} + + {{ vendor }} + + {%- endif -%} + {%- if show_title -%} + {{ title }} + {%- endif -%} + {%- if layout == 'list-compact' and product.has_only_default_variant == false -%} + {% if enable_variant_picker == false or enable_variant_picker and available_variants.size == 1 %} + + {{ current_variant.title }} + + {%- endif -%} + {%- endif -%} +

+ {%- endif -%} + {%- if rating_value and show_rating -%} +

+ + {%- if rating_count -%} + {{ rating_count }} + {{ 'product.reviews.count' | t: count: rating_count }} + {%- endif -%} + +

+ {%- endif -%} + {%- if show_stock -%} + {%- render 'product-deliverytime', + product: product, + show_stock: false, + current_variant: current_variant, + container: 'p', + extra_class: 'list-hide', + origin: 'productitem' + -%} + {%- endif -%} + {%- if show_price -%} +

+ {%- liquid + comment + start Yagi app code + endcomment + assign product_price_min = product.price_min + assign product_price_max = product.price_max + assign current_variant_price = current_variant.price + assign current_variant_compare_at_price = current_variant_compare_at_price + + assign public_or_tags_matched = true + + if product.metafields.app--168074346497.segment_tags.value.size > 0 + assign public_or_tags_matched = false + endif + + for etag in product.metafields.app--168074346497.segment_tags.value + if customer.tags contains etag + assign public_or_tags_matched = true + break + endif + endfor + + if public_or_tags_matched + assign current_variant_price = current_variant.metafields.app--168074346497.auto_discounted_price.value | default: current_variant.price + assign current_variant_compare_at_price = current_variant.compare_at_price + + assign product_price_min = product.metafields.app--168074346497.min_auto_discounted_price.value | default: product.price_min + + if shop.metafields.app--168074346497.discount_percentage.value > 0.005 + assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0 + assign deducted_percentage = 1.0 | minus: discount_percentage + assign current_variant_price = current_variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + endif + + if current_variant_price < current_variant.price and current_variant_compare_at_price == 0 or current_variant_compare_at_price == blank + assign current_variant_compare_at_price = current_variant.price + endif + + if layout == 'list-compact' + assign price = current_variant_price | money + else + assign price = product_price_min | money + endif + endif + + assign price_min = product_price_min | money + assign price_max = product_price_max | money + + comment + end Yagi app code + endcomment + -%} + + {%- if product.price_varies and settings.show_price_varies and layout != 'list-compact' -%} + + {{ price_min -}} +  - {{ price_max }} + {%- else -%} + {%- if current_variant_compare_at_price > current_variant_price -%} + {{ current_variant_compare_at_price | money }}  + {%- endif -%} + {{ price }} + {%- endif -%} + {%- if current_variant.unit_price_measurement -%} + + {{ 'product.unit_price_label' | t }} {{ current_variant.unit_price | unit_price_with_measurement: current_variant.unit_price_measurement }} + + {%- endif -%} +

+ {%- endif -%} + +{%- if quick_buy + and layout != 'list-compact' + and settings.layout_productcard != 'standard' + and layout != 'list' +-%} +
+ {{ quick_buy | replace: '-quick-add-form_x', '1' }} +
+{%- endif -%} + + + {%- if color_picker and static_color_picker -%} + {{ color_picker }} + {%- endif -%} + {% if layout == 'list-compact' %} +
+ {% elsif settings.layout_productcard != 'variant_picker' %} +
+ {% endif %} + + {% if quick_buy %} + {% if layout == 'hotspot' or layout == 'list' or layout == 'grid' %} + {{ quick_buy | replace: '-quick-add-form_x', '1' }} + {% endif %} + {% endif %} + + {% comment %} + {%- if quick_buy and settings.layout_productcard != 'variant_picker' -%} + {% if layout == 'list-compact' %}
{% endif %} + {{ quick_buy | replace: '-quick-add-form_x', '2' }} + {% if layout == 'list-compact' %}
{% endif %} + {%- endif -%} + {% endcomment %} + {%- if quick_buy and layout == 'list-compact' -%} +
+ {{ quick_buy | replace: '-quick-add-form_x', '2' }} +
+ {%- endif -%} + {% if layout == 'list-compact' %} +
+ {% elsif settings.layout_productcard != 'variant_picker' %} +
+ {% endif %} + + diff --git a/snippets/product-labels.liquid b/snippets/product-labels.liquid new file mode 100644 index 0000000..417f52e --- /dev/null +++ b/snippets/product-labels.liquid @@ -0,0 +1,91 @@ +{%- liquid + assign current_variant = product.selected_or_first_available_variant + assign custom_label_namespace = settings.product_custom_label | split: '.' | first + assign custom_label_key = settings.product_custom_label | split: '.' | last + assign custom_label = product.metafields[custom_label_namespace][custom_label_key] + assign total_stock = 0 + + comment + start Yagi app code + endcomment + assign current_variant_price = current_variant.price + assign current_variant_compare_at_price = current_variant.compare_at_price + + assign public_or_tags_matched = true + + if product.metafields.app--168074346497.segment_tags.value.size > 0 + assign public_or_tags_matched = false + endif + + for etag in product.metafields.app--168074346497.segment_tags.value + if customer.tags contains etag + assign public_or_tags_matched = true + break + endif + endfor + + if public_or_tags_matched + assign current_variant_price = current_variant.metafields.app--168074346497.auto_discounted_price.value | default: current_variant.price + assign current_variant_compare_at_price = current_variant.compare_at_price + + if shop.metafields.app--168074346497.discount_percentage.value > 0.005 + assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0 + assign deducted_percentage = 1.0 | minus: discount_percentage + assign current_variant_price = current_variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + endif + + if current_variant_price < current_variant.price and current_variant_compare_at_price == 0 or current_variant_compare_at_price == blank + assign current_variant_compare_at_price = current_variant.price + endif + endif + + comment + end Yagi app code + endcomment + + if origin == 'productitem' + for variant in product.variants + if variant.matched and variant.inventory_quantity > 0 + assign total_stock = total_stock | plus: variant.inventory_quantity + endif + endfor + endif + if total_stock == 0 + assign total_stock = current_variant.inventory_quantity + endif + + if current_variant_compare_at_price > current_variant_price and settings.show_sale_label + assign show_sale_label = true + if settings.sale_label_price == 'percentage' + assign discount = current_variant_compare_at_price | minus: current_variant_price | times: 100.0 | divided_by: current_variant_compare_at_price + if discount > 1 + assign discount = discount | round + else + assign discount = discount | round: 1 + endif + if discount == 100 and product.price != 0 + assign discount = discount | minus: 0.1 + endif + elsif settings.sale_label_price == 'amount' + assign discount = current_variant_compare_at_price | minus: current_variant_price | money + endif + endif +-%} + + + {%- if show_sale_label -%} + {{ 'product.sale_tag' | t }}{% if settings.sale_label_price == 'percentage' %} -{{ discount }}%{% elsif settings.sale_label_price == 'amount' %} -{{ discount }}{% endif %} + {%- endif -%} + {%- if settings.show_stock_label and total_stock > 0 and total_stock <= settings.stock_label_qty -%} + {{ 'product.stock_tag' | t }} + {%- endif -%} + {%- if settings.show_out_of_stock_label and total_stock <= 0 and current_variant.available == false -%} + {{ 'product.not_in_stock_tag' | t }} + {%- endif -%} + {%- if total_stock <= 0 and current_variant.inventory_management != nil and current_variant.inventory_policy == 'continue' and current_variant.available and current_variant.inventory_quantity <= 0 and settings.preorder -%} + {{ 'product.preorder_tag' | t }} + {%- endif -%} + {%- if custom_label != blank -%} + {{ custom_label }} + {%- endif %} +