shopify - Displaying Collection thumbnails by matching Variant -


one of collections on shopify theme i'm editing uses settings: products must match - variant's title contains red

how go tweaking collection-loop.liquid template (or other snippets?) have collection use relevant variant product images associated red thumbnails, without messing other collections?

a: make alternate template , apply collection(s) in question

shopify allows make multiple templates each of main types of pages , set 1 want use in admin.

step 1: open theme editor live theme

  • go [your-shopify-store].myshopify.com/admin/themes
  • the top half of admin screen should showcase of live theme. click 'actions' (right above main preview) , select 'edit html/css'

step 2: create 'red' template

  • in folder list on left-hand side of editor, open 'templates' folder , click 'new template'
  • select 'collection' type , give name makes sense.

step 3: make desired updates file show off redness.

  • eg: images being displayed, first loop through variants on product , image of first variant 'red' option value.
  • depending on how theme set up, may need edit and/or duplicate-and-change 1 or more snippets. can find one(s) following 'include' , 'section' tags. 'include' tag points files in 'snippets' folder, , 'section' tag points files in 'sections' folder.
  • for drastic changes, recommend creating new snippets , including in alternate template instead. minor changes, though, can find out if you're on alternate template through liquid variable template.suffix
  • for example, loop through variants find 1 variant.title contains template.suffix - make collections.blue, collections.green, etc. , not need make further edits snippet.

step 4: preview alternate template make sure want

  • if collection called 'shirts' , alternate template called 'red', preview template as: /collections/shirts?view=red - view=red part tells shopify load alternate template.

step 5: repeat steps 3 & 4 until you're happy results.

step 6: apply new collection template collection(s) want default cool (hot?) new style.

  • in shopify admin, select (from left-hand navigation) 'products' 'collections'
  • select collection want apply template to
  • now have @ least 1 alternate template, template selector should visible in right-hand column.
  • change template default new one, click save, kick , relax!

finding appropriate image show

this part vary in complexity depending on how products set up. going assume there option on each product named 'color', 'color' can of 3 option columns on product (ie, can't assume first option colour option)

step 1: make new snippet contain image-finding logic (it keeps our code clean , reusable)

  • in theme editor, make sure 'snippets' folder expanded in right-hand pane
  • click 'add new snippet' link
  • give file meaningful name (such 'find-color-image')

step 2: in alternate collection template, find product loop , include new snippet

  • first, find product loop. should {% product in collection.products %}

  • immediately after above line, add {% include 'find-color-image', color: template.suffix, product:product %}(assuming template name matches colour looking - otherwise, change template.suffix colour want (wrapped in quotes), such 'red')

step 3: build find-color-image snippet. following code should you're looking for.

{% comment %} find-color-image.liquid: given product , colour,  set variable named color_image first variant image matches specified colour {% endcomment %}  {% comment %} clear leftover variables previous includes {% endcomment %} {% assign color_image = nil %}  {% comment %} loop through variants find 1 matching our colour {% endcomment %} {% variant in product.variants %}   {% comment %} don't care variants without featured image - skip using continue {% endcomment %}   {% unless variant.featured_image %}{% continue %}{% endunless %}    {% comment %}make sure comparison case-insensitive. variable named color expected passed when snippet included {% endcomment %}   {% assign opt1 = variant.option1 | downcase %}   {% assign opt2 = variant.option2 | downcase %}   {% assign opt3 = variant.option3 | downcase %}   {% assign target_color = color | downcase %}    {% comment %} check see if 1 of above options matches our target colour {% endcomment %}   {% if opt1 == target_color or opt2 == target_color or opt3 == target_color %}     {% assign color_image = variant.featured_image %}     {% break %}   {% endfor %}  {% endfor %} 

step 4: update image links in collection template

  • change references product's image color_image variable set in above snippet.

hope helps!


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -