Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions assets/upsell-carousel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class UpsellCarousel extends HTMLElement {
connectedCallback() {
const root = this.querySelector('.swiper');
if (!root) return;

this.swiper = new Swiper(root, {
slidesPerView: 1,
spaceBetween: 16,
pagination: {
el: this.querySelector('.swiper-pagination'),
clickable: true,
},
navigation: {
nextEl: this.querySelector('.swiper-button-next'),
prevEl: this.querySelector('.swiper-button-prev'),
},
breakpoints: {
750: { slidesPerView: 2 },
990: { slidesPerView: 3 },
},
});
}
}
customElements.define('upsell-carousel', UpsellCarousel);
4 changes: 4 additions & 0 deletions layout/theme.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@
document.documentElement.classList.add('shopify-design-mode');
}
</script>

{{ 'upsell-carousel.js' | asset_url | script_tag }}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.css">
<script defer src="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.js"></script>
</head>

<body class="gradient{% if settings.animations_hover_elements != 'none' %} animate--hover-{{ settings.animations_hover_elements }}{% endif %}">
Expand Down
68 changes: 68 additions & 0 deletions sections/main-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,40 @@
{%- endif -%}
{%- endif -%}
</p>
{%- when 'upsell_products' -%}
{% liquid
assign upsell_list = product.metafields.custom.upsell_products.value
assign upsell_count = upsell_list | size
%}
{% if upsell_count > 0 %}
<div
class="product-upsell"
{{ block.shopify_attributes }}
style="
margin-top: {{ block.settings.margin_top }}px;
margin-bottom: {{ block.settings.margin_bottom }}px;
background-color: {{ block.settings.background }};
"
>
{%- if block.settings.heading != blank -%}
<h3>{{ block.settings.heading }}</h3>
{%- endif -%}
<upsell-carousel>
<div class="swiper">
<div class="swiper-wrapper">
{%- for upsell_product in upsell_list -%}
<div class="swiper-slide">
{%- render 'card-product', card_product: upsell_product -%}
</div>
{%- endfor -%}
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</upsell-carousel>
</div>
{% endif %}
{%- when 'description' -%}
{%- if product.description != blank -%}
<div class="product__description rte quick-add-hidden" {{ block.shopify_attributes }}>
Expand Down Expand Up @@ -2086,6 +2120,40 @@
"info": "t:sections.main-product.blocks.icon_with_text.settings.heading.info"
}
]
},
{
"type": "upsell_products",
"name": "Upsell products",
"limit": 1,
"settings": [
{ "type": "text", "id": "heading", "label": "Tytuł", "default": "Polecane produkty" },
{
"type": "range",
"id": "margin_top",
"min": 0,
"max": 80,
"step": 4,
"unit": "px",
"label": "Margines górny",
"default": 24
},
{
"type": "range",
"id": "margin_bottom",
"min": 0,
"max": 80,
"step": 4,
"unit": "px",
"label": "Margines dolny",
"default": 24
},
{
"type": "color",
"id": "background",
"label": "Kolor tła",
"default": "#ffffff"
}
]
}
],
"settings": [
Expand Down
Loading