Storing line_items in an Associative Array

Dvrb
New Member
1 0 0

When generating a "Order confirmation"  email I'd like a list of the products sorted in "arrays" based on the vendor.

But I can't figure out how to setup line items to be associated with there vendor.

Here is what I'm trying;

{% assign vendor_count = 0 %}
{% capture vendor_check %}
    {% for line in line_items %}
        {{ line.product.vendor }}{% if forloop.last != true %},{% endif %}
    {% endfor %}
{% endcapture %}

{% assign line_vendor = vendor_check | split: ',' | uniq %}

{%- assign vendor_items = line_items | where: "vendor", vendor -%}

{% for vendor in line_vendor %}
      {% assign vendor_count = vendor_count | plus: 1 %}
      <div><strong>Delivery {{ vendor_count }} - {{ vendor }}</strong></div>
      {% for line in vendor_items %}
          {{ line.title }}<br>      
      {% endfor %}  
{% endfor %}

Current output:
Delivery 1 - Vendor#1
Product 1
Product 2
Product 3
Product 4

Delivery 2 - Vendor#2
Product 1
Product 2
Product 3
Product 4

 

Desired output:
Delivery 1 - Vendor#1
Product 1
Product 2

Delivery 2 - Vendor#2
Product 3
Product 4

 

What am I doing wrong here?

0 Likes