Skip to content

Commit 9149fb8

Browse files
authored
mail template prices now reflect input price type setting (#3865)
2 parents baf0174 + 4bb4ab9 commit 9149fb8

File tree

10 files changed

+190
-13
lines changed

10 files changed

+190
-13
lines changed

src/Model/Mail/MailTemplateConfiguration.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ protected function createOrderStatusMailTemplateVariables(): MailTemplateVariabl
126126
->addVariable(OrderMail::VARIABLE_PAYMENT, t('Chosen payment name'), MailTemplateVariables::CONTEXT_BODY)
127127
->addVariable(OrderMail::VARIABLE_PAYMENT_INFO, t('Chosen payment information (image, name, price)'), MailTemplateVariables::CONTEXT_BODY)
128128
->addVariable(
129-
OrderMail::VARIABLE_TOTAL_PRICE,
129+
OrderMail::VARIABLE_TOTAL_PRICE_WITH_VAT,
130130
t('Total order price (including VAT)'),
131131
MailTemplateVariables::CONTEXT_BODY,
132132
)
133+
->addVariable(
134+
OrderMail::VARIABLE_TOTAL_PRICE_WITHOUT_VAT,
135+
t('Total order price (excluding VAT)'),
136+
MailTemplateVariables::CONTEXT_BODY,
137+
)
133138
->addVariable(
134139
OrderMail::VARIABLE_BILLING_ADDRESS,
135140
t('Billing address'),

src/Model/Order/Mail/OrderMail.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Shopsys\FrameworkBundle\Model\Order\Order;
1616
use Shopsys\FrameworkBundle\Model\Order\OrderUrlGenerator;
1717
use Shopsys\FrameworkBundle\Model\Order\Status\OrderStatus;
18+
use Shopsys\FrameworkBundle\Model\Pricing\PricingSetting;
1819
use Shopsys\FrameworkBundle\Twig\DateTimeFormatterExtension;
1920
use Shopsys\FrameworkBundle\Twig\HiddenPriceExtension;
2021
use Shopsys\FrameworkBundle\Twig\PriceExtension;
@@ -31,7 +32,8 @@ class OrderMail implements MessageFactoryInterface
3132
public const string VARIABLE_TRANSPORT_INFO = '{transport_info}';
3233
public const string VARIABLE_PAYMENT = '{payment}';
3334
public const string VARIABLE_PAYMENT_INFO = '{payment_info}';
34-
public const string VARIABLE_TOTAL_PRICE = '{total_price}';
35+
public const string VARIABLE_TOTAL_PRICE_WITH_VAT = '{total_price_with_vat}';
36+
public const string VARIABLE_TOTAL_PRICE_WITHOUT_VAT = '{total_price_without_vat}';
3537
public const string VARIABLE_BILLING_ADDRESS = '{billing_address}';
3638
public const string VARIABLE_DELIVERY_ADDRESS = '{delivery_address}';
3739
public const string VARIABLE_NOTE = '{note}';
@@ -45,7 +47,13 @@ class OrderMail implements MessageFactoryInterface
4547
public const string VARIABLE_ROUNDING_INFO = '{rounding_info}';
4648
public const string VARIABLE_ADDRESSES = '{addresses}';
4749

50+
public const string DISPLAY_PRICE_WITH_VAT = 'with_vat';
51+
public const string DISPLAY_PRICE_WITHOUT_VAT = 'without_vat';
52+
public const string DISPLAY_PRICE_BOTH = 'both';
53+
protected const string DISPLAY_PRICE_INPUT = 'input_price';
54+
4855
/**
56+
* @param string $mailTemplateDisplayPrice
4957
* @param \Shopsys\FrameworkBundle\Component\Setting\Setting $setting
5058
* @param \Shopsys\FrameworkBundle\Component\Router\DomainRouterFactory $domainRouterFactory
5159
* @param \Twig\Environment $twig
@@ -55,8 +63,10 @@ class OrderMail implements MessageFactoryInterface
5563
* @param \Shopsys\FrameworkBundle\Twig\DateTimeFormatterExtension $dateTimeFormatterExtension
5664
* @param \Shopsys\FrameworkBundle\Model\Order\OrderUrlGenerator $orderUrlGenerator
5765
* @param \Shopsys\FrameworkBundle\Twig\HiddenPriceExtension $hiddenPriceExtension
66+
* @param \Shopsys\FrameworkBundle\Model\Pricing\PricingSetting $pricingSetting
5867
*/
5968
public function __construct(
69+
protected readonly string $mailTemplateDisplayPrice,
6070
protected readonly Setting $setting,
6171
protected readonly DomainRouterFactory $domainRouterFactory,
6272
protected readonly Environment $twig,
@@ -66,6 +76,7 @@ public function __construct(
6676
protected readonly DateTimeFormatterExtension $dateTimeFormatterExtension,
6777
protected readonly OrderUrlGenerator $orderUrlGenerator,
6878
protected readonly HiddenPriceExtension $hiddenPriceExtension,
79+
protected readonly PricingSetting $pricingSetting,
6980
) {
7081
}
7182

@@ -131,7 +142,8 @@ protected function getVariablesReplacementsForBody(Order $order)
131142
self::VARIABLE_URL => $router->generate('front_homepage', [], UrlGeneratorInterface::ABSOLUTE_URL),
132143
self::VARIABLE_TRANSPORT => htmlspecialchars($order->getTransportItem()->getName(), ENT_QUOTES),
133144
self::VARIABLE_PAYMENT => htmlspecialchars($order->getPaymentItem()->getName(), ENT_QUOTES),
134-
self::VARIABLE_TOTAL_PRICE => $this->getFormattedPrice($order),
145+
self::VARIABLE_TOTAL_PRICE_WITH_VAT => $this->getFormattedPriceWithVat($order),
146+
self::VARIABLE_TOTAL_PRICE_WITHOUT_VAT => $this->getFormattedPriceWithoutVat($order),
135147
self::VARIABLE_BILLING_ADDRESS => $this->getBillingAddressHtmlTable($order),
136148
self::VARIABLE_DELIVERY_ADDRESS => $this->getDeliveryAddressHtmlTable($order),
137149
self::VARIABLE_NOTE => $this->getNoteHtml($order),
@@ -163,7 +175,7 @@ protected function getVariablesReplacementsForSubject(Order $order)
163175
* @param \Shopsys\FrameworkBundle\Model\Order\Order $order
164176
* @return string
165177
*/
166-
protected function getFormattedPrice(Order $order): string
178+
protected function getFormattedPriceWithVat(Order $order): string
167179
{
168180
$price = $this->priceExtension->priceTextWithCurrencyByCurrencyIdAndLocaleFilter(
169181
$order->getTotalPriceWithVat(),
@@ -174,6 +186,21 @@ protected function getFormattedPrice(Order $order): string
174186
return $this->hiddenPriceExtension->hidePriceFilter($price, $order->getCustomerUser());
175187
}
176188

189+
/**
190+
* @param \Shopsys\FrameworkBundle\Model\Order\Order $order
191+
* @return string
192+
*/
193+
protected function getFormattedPriceWithoutVat(Order $order): string
194+
{
195+
$price = $this->priceExtension->priceTextWithCurrencyByCurrencyIdAndLocaleFilter(
196+
$order->getTotalPriceWithoutVat(),
197+
$order->getCurrency()->getId(),
198+
$this->getDomainLocaleByOrder($order),
199+
);
200+
201+
return $this->hiddenPriceExtension->hidePriceFilter($price, $order->getCustomerUser());
202+
}
203+
177204
/**
178205
* @param \Shopsys\FrameworkBundle\Model\Order\Order $order
179206
* @return string
@@ -269,6 +296,7 @@ protected function getProductsHtmlTable(Order $order, array $orderItemTotalPrice
269296
'order' => $order,
270297
'orderItemTotalPricesById' => $orderItemTotalPricesById,
271298
'orderLocale' => $this->getDomainLocaleByOrder($order),
299+
'displayPrice' => $this->getDisplayPrice(),
272300
]);
273301
}
274302

@@ -319,6 +347,7 @@ protected function getTransportInfoHtml(Order $order, array $orderItemTotalPrice
319347
'orderTransportItem' => $orderTransportItem,
320348
'orderLocale' => $this->getDomainLocaleByOrder($order),
321349
'orderTransportTotalPrice' => $orderItemTotalPricesById[$orderTransportItem->getId()],
350+
'displayPrice' => $this->getDisplayPrice(),
322351
]);
323352
}
324353

@@ -336,6 +365,7 @@ protected function getPaymentInfoHtml(Order $order, array $orderItemTotalPricesB
336365
'orderPaymentItem' => $orderPaymentItem,
337366
'orderLocale' => $this->getDomainLocaleByOrder($order),
338367
'orderPaymentTotalPrice' => $orderItemTotalPricesById[$orderPaymentItem->getId()],
368+
'displayPrice' => $this->getDisplayPrice(),
339369
]);
340370
}
341371

@@ -373,4 +403,18 @@ protected function getAddressesHtml(Order $order): string
373403
'orderLocale' => $this->getDomainLocaleByOrder($order),
374404
]);
375405
}
406+
407+
/**
408+
* @return string
409+
*/
410+
protected function getDisplayPrice(): string
411+
{
412+
if ($this->mailTemplateDisplayPrice === static::DISPLAY_PRICE_INPUT) {
413+
return $this->pricingSetting->getInputPriceType() === PricingSetting::INPUT_PRICE_TYPE_WITH_VAT
414+
? static::DISPLAY_PRICE_WITH_VAT
415+
: static::DISPLAY_PRICE_WITHOUT_VAT;
416+
}
417+
418+
return static::DISPLAY_PRICE_BOTH;
419+
}
376420
}

src/Model/Order/PromoCode/DiscountCalculation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function calculatePercentageDiscountRoundedByCurrency(
5858
$totalItemPrice->getPriceWithoutVat()->multiply($multiplier),
5959
$currency,
6060
);
61+
62+
$priceWithVat = $this->rounding->roundPriceWithVatByCurrency(
63+
$this->priceCalculation->applyVatByPercent($priceWithoutVat, $vatPercent),
64+
$currency,
65+
);
6166
}
6267

6368
return new Price($priceWithoutVat, $priceWithVat);

src/Resources/config/parameters_common.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ parameters:
2323

2424
# Default extended classes mapping
2525
shopsys.entity_extension.map: {}
26+
27+
shopsys.mail_template.display_price: 'input_price'

src/Resources/config/services.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ services:
677677

678678
Shopsys\FrameworkBundle\Model\Module\ModuleList: ~
679679

680-
Shopsys\FrameworkBundle\Model\Order\Mail\OrderMail: ~
680+
Shopsys\FrameworkBundle\Model\Order\Mail\OrderMail:
681+
arguments:
682+
$mailTemplateDisplayPrice: '%shopsys.mail_template.display_price%'
681683

682684
Shopsys\FrameworkBundle\Model\Order\Messenger\HeurekaPlacedOrderMessageHandler:
683685
arguments:

src/Resources/translations/messages.cs.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,6 +4381,9 @@ msgstr "Celkem bez DPH"
43814381
msgid "Total including VAT"
43824382
msgstr "Celkem s DPH"
43834383

4384+
msgid "Total order price (excluding VAT)"
4385+
msgstr "Celková cena za objednávku (bez DPH)"
4386+
43844387
msgid "Total order price (including VAT)"
43854388
msgstr "Celková cena za objednávku (s DPH)"
43864389

@@ -4885,6 +4888,9 @@ msgstr "neobsahuje"
48854888
msgid "empty value"
48864889
msgstr "prázdná hodnota"
48874890

4891+
msgid "ex VAT"
4892+
msgstr "bez DPH"
4893+
48884894
msgid "files"
48894895
msgstr "soubory"
48904896

@@ -4909,6 +4915,9 @@ msgstr "větší než"
49094915
msgid "in category (between first and second row of products)"
49104916
msgstr "v kategorii (mezi prvním a druhým řádkem produktů)"
49114917

4918+
msgid "inc VAT"
4919+
msgstr "s DPH"
4920+
49124921
msgid "include"
49134922
msgstr "obsahuje"
49144923

src/Resources/translations/messages.en.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,6 +4381,9 @@ msgstr ""
43814381
msgid "Total including VAT"
43824382
msgstr ""
43834383

4384+
msgid "Total order price (excluding VAT)"
4385+
msgstr ""
4386+
43844387
msgid "Total order price (including VAT)"
43854388
msgstr ""
43864389

@@ -4885,6 +4888,9 @@ msgstr ""
48854888
msgid "empty value"
48864889
msgstr ""
48874890

4891+
msgid "ex VAT"
4892+
msgstr ""
4893+
48884894
msgid "files"
48894895
msgstr ""
48904896

@@ -4909,6 +4915,9 @@ msgstr ""
49094915
msgid "in category (between first and second row of products)"
49104916
msgstr ""
49114917

4918+
msgid "inc VAT"
4919+
msgstr ""
4920+
49124921
msgid "include"
49134922
msgstr ""
49144923

src/Resources/views/Mail/Order/paymentInfo.html.twig

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,36 @@
1111
<strong>{{ orderPaymentItem.name }}</strong>
1212
</td>
1313
<td align="right">
14-
<strong style="white-space: nowrap; padding-left: 10px;">{{ orderPaymentTotalPrice.priceWithVat|priceTextWithCurrencyByCurrencyIdAndLocale(order.currency.id, orderLocale)|hidePrice(order.customerUser) }}</strong>
14+
{% if displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_WITHOUT_VAT')) or displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) %}
15+
{% if not (displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) and orderPaymentTotalPrice.priceWithVat.isZero is same as(true)) %}
16+
{% if displayPrice is not same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) %}
17+
<strong style="white-space: nowrap; padding-left: 10px;">
18+
{% endif %}
19+
20+
{{ orderPaymentTotalPrice.priceWithoutVat|priceTextWithCurrencyByCurrencyIdAndLocale(order.currency.id, orderLocale)|hidePrice(order.customerUser) }}
21+
{% if displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) %}
22+
{{ 'ex VAT'|trans }}&nbsp;
23+
{% endif %}
24+
25+
{% if displayPrice is not same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) %}
26+
</strong>
27+
{% endif %}
28+
{% endif %}
29+
{% endif %}
30+
31+
{% if displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) %}
32+
<br>
33+
{% endif %}
34+
35+
{% if displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_WITH_VAT')) or displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) %}
36+
<strong style="white-space: nowrap; padding-left: 10px;">
37+
{{ orderPaymentTotalPrice.priceWithVat|priceTextWithCurrencyByCurrencyIdAndLocale(order.currency.id, orderLocale)|hidePrice(order.customerUser) }}
38+
{% if displayPrice is same as(constant('Shopsys\\FrameworkBundle\\Model\\Order\\Mail\\OrderMail::DISPLAY_PRICE_BOTH')) and orderPaymentTotalPrice.priceWithVat.isZero is same as(false) %}
39+
{{ 'inc VAT'|trans }}&nbsp;
40+
{% endif %}
41+
</strong>
42+
{% endif %}
1543
</td>
1644
</tr>
1745
</tbody>
18-
</table>
46+
</table>

0 commit comments

Comments
 (0)