Hello. I am trying to get my store to sort alphabetically by vendor. It’s an online record store and I would like it to sort by artist’s last name, so Miles Davis sorts before Art Pepper (under D and P respectively instead of M and A). Since I can’t do this by SKU, or by product title without using the names “Davis, Miles” and “Pepper, Art” (or even worse something like “Beatles, The”) I was hoping I could enter the names in Vendor that way and sort them like that. I am using the Debut theme but am open to switching if there’s a way to do this. Thanks!
Something like this should get a list of vendors by alphabet
{% assign chars = '' %}
{% for vendor in shop.vendors %}
{% capture first_char %}{{ vendor | truncate: 1, '' | upcase}}{% endcapture %}
{% if forloop.first %}
<div>
<ul id="vendorlist">
{% endif %}
{% unless chars contains first_char %}
{% unless forloop.first %}
<div style="clear:both;"></div>
</ul>
</div>
{% endunless %}
<div>
<h2>{{ first_char }}</h2>
<ul>
{% capture temp %}{{ chars }}{{ first_char }}{% endcapture %}
{% assign chars = temp %}
{% endunless %}
<li><a href="/collections/vendors?q={{ vendor }}&sort_by=created-descending">{{vendor | capitalize}}</a></li>
{% endfor %}
Hi Thomas,
Mybe you can help me:
this code works for us but I would like to split in in 3 or 4 columns.
Do you know how ?
{% assign counter = 0 %}
{% for vendor in shop.vendors %}
{% assign counter = counter | plus: 1 %}
{% endfor %}
{% assign counter_divided_by_3 = counter | divided_by: 3 | floor %}
- {{vendor | capitalize}} {% endfor %}
{{ page.content }}
{% assign chars = ‘’ %}
{% for vendor in shop.vendors %}
{% capture first_char %}{{ vendor | truncate: 1, ‘’ | upcase}}{% endcapture %}
{% if forloop.first %}
-
{% endif %}
{% unless chars contains first_char %}
{% unless forloop.first %}
{{ first_char }}
-
{% capture temp %}{{ chars }}{{ first_char }}{% endcapture %}
{% assign chars = temp %}
{% endunless %}