Untitled

 avatar
unknown
plain_text
a year ago
8.9 kB
6
Indexable
{% liquid
assign children = false 
assign childOptionName = false 
if product.tags contains 'Parent'
assign children = collections[product.handle]
assign childOptionName = children.title | split: ' - ' | last
endif
%}
{
	"id": {{product.id}},
	"options_with_values": [
		{% unless children and product.options[0] == 'Title' %}
    {%- for option in product.options_with_values -%}
		{
			"name": {{ option.name | escape | json }},
			"position": {{forloop.index | json }},
			"values": [{%- for value in option.values -%}{{ value | escape | json }}{%- unless forloop.last -%},{%-endunless-%}{%- endfor -%}
			]
		}
		{%- unless forloop.last -%},{%-endunless-%}
		{%-endfor-%}
		{% endunless %}
		{% if children %}
		{% if product.options.size > 0 and product.options[0] != 'Title'%},{% endif %}
    {
			"name": {{ childOptionName | json }},
			"position": 0,
			{% capture childOptionValuesString -%}
			{%- for child in children.products -%}
			{{ child.title | split: ' - ' | last | escape }}{%- unless forloop.last -%},{%-endunless-%}
			{%- endfor -%}
			{%- endcapture -%}
			"values": {{ childOptionValuesString | split: ',' | uniq | json }}
		}
		{% endif %}
	],
	"image_constraint_options": ["Color"],
	"variants":[
		{% if children %}
		{% for child in children.products %}
		{% for variant in child.variants %}
		{
			"id":{{ variant.id | json}},
			"available":{{ variant.available | json }},
			"option1":{% if product.options.size == 0 or product.options[0] == 'Title'%}{{ child.title | split: ' - ' | last | escape | json }}{% else %}{% assign childColorA = child.title | split: ' - ' %}{{ childColorA[1] | escape | json}}{% endif %},
			"option2":{% if product.options.size == 1 and product.options[0] != 'Title'%}{{ child.title | split: ' - ' | last | escape | json }}{% else %}{{ variant.option2 | escape | json}}{% endif %},
			"option3":{% if product.options.size == 2 %}{{ child.title | split: ' - ' | last | escape | json }}{% else %}{{ variant.option3 | escape | json}}{% endif %},
			"options":[
				{% if product.options.size == 1 and product.options[0] != 'Title' %}{{ childColorA[1] | json }},{% endif %}
				{{ child.title | split: ' - ' | last | escape | json }}
			],
			"price":{{ variant.price | json}},
			"compare_at_price":{{ variant.compare_at_price | json}},
			"inventory_quantity":{{ variant.inventory_quantity | json}},
			"title":{{ variant.title | escape | json}},
			{%- capture variantImages -%}
			{%- assign images_start = false -%}
			{%- for image in child.images -%}
				{ 
					"src": {{image.src | json}},
					"alt": {{image.alt | escape | json}},
					"aspect_ratio": {{image.aspect_ratio | json}},
					"width": {{image.width | json}},
					"height": {{image.height | json}}
				},
			{%-endfor-%}
			{%-endcapture-%}
			{%- assign vis = variantImages | strip | size | minus: 1 -%}
			"images": [{{ variantImages | strip | slice: 0, vis}}]
		}{%- unless forloop.last -%},{%-endunless-%}
		{% endfor %}
		{%- unless forloop.last -%},{%-endunless-%}
		{% endfor %}
		{% else %}
		{%-for variant in product.variants -%}
		{
			"id":{{ variant.id | json}},
			"available":{{ variant.available | json}},
			"option1":{{ variant.option1 | escape | json}},
			"option2":{{ variant.option2 | escape | json}},
			"option3":{{ variant.option3 | escape | json}},
			"options":[{% for option in variant.options %}{{option | escape | json}}{%- unless forloop.last -%},{%-endunless-%}{% endfor %}],
			"price":{{ variant.price | json}},
			"compare_at_price":{{ variant.compare_at_price | json}},
			"inventory_quantity":{{ variant.inventory_quantity | json}},
			"title":{{ variant.title | escape | json}},
			{%- capture variantImages -%}
			{%- assign images_start = false -%}
			{%- for image in product.images -%}
				{%- if image.variants.size > 0-%}
					{%- assign has_variant = false %}
					{%- for imgvariant in image.variants-%}
						{%- if imgvariant.id == variant.id -%}
							{%- assign images_start = true -%}
							{%- assign has_variant = true %}
						{%-endif-%}
					{%- endfor -%}
					{%- if images_start == true and has_variant == false -%}{%- break -%}{%- endif -%}
				{%- endif -%}
				{%- if images_start -%}
				{ 
					"src": {{image.src | json}},
					"alt": {{image.alt | escape | json}},
					"aspect_ratio": {{image.aspect_ratio | json}},
					"width": {{image.width | json}},
					"height": {{image.height | json}}
				},
				{%- endif -%}
			{%-endfor-%}
			{%-endcapture-%}
			{%- assign vis = variantImages | strip | size | minus: 1 -%}
			"images": [{{ variantImages | strip | slice: 0, vis}}]
		}
		{%- unless forloop.last -%},{%-endunless-%}
		{%-endfor-%}
		{%-endif-%}
	],
	"images":[{%- for image in product.images -%}
		{ 
			"src": {{image.src | json}},
			"alt": {{image.alt | escape | json}},
			"aspect_ratio": {{image.aspect_ratio | json}},
			"width": {{image.width | json}},
			"height": {{image.height | json}},
			"variants":[
				{%-for variant in image.variants -%}
				{
					"id":{{ variant.id | json}},
					"option1":{{ variant.option1 | json}}
				}{%- unless forloop.last -%},{%-endunless-%}
			{%-endfor-%}]
		}{%- unless forloop.last -%},{%-endunless-%}
	{%-endfor-%}],
	"videos": {{ product.media | where: 'media_type', 'video' | json }},
	"tags": [{%- for tag in product.tags -%}{{ tag | escape | json }}{%- unless forloop.last -%},{%-endunless-%}{%-endfor%}],
	"discounts_structure": {
		"groups": [
			{
				"id": 1,
				"tiers": [
					{
						"id": 1,
						"discount": [
							{
								"min_quantity": 3,
								"discount_amount": 1
							},
							{
								"min_quantity": 6,
								"discount_amount": 2
							},
							{
								"min_quantity": 9,
								"discount_amount": 3
							},
							{
								"min_quantity": 12,
								"discount_amount": 4
							}
						]
					},
					{
						"id": 2,
						"discount": [
							{
								"min_quantity": 3,
								"discount_amount": 0.5
							},
							{
								"min_quantity": 6,
								"discount_amount": 1
							},
							{
								"min_quantity": 9,
								"discount_amount": 1.5
							},
							{
								"min_quantity": 12,
								"discount_amount": 2
							}
						]
					},
					{
						"id": 3,
						"discount": [
							{
								"min_quantity": 3,
								"discount_amount": 0.3
							},
							{
								"min_quantity": 6,
								"discount_amount": 0.6
							},
							{
								"min_quantity": 9,
								"discount_amount": 1
							},
							{
								"min_quantity": 12,
								"discount_amount": 1.5
							},
							{
								"min_quantity": 24,
								"discount_amount": 2
							}
						]
					},
					{
						"id": 4,
						"discount": [
							{
								"min_quantity": 8,
								"discount_amount": 0.5
							},
							{
								"min_quantity": 16,
								"discount_amount": 1
							},
							{
								"min_quantity": 24,
								"discount_amount": 1.5
							},
							{
								"min_quantity": 32,
								"discount_amount": 2
							}
						]
					},
					{
						"id": 5,
						"discount": [
							{
								"min_quantity": 3,
								"discount_amount": 0.4
							},
							{
								"min_quantity": 6,
								"discount_amount": 0.8
							},
							{
								"min_quantity": 9,
								"discount_amount": 1.5
							},
							{
								"min_quantity": 12,
								"discount_amount": 2
							},
							{
								"min_quantity": 24,
								"discount_amount": 2.5
							}
						]
					}
				]
			},
			{
				"id": 2,
				"tiers": [
					{
						"id": 1,
						"discount": [
							{
								"min_quantity": 8,
								"discount_amount": 0.5
							},
							{
								"min_quantity": 12,
								"discount_amount": 1
							},
							{
								"min_quantity": 16,
								"discount_amount": 1.5
							},
							{
								"min_quantity": 20,
								"discount_amount": 2
							},
							{
								"min_quantity": 24,
								"discount_amount": 2.5
							},
							{
								"min_quantity": 32,
								"discount_amount": 3
							},
							{
								"min_quantity": 40,
								"discount_amount": 3.25
							},
							{
								"min_quantity": 48,
								"discount_amount": 3.5
							},
							{
								"min_quantity": 56,
								"discount_amount": 3.75
							},
							{
								"min_quantity": 64,
								"discount_amount": 4
							},
							{
								"min_quantity": 72,
								"discount_amount": 4.25
							},
							{
								"min_quantity": 80,
								"discount_amount": 4.5
							},
							{
								"min_quantity": 88,
								"discount_amount": 4.75
							},
							{
								"min_quantity": 96,
								"discount_amount": 5
							}
						]
					}
				]
			}
		]
	}

}
Editor is loading...
Leave a Comment