Skip to content

Commit eb4736e

Browse files
committed
fix: optimize products fetching in featured-collection
1 parent 28c420b commit eb4736e

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

sections/featured-collection.liquid

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@
3939
{%- endstyle -%}
4040

4141
{%- liquid
42-
assign products_to_display = section.settings.collection.all_products_count
42+
assign featured_collection = section.settings.collection
43+
assign collection_products = featured_collection.products
44+
assign collection_products_count = featured_collection.products_count
45+
assign products_to_display = section.settings.products_to_show
46+
assign more_in_collection = false
4347

44-
if section.settings.collection.all_products_count > section.settings.products_to_show
45-
assign products_to_display = section.settings.products_to_show
48+
if collection_products_count > products_to_display
4649
assign more_in_collection = true
50+
else
51+
assign products_to_display = collection_products_count
4752
endif
4853

4954
assign columns_mobile_int = section.settings.columns_mobile | plus: 0
@@ -102,37 +107,40 @@
102107
>
103108
{% assign skip_card_product_styles = false %}
104109

105-
{%- if section.settings.collection.products.size > 0 -%}
110+
{%- if collection_products.size > 0 -%}
111+
{% assign skip_card_product_styles = false %}
106112
{% assign lazy_load = false %}
107-
{% paginate section.settings.collection.products by section.settings.products_to_show %}
108-
{%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
109-
{% if lazy_load == false and forloop.index > max_columns_to_show %}
110-
{% assign lazy_load = true %}
113+
{% if products_to_display > max_columns_to_show %}
114+
{% assign lazy_load = true %}
115+
{% endif %}
116+
{%- for product in collection_products limit: products_to_display -%}
117+
<li
118+
id="Slide-{{ section.id }}-{{ forloop.index }}"
119+
class="
120+
grid__item{% if show_mobile_slider or show_desktop_slider %} slider__slide{% endif %}{% if settings.animations_reveal_on_scroll %} scroll-trigger
121+
animate--slide-in{% endif %}
122+
"
123+
{% if settings.animations_reveal_on_scroll %}
124+
data-cascade
125+
style="--animation-order: {{ forloop.index }};"
111126
{% endif %}
112-
<li
113-
id="Slide-{{ section.id }}-{{ forloop.index }}"
114-
class="grid__item{% if show_mobile_slider or show_desktop_slider %} slider__slide{% endif %}{% if settings.animations_reveal_on_scroll %} scroll-trigger animate--slide-in{% endif %}"
115-
{% if settings.animations_reveal_on_scroll %}
116-
data-cascade
117-
style="--animation-order: {{ forloop.index }};"
118-
{% endif %}
119-
>
120-
{% render 'card-product',
121-
card_product: product,
122-
media_aspect_ratio: section.settings.image_ratio,
123-
image_shape: section.settings.image_shape,
124-
lazy_load: lazy_load,
125-
show_secondary_image: section.settings.show_secondary_image,
126-
show_vendor: section.settings.show_vendor,
127-
show_rating: section.settings.show_rating,
128-
skip_styles: skip_card_product_styles,
129-
section_id: section.id,
130-
quick_add: section.settings.quick_add
131-
%}
132-
</li>
133-
{%- assign skip_card_product_styles = true -%}
134-
{%- endfor -%}
135-
{% endpaginate %}
127+
>
128+
{%
129+
render 'card-product',
130+
card_product: product,
131+
media_aspect_ratio: section.settings.image_ratio,
132+
image_shape: section.settings.image_shape,
133+
lazy_load: lazy_load and forloop.index > max_columns_to_show,
134+
show_secondary_image: section.settings.show_secondary_image,
135+
show_vendor: section.settings.show_vendor,
136+
show_rating: section.settings.show_rating,
137+
skip_styles: skip_card_product_styles,
138+
section_id: section.id,
139+
quick_add: section.settings.quick_add
140+
%}
141+
</li>
142+
{%- assign skip_card_product_styles = true -%}
143+
{%- endfor -%}
136144
{%- else -%}
137145
{%- for i in (1..section.settings.columns_desktop) -%}
138146
<li
@@ -236,11 +244,11 @@
236244
"step": 1,
237245
"default": 4,
238246
"label": "t:sections.featured-collection.settings.products_to_show.label"
239-
},
247+
},
240248
{
241249
"type": "header",
242250
"content": "t:sections.featured-collection.settings.header_text.content"
243-
},
251+
},
244252
{
245253
"type": "inline_richtext",
246254
"id": "title",
@@ -284,7 +292,7 @@
284292
"type": "checkbox",
285293
"id": "show_description",
286294
"label": "t:sections.featured-collection.settings.show_description.label",
287-
"default": false
295+
"default": false
288296
},
289297
{
290298
"type": "select",
@@ -309,7 +317,7 @@
309317
{
310318
"type": "header",
311319
"content": "t:sections.featured-collection.settings.header_collection.content"
312-
},
320+
},
313321
{
314322
"type": "range",
315323
"id": "columns_desktop",
@@ -319,7 +327,7 @@
319327
"default": 4,
320328
"label": "t:sections.featured-collection.settings.columns_desktop.label"
321329
},
322-
{
330+
{
323331
"type": "checkbox",
324332
"id": "enable_desktop_slider",
325333
"label": "t:sections.featured-collection.settings.enable_desktop_slider.label",
@@ -357,7 +365,7 @@
357365
}
358366
],
359367
"default": "solid"
360-
},
368+
},
361369
{
362370
"type": "color_scheme",
363371
"id": "color_scheme",
@@ -487,13 +495,13 @@
487495
"label": "t:sections.featured-collection.settings.columns_mobile.options__2.label"
488496
}
489497
]
490-
},
498+
},
491499
{
492500
"type": "checkbox",
493501
"id": "swipe_on_mobile",
494502
"default": false,
495503
"label": "t:sections.featured-collection.settings.swipe_on_mobile.label"
496-
},
504+
},
497505
{
498506
"type": "header",
499507
"content": "t:sections.all.padding.section_padding_heading"

0 commit comments

Comments
 (0)