-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcollection.fb-product-update.liquid
68 lines (62 loc) · 3.36 KB
/
collection.fb-product-update.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{% layout none %}<?xml version="1.0"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
{%- paginate collection.products by 1000 -%}
{%- assign useSEOdescription = true -%}
{%- assign additionalImagesForVariants = true -%}
{%- assign includeOutOfStock = false -%}
{%- assign filterVariantImagesByColor = true -%}
{% comment %}
This template is used to add additional information to the Facebook product catalog
Documentation: https://business.czarto.com/2019/12/11/update-your-shopify-facebook-product-feed-with-missing-attributes/
<comment:title>{{ product.title}} {{variant.title}}</comment:title>
{% endcomment %}
<channel>
<title>{{ shop.name }} {{ collection.title | replace: '&', '&' }}</title>
<link>{{ shop.url }}</link>
<description>{{ collection.description | strip_html }}</description>
{% for product in collection.products %}
{%- assign GoogleProductCategory = product.metafields.mm-google-shopping.google_product_category -%}
{%- assign Gender = product.metafields.mm-google-shopping.gender -%}
{%- assign AgeGroup = product.metafields.mm-google-shopping.age_group -%}
{%- assign Material = product.metafields.mm-google-shopping.material -%}
{%- assign Color = "" -%}
{%- if product.variants.size > 1 -%}
{%- for variant in product.variants -%}
{%- if includeOutOfStock or variant.available -%}
{%- for option in product.options -%}
{%- if option == 'Color' -%}{% capture Color %}{{ variant.options[forloop.index0] }}{% endcapture %}{%- endif -%}
{%- endfor -%}
{% assign additional_images = product.images %}
{% if filterVariantImagesByColor %}{% assign additional_images = product.images | where: "alt", Color | sort: 'attached_to_variant' | reverse%}{% endif %}
<item>
<g:id>{{ variant.id }}</g:id>
{% if useSEOdescription and product.metafields.global.description_tag.size > 0 %}<g:description>{{ product.metafields.global.description_tag | strip_html | strip_newlines | replace: '&', '&' }}</g:description>{% endif %}
<g:google_product_category>{{ GoogleProductCategory | replace: '&', '&' }}</g:google_product_category>
{% if Material %}<g:material>{{ Material }}</g:material>{% endif %}
{% if Gender %}<g:gender>{{ Gender }}</g:gender>{% endif %}
{% if AgeGroup %}<g:age_group>{{ AgeGroup }}</g:age_group>{% endif %}
{% if additionalImagesForVariants %}
{% if additional_images.size > 1 %}{%- for image in additional_images offset:1 limit:10 -%}
<g:additional_image_link>https:{{ image.src | product_img_url: 'master' }}</g:additional_image_link>
{% endfor %}{% endif %}
{% endif %}
</item>
{%- endif -%}
{% endfor %}
{%- else -%}
<item>
<g:id>{{ product.variants[0].id }}</g:id>
<g:google_product_category>{{ GoogleProductCategory | replace: '&', '&' }}</g:google_product_category>
{% if useSEOdescription and product.metafields.global.description_tag.size > 0 %}<description>{{ product.metafields.global.description_tag | strip_html | strip_newlines | replace: '&', '&' }}</description>{% endif %}
{% if Material %}<g:material>{{ Material }}</g:material>{% endif %}
{% if Gender %}<g:gender>{{ Gender }}</g:gender>{% endif %}
{% if AgeGroup %}<g:age_group>{{ AgeGroup }}</g:age_group>{% endif %}
{% if product.images.size > 1 %}{%- for image in product.images offset:1 limit:10 -%}
<g:additional_image_link>https:{{ image.src | product_img_url: 'master' }}</g:additional_image_link>
{% endfor %}{% endif %}
</item>
{% endif %}
{% endfor %}
</channel>
</rss>
{% endpaginate %}