1515use Shopsys \FrameworkBundle \Model \Order \Order ;
1616use Shopsys \FrameworkBundle \Model \Order \OrderUrlGenerator ;
1717use Shopsys \FrameworkBundle \Model \Order \Status \OrderStatus ;
18+ use Shopsys \FrameworkBundle \Model \Pricing \PricingSetting ;
1819use Shopsys \FrameworkBundle \Twig \DateTimeFormatterExtension ;
1920use Shopsys \FrameworkBundle \Twig \HiddenPriceExtension ;
2021use 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}
0 commit comments