// Save product ID to localStorage, for use in the 'Recently viewed products' section.
{%- if request.page_type == 'product' %}
try {
const items = JSON.parse(localStorage.getItem('cc-recently-viewed') || '[]');
// If product ID is not already in the recently viewed list, add it to the beginning.
if (!items.includes({{ product.id | json }})) {
items.unshift({{ product.id | json }});
}
// Set recently viewed list and limit to 12 products.
localStorage.setItem('cc-recently-viewed', JSON.stringify(items.slice(0, 12)));
} catch (e) {}
{%- endif %}
评论 (0)