Liquid、JavaScript、主题、销售渠道。
{% assign related_keys = "related_antenna,related_batteries,related_charger,related_remote_speaker_mics,related_earpieces,related_carry_accessories" | split: ',' %}
{% assign related_labels = "Antenna,Batteries,Chargers,Microphones,Earpieces,Carry Attachments" | split: ',' %}
<div class="related-products-container">
<ul class="related-products-menu"><b>Accessories:</b>
{% for index in (0..related_keys.size ) %}
{% assign key = related_keys[index] %}
{% assign label = related_labels[index] %}
{% assign related_products = product.metafields.custom[key] %}
{% if related_products %}
<li><a href="#" class="related-products-tab{% if forloop.first %} active{% endif %}" data-key="{{ key }}">{{ label }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% for index in (0..related_keys.size ) %}
{% assign key = related_keys[index] %}
{% assign label = related_labels[index] %}
{% assign related_products = product.metafields.custom[key] %}
{% if related_products %}
<div class="related-products-content{% if forloop.first %} active{% endif %}" id="{{ key }}">
<div class="carousel">
<div class="carousel-arrow left"><</div>
<div class="carousel-track-container">
<div class="carousel-track">
{% assign related_product_handles = related_products.value | split: ',' %}
{% for handle in related_product_handles %}
{% assign related_product = all_products[handle] %}
{% if related_product %}
<div class="related-product">
<a href="{{ related_product.url }}">
<img src="{{ related_product.featured_image | img_url: 'medium' }}" alt="{{ related_product.title }}">
<p>{{ related_product.title }}</p>
</a>
</div>
{% else %}
<p>Related product not found: {{ handle }}</p>
{% endif %}
{% endfor %}
</div>
</div>
<div class="carousel-arrow right">></div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const tabs = document.querySelectorAll(".related-products-tab");
const contents = document.querySelectorAll(".related-products-content");
const carousels = document.querySelectorAll(".carousel");
tabs.forEach(tab => {
tab.addEventListener("click", function(e) {
e.preventDefault();
const key = this.getAttribute("data-key");
tabs.forEach(t => t.classList.remove("active"));
contents.forEach(c => c.classList.remove("active"));
this.classList.add("active");
document.getElementById(key).classList.add("active");
});
});
carousels.forEach(carousel => {
const leftArrow = carousel.querySelector(".carousel-arrow.left");
const rightArrow = carousel.querySelector(".carousel-arrow.right");
const trackContainer = carousel.querySelector(".carousel-track-container");
const track = carousel.querySelector(".carousel-track");
let scrollAmount = 0;
function getItemWidth() {
if (window.innerWidth <= 768) {
return trackContainer.clientWidth / 2;
} else {
return trackContainer.clientWidth / 3;
}
}
leftArrow.addEventListener("click", () => {
const itemWidth = getItemWidth();
scrollAmount -= itemWidth;
if (scrollAmount < 0) {
scrollAmount = 0;
}
trackContainer.scrollTo({
top: 0,
left: scrollAmount,
behavior: 'smooth'
});
});
rightArrow.addEventListener("click", () => {
const itemWidth = getItemWidth();
scrollAmount += itemWidth;
if (scrollAmount > track.scrollWidth - trackContainer.clientWidth) {
scrollAmount = track.scrollWidth - trackContainer.clientWidth;
}
trackContainer.scrollTo({
top: 0,
left: scrollAmount,
behavior: 'smooth'
});
});
window.addEventListener("resize", () => {
scrollAmount = 0;
trackContainer.scrollTo({
top: 0,
left: scrollAmount,
behavior: 'smooth'
});
});
});
});
</script>
这是我的商品配件代码的显示部分,原理是通过产品元字段的产品句柄的引用来实现配件产品的展示。
但是我发现了当我产品数量总数到达20个时(所有种类产品总和),后面的第21,22....所有产品都重复第20个产品,请问这是什么原因,时因为liquid语言的数组的大小最大就是20吗?有人可以帮我解决这个问题吗?
在当今竞争激烈的电商市场中,视觉效果是吸引和留住客户的关键因素之一。高质量的图片不仅能提升店铺的专业形象,还能显著提高转化率和用户体验。研究表明,优质的产品图片可以增...
By Vikki Sep 15, 2024您是否遇到过尝试在 Shopify 后台连接您在第三方购买的域名,但是遇到错误提示无法连接的情况? 我们懂您的困扰!不用担心,我将把我们在进行支持时遇到的最常见...
By OwenX7 Sep 8, 2024返校促销/劳动节促销是向大量客户展示您的商店的最佳时机。作为一名出海的跨境电商卖家,您该如何参与其中?您该如何在返校促销/劳动节促销中及时吸引在线购物者的注意力?您如何将促销...
By Alice_Z Aug 13, 2024