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 Alice_Z Aug 13, 2024作为一名 Shopify 商家,您可能会遇到客户在结账时无法完成订单的情况。为了找到客户未完成订单的原因,您可以在 Shopify 后台的订单界面中查看相应的弃单详细信息。帮...
By Vikki Aug 4, 2024如果您是一位经营网店的商家,那么您肯定遇到过一些技术上的挑战,这些挑战可能会直接影响到您网店的功能。您是否曾经遇到过这样的情况:突然之间,某些功能停止了工作?那您该怎么办呢?...
By OwenX7 Jul 23, 2024