Create list of unique collections based on current collection

Tourist
27 0 2

I've created a collection naming scheme formatted "Tier Number":"Tier1 Name" - "Tier2 Name" - "Tier3 Name".

In practice this would look like "3:Ski - Clothing - Jackets & Outerwear"

I am then trying to build a sidebar menu that:

1) checks current collection name for whatever is previous to ":", or the Tier Number

2) gets all associated collections of products in current collection(unique list only)

3) only display's collections in sidebar if their Tier Number is 1 above current collection's. For example if current collection page title is "1:Men's Clothing", the sidebar should only display collections associated with products in current collection that contain "2:"

 

The issue I'm having is building an array of all collections the current collection contains that can then be sorted based on the above parameters.

Here is my starting block:

{% assign col_count = collection.products_count %}
{% assign current_collection = collection.title %}
{% assign all_collections = "" %}
 {% if col_count > 0 %}
    {% for product in collection.products %}
  	   {% for collections in product.collections %}
          {% assign all_collections = collection.title %}
       {% endfor %}
    {% endfor %}
    {% comment %}Logic for sorting through the all_collections for display goes here {% endcomment %}
 {% endif %}

 

0 Likes
Tourist
27 0 2

Here is something a bit more complete, though probably not clean from a efficient code perspective.

 

{% assign col_count = collection.products_count %}
{% assign current_collection = collection.title %}
          <p>{{current_collection}}</p>
          	{% if col_count > 0 %}
          		{% if current_collection contains "1:" %}
          		{% for product in collection.products %}
  					{% for collection in product.collections %}
          				{% if collection.title contains "2:" %}
          					{{collection.title}}
          				{% endif %}
          			{% endfor %}
				{% endfor %}
          		{% endif %}
          		{% if current_collection contains "2:" %}
          		{% for product in collection.products %}
  					{% for collection in product.collections %}
          				{% if collection.title contains "3:" %}
          					{{collection.title}}
          				{% endif %}
          			{% endfor %}
				{% endfor %}
          		{% endif %}
          	{% endif %}

 

0 Likes
Highlighted
Shopify Partner
2560 39 582

Hi a-aron,

Just to confirm -- are you aware of pagination? I mean, the 

{% for product in collection.products %}

loop can access only products from the current pagination page, so if you're on the page 1 and some collection is only present on the products from the second page, it will not be seen by your code.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com! My post solved your problem? This is my Paypal too :)
0 Likes
Shopify Partner
130 0 12

I think you can definitely create a collection page like that using PageFly - Page Builder, without touching HTML code. This app helps you create any highly customizable Shopify pages. PageFly is still free of cost to collect users' feedback, just go ahead and give it a try.

Hope this helps ;)

Download free Shopify theme: https://www.sellersmith.com/pages/sellersmith-free-themes
0 Likes
Tourist
27 0 2

Ah pagination is quite the wrench in this plan.

 

Seems I could use the same logic and same collection title analysis but utilize tags for tier 2 and tier 3 display.  This would remove pagination as an issue, correct?

More explanation:

1) If Collection contains "1:" only display tags containing "2:"

2) If Collection or Active tag contains "2:" display tags containing "3:"

--------- or ---------

Would it be better to simply make link lists(menus) for all Tiers and then populate these menus in the sidebar based on current collection and menu title matching?

This would require quite a few menus to be created, 1 for all Tier 1 collections(Tier1 -> Tier2), one for all Tier 2 collections(Tier2 -> Tier3).

 

0 Likes
Shopify Partner
2560 39 582

These options should work, both of them, i's just a question of what's easier to use/maintain...

Tags will probably emulate you initial idea -- instead of checking for collection, check for tags on which this collection is based?

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com! My post solved your problem? This is my Paypal too :)
0 Likes
Tourist
27 0 2

Well if I check for tags used to build collection I won't get a clear picture of what is needed for the sub-menu in that collection because it doesn't contain the values i'd like to display.

For example:

You are on a collection of Men's Boots.  That collection is build using two tags...Mens and Boots.  In the sidebar of this collection I'd like to display links to the collections Tall, Short.  I click on Tall, and then the menu on the sidebar shows Hiking, Snowboard, Ski.

The two issues in the example above are

a) how does clicking on Tall know to show Hiking, Snowboard, Ski?

b) how does clicking on Tall change the menu content for additional selection of Hiking, Snowboard, Ski?

0 Likes