So, I had a perfectly working theme that stopped doing calculations. @lubos
Something changed?
Seems to be that The result of math operations on two variables can’t be assigned anymore to a third variable.
Also I will add that on the Theme Preview (Lorem Ipsum) Looks like it brings the Result and assigns correctly.
Mind that Total Weight in Template Shows Zero as Weight Custom Column won’t show in Theme Preview.
And below is the real example trat USED to work.
{% for column in table.columns %}
{% if column.label == “Weight” %}
{% assign weightIndex = forloop.index0 %} (Gets the position of the Weight Column)
{% endif %}
{% if column.label == “Qty” %}
{% assign quantityIndex = forloop.index0 %} (Gets the position of the Qty Column)
{% endif %}
{% endfor %}
{% for row in table.rows %}
{% assign Weight = row.cells[weightIndex].text %} (Gets the Weight of the Product) Works
{% assign Quant = row.cells[quantityIndex].text %} (Gets the Qty of the Product) Works
{{Weight}} Weight <-------------------- This displays the Weight correctly
{{Quant}} Quant <-------------------- This displays the Quantity correctly
{% assign rowWeightSum = Weight | times: Quant %} <-------------------- This should multiply the weight of each item to the Qty of the item.
rowWeightSum {{rowWeightSum}} rowWeightSum <-------------------- This gives an empty Result. Should Display the sum of the row Weight * Qty
{% assign totalWeight = totalWeight | plus: rowWeightSum %}
{% assign NQuant = Quant | times: 1 %}
{% assign totalQuant = totalQuant | plus: NQuant %}
Complete Theme Below
<table style="padding: 30px">
<thead>
<tr>
<td colspan="99">
<table style="margin-bottom: 20px"><tr>
<td style="font-weight: bold; font-size: 32px">{{ title }}</td>
{% if business.logo != null %}<td style="text-align: right"><img src="{{ business.logo }}" style="max-height: 150px; max-width: 300px" /></td>{% endif %}
</tr></table>
<table style="margin-bottom: 20px"><tr>
<td>
<div style="font-weight: bold">{{ recipient.name }}</div>
<div>{{ recipient.address | newline_to_br }}</div>
<div>{{ recipient.identifier }}</div>
</td>
<td style="{% if business.address != null %}border-right-width: 1px; padding-right: 20px; {% endif %}text-align: right">
{% for field in fields %}
<div style="font-weight: bold">{{ field.label }}</div>
<div style="margin-bottom: 10px">{{ field.text }}</div>
{% endfor %}
</td>
{% if business.address != null %}
<td style="padding-left: 20px; width: 1px; white-space: nowrap">
<div style="font-weight: bold">{{ business.name }}</div>
<div>{{ business.address | newline_to_br }}</div>
<div>{{ business.identifier }}</div>
</td>
{% endif %}
</tr></table>
<div style="font-size: 14px; font-weight: bold; margin-bottom: 20px">{{ description }}</div>
</td>
</tr>
<tr><td colspan='99' style="text-align: right; passing: 10px"><!--Page Counter--></td></tr>
<tr>
{% for column in table.columns %}
<td style="font-weight: bold; padding: 5px 10px; text-align: {{ column.align }}; border-left-width: 1px; border-bottom-width: 1px; border-top-width: 1px{% if forloop.last == true %}; border-right-width: 1px{% endif %}{% if column.nowrap %}; width: 80px{% endif %}">{{ column.label }}</td>
{% endfor %}
{% for column in table.columns %}
{% if column.label == "Weight" %}
{% assign weightIndex = forloop.index0 %}
{% endif %}
{% if column.label == "Qty" %}
{% assign quantityIndex = forloop.index0 %}
{% endif %}
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in table.rows %}
{% assign Weight = row.cells[weightIndex].text %}
{% assign Quant = row.cells[quantityIndex].text %}
{% assign rowWeightSum = Weight | times: Quant %}
{% assign totalWeight = totalWeight | plus: rowWeightSum %}
{% assign NQuant = Quant | times: 1 %}
{% assign totalQuant = totalQuant | plus: NQuant %}
<tr>
{% for cell in row.cells %}
<td style="padding: 5px 10px; text-align: {{ table.columns[forloop.index0].align }}; border-left-width: 1px{% if forloop.last == true %}; border-right-width: 1px{% endif %}{% if table.columns[forloop.index0].nowrap %}; white-space: nowrap; width: 80px{% endif %}">{{ cell.text | newline_to_br }}</td>
{% endfor %}
</tr>
{% endfor %}
<tr>
{% for column in table.columns %}
<td style="border-bottom-width: 1px; border-left-width: 1px{% if forloop.last == true %}; border-right-width: 1px{% endif %}"> </td>
{% endfor %}
</tr>
{% for total in table.totals %}
<tr>
<td colspan="{{ table.columns | size | minus:1 }}" style="padding: 5px 10px; text-align: right{% if total.emphasis == true %}; font-weight: bold{% endif %}">{{ total.label }}</td>
<td style="border-left-width: 1px; white-space: nowrap; border-right-width: 1px; border-bottom-width: 1px; padding: 5px 10px; text-align: right{% if total.emphasis == true %}; font-weight: bold{% endif %}">{{ total.text }}</td>
</tr>
{% endfor %}
{% for field in custom_fields %}
<tr>
<td colspan="99">
<div style="font-weight: bold; padding-top: 20px">{{ field.label }}</div>
<div>{{ field.text | newline_to_br }}</div>
</td>
</tr>
{% endfor %}
<tr>
<td colspan="99">
{% if emphasis.text != null and emphasis.positive %}
<div style="text-align: center; margin-top: 40px"><span style="color: #006400; border-width: 5px; border-color: #006400; padding: 10px; font-size: 20px">{{ emphasis.text | upcase }}</span></div>
{% endif %}
{% if emphasis.text != null and emphasis.negative %}
<div style="text-align: center; margin-top: 40px"><span style="color: #FF0000; border-width: 5px; border-color: #FF0000; padding: 10px; font-size: 20px">{{ emphasis.text | upcase }}</span></div>
{% endif %}
</td>
</tr>
</tbody>
<tr>
<td colspan="30">
<div style="font-weight: bold; padding-top: 20px">Total Weight</div>
</td>
</tr>
<tr>
<td>{{totalWeight}} kgs</td>
</tr>
<tr>
<td colspan="30"><div style="font-weight: bold; padding-top: 20px">Total Quantity</div></td>
</tr>
<tr>
<td>
{{totalQuant}}
</td>
</tr>
</table>