Skip to content

Commit 9cb2f15

Browse files
Make line_item_tax_total available in templates (#93)
1 parent dc1cca6 commit 9cb2f15

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/frontend/tags/cart.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ These snippets might come in handy... they're all pretty self-explanatory:
5757
* `{{ cart:sub_total }}`
5858
* `{{ cart:discount_total }}`
5959
* `{{ cart:tax_total }}`
60+
* `{{ cart:line_item_tax_total }}`
61+
* `{{ cart:shipping_tax_total }}`
6062
* `{{ cart:shipping_total }}`
6163
* `{{ cart:is_free }}`
6264
* `{{ cart:has_physical_products }}`

src/Cart/AugmentedCart.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DuncanMcClean\Cargo\Orders\LineItem;
88
use Statamic\Data\AbstractAugmented;
99
use Statamic\Fields\Field;
10+
use Statamic\Fields\Value;
1011

1112
class AugmentedCart extends AbstractAugmented
1213
{
@@ -47,6 +48,7 @@ private function commonKeys(): array
4748
'tax_breakdown',
4849
'has_physical_products',
4950
'has_digital_products',
51+
'line_items_tax_total',
5052
];
5153
}
5254

@@ -126,4 +128,18 @@ public function hasDigitalProducts(): bool
126128
->filter(fn (LineItem $lineItem) => $lineItem->product()?->get('type', 'physical') === 'digital')
127129
->isNotEmpty();
128130
}
131+
132+
public function lineItemsTaxTotal()
133+
{
134+
$moneyField = new Field('line_items_tax_total', [
135+
'type' => 'money',
136+
'save_zero_value' => true,
137+
]);
138+
139+
return new Value(
140+
value: $this->data->lineItems()->sum('taxTotal'),
141+
fieldtype: $moneyField->fieldtype(),
142+
augmentable: $this->data
143+
);
144+
}
129145
}

src/Orders/AugmentedOrder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private function commonKeys(): array
4444
'tax_breakdown',
4545
'has_physical_products',
4646
'has_digital_products',
47+
'line_items_tax_total',
4748
'downloads',
4849
];
4950
}

0 commit comments

Comments
 (0)