Skip to content

Commit

Permalink
updated email templates (#3711)
Browse files Browse the repository at this point in the history
  • Loading branch information
chlebektomas authored Jan 20, 2025
2 parents bdc1b56 + ddfb85a commit 71ba1be
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 132 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/ecs-skip-rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
__DIR__ . '/src/Form/Admin/NotificationBarFormType.php',
__DIR__ . '/src/Migrations/Version20200319113341.php',
__DIR__ . '/src/Migrations/Version20221205123619.php',
__DIR__ . '/src/Model/Mail/MailTemplateBuilder.php',
__DIR__ . '/src/Model/Mail/MailTemplateConfiguration.php',
__DIR__ . '/tests/App/Functional/EntityExtension/EntityExtensionTest.php',
__DIR__ . '/tests/App/Functional/Model/Product/ProductOnCurrentDomainElasticFacadeCountDataTest.php',
__DIR__ . '/tests/App/Smoke/Http/RouteConfigCustomization.php',
Expand Down
1 change: 1 addition & 0 deletions app/src/DataFixtures/Demo/CompanyOrderDataFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public function getDependencies(): array
PaymentDataFixture::class,
OrderStatusDataFixture::class,
CompanyDataFixture::class,
OrderDataFixture::class,
];
}

Expand Down
224 changes: 162 additions & 62 deletions app/src/DataFixtures/Demo/MailTemplateDataFixture.php

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions app/src/DataFixtures/Demo/OrderDataFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Model\Administrator\Administrator;
use App\Model\Order\Order;
use App\Model\Order\PromoCode\PromoCode;
use App\Model\Order\Status\OrderStatus;
use App\Model\Payment\Payment;
use App\Model\Product\Product;
Expand All @@ -24,6 +25,8 @@
use Shopsys\FrameworkBundle\Model\Order\PlaceOrderFacade;
use Shopsys\FrameworkBundle\Model\Order\Processing\OrderInputFactory;
use Shopsys\FrameworkBundle\Model\Order\Processing\OrderProcessor;
use Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency;
use Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyDataFactory;
use Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFacade;

class OrderDataFixture extends AbstractReferenceFixture implements DependentFixtureInterface
Expand All @@ -42,6 +45,7 @@ class OrderDataFixture extends AbstractReferenceFixture implements DependentFixt
* @param \Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFacade $currencyFacade
* @param \Shopsys\FrameworkBundle\Model\Order\Processing\OrderProcessor $orderProcessor
* @param \Shopsys\FrameworkBundle\Model\Order\Processing\OrderInputFactory $orderInputFactory
* @param \Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyDataFactory $currencyDataFactory
*/
public function __construct(
private readonly CustomerUserRepository $customerUserRepository,
Expand All @@ -51,6 +55,7 @@ public function __construct(
private readonly CurrencyFacade $currencyFacade,
private readonly OrderProcessor $orderProcessor,
private readonly OrderInputFactory $orderInputFactory,
private readonly CurrencyDataFactory $currencyDataFactory,
) {
}

Expand Down Expand Up @@ -775,6 +780,8 @@ private function loadDistinct(int $domainId): void
PaymentDataFixture::PAYMENT_LATER,
$customerUser,
);

$this->createOrderWithPromoCodeAndRounding($domainDefaultCurrency, $domainId);
}

/**
Expand All @@ -783,6 +790,7 @@ private function loadDistinct(int $domainId): void
* @param string $transportReferenceName
* @param string $paymentReferenceName
* @param \App\Model\Customer\User\CustomerUser|null $customerUser
* @param \App\Model\Order\PromoCode\PromoCode|null $promoCode
* @return \App\Model\Order\Order
*/
private function createOrder(
Expand All @@ -791,6 +799,7 @@ private function createOrder(
string $transportReferenceName,
string $paymentReferenceName,
?CustomerUser $customerUser = null,
?PromoCode $promoCode = null,
): Order {
$uniqueOrderHash = $orderData->domainId . '-';

Expand All @@ -802,6 +811,10 @@ private function createOrder(
$orderInput->setPayment($payment);
$orderInput->setCustomerUser($customerUser);

if ($promoCode !== null) {
$orderInput->addPromoCode($promoCode);
}

foreach ($products as $productReferenceName => $quantity) {
$product = $this->getReference($productReferenceName, Product::class);
$orderInput->addProduct($product, $quantity);
Expand Down Expand Up @@ -837,6 +850,48 @@ public function getDependencies(): array
OrderStatusDataFixture::class,
CountryDataFixture::class,
SettingValueDataFixture::class,
PromoCodeDataFixture::class,
];
}

/**
* @param \Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency $domainDefaultCurrency
* @param int $domainId
*/
private function createOrderWithPromoCodeAndRounding(Currency $domainDefaultCurrency, int $domainId): void
{
$currencyData = $this->currencyDataFactory->createFromCurrency($domainDefaultCurrency);
$originalRounding = $currencyData->roundingType;
$currencyData->roundingType = Currency::ROUNDING_TYPE_HUNDREDTHS;
$this->currencyFacade->edit($domainDefaultCurrency->getId(), $currencyData);

$orderData = $this->orderDataFactory->create();
$orderData->status = $this->getReference(OrderStatusDataFixture::ORDER_STATUS_NEW, OrderStatus::class);
$orderData->firstName = 'Peťka';
$orderData->lastName = 'Šuster';
$orderData->email = '[email protected]';
$orderData->telephone = '+420123456789';
$orderData->street = 'Petřkovická 123';
$orderData->city = 'Ostrava Lhotka';
$orderData->postcode = '71200';
$orderData->country = $this->getReference(CountryDataFixture::COUNTRY_CZECH_REPUBLIC, Country::class);
$orderData->deliveryAddressSameAsBillingAddress = true;
$orderData->domainId = $domainId;
$orderData->currency = $domainDefaultCurrency;
$orderData->createdAt = new DateTime('now');
$this->createOrder(
$orderData,
[
ProductDataFixture::PRODUCT_PREFIX . '1' => 1,
ProductDataFixture::PRODUCT_PREFIX . '2' => 1,
],
TransportDataFixture::TRANSPORT_CZECH_POST,
PaymentDataFixture::PAYMENT_CASH,
null,
$this->getReferenceForDomain(PromoCodeDataFixture::VALID_PROMO_CODE, $domainId, PromoCode::class),
);

$currencyData->roundingType = $originalRounding;
$this->currencyFacade->edit($domainDefaultCurrency->getId(), $currencyData);
}
}
1 change: 1 addition & 0 deletions app/src/DataFixtures/Demo/PromoCodeDataFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private function loadForOtherDomains(): void
$promoCodeData->domainId = $domainId;
$promoCode = $this->promoCodeFacade->create($promoCodeData);
$this->setDefaultLimit($promoCode);
$this->addReferenceForDomain(self::VALID_PROMO_CODE, $promoCode, $domainId);

$promoCodeData = $this->promoCodeDataFactory->create();
$promoCodeData->code = 'test100';
Expand Down
9 changes: 8 additions & 1 deletion app/src/Model/Order/Mail/OrderMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @method string getFormattedPrice(\App\Model\Order\Order $order)
* @method string getFormattedDateTime(\App\Model\Order\Order $order)
* @method string getDeliveryAddressHtmlTable(\App\Model\Order\Order $order)
* @method string getProductsHtmlTable(\App\Model\Order\Order $order)
* @method string getProductsHtmlTable(\App\Model\Order\Order $order, \Shopsys\FrameworkBundle\Model\Pricing\Price[] $orderItemTotalPricesById)
* @method string getDomainLocaleByOrder(\App\Model\Order\Order $order)
* @property \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @property \Shopsys\FrameworkBundle\Component\Router\DomainRouterFactory $domainRouterFactory
Expand All @@ -23,6 +23,13 @@
* @method array getVariablesReplacementsForBody(\App\Model\Order\Order $order)
* @method string|null getTrackingInstructions(\App\Model\Order\Order $order)
* @method string getBillingAddressHtmlTable(\App\Model\Order\Order $order)
* @method string|null getNoteHtml(\App\Model\Order\Order $order)
* @method string|null getTransportInstructionsHtml(\App\Model\Order\Order $order)
* @method string|null getPaymentInstructionsHtml(\App\Model\Order\Order $order)
* @method string getTransportInfoHtml(\App\Model\Order\Order $order, \Shopsys\FrameworkBundle\Model\Pricing\Price[] $orderItemTotalPricesById)
* @method string getPaymentInfoHtml(\App\Model\Order\Order $order, \Shopsys\FrameworkBundle\Model\Pricing\Price[] $orderItemTotalPricesById)
* @method string|null getRoundingInfoHtml(\App\Model\Order\Order $order, \Shopsys\FrameworkBundle\Model\Pricing\Price[] $orderItemTotalPricesById)
* @method string getAddressesHtml(\App\Model\Order\Order $order)
*/
class OrderMail extends BaseOrderMail
{
Expand Down
14 changes: 8 additions & 6 deletions app/tests/App/Functional/Model/Order/Mail/OrderMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@

class OrderMailTest extends TransactionFunctionalTestCase
{
public function testGetMailTemplateNameByStatus()
/**
* @inject
*/
private OrderItemPriceCalculation $orderItemPriceCalculation;

public function testGetMailTemplateNameByStatus(): void
{
$orderStatus1 = $this->getMockBuilder(OrderStatus::class)
->onlyMethods(['getId'])
Expand All @@ -50,7 +55,7 @@ public function testGetMailTemplateNameByStatus()
$this->assertNotSame($mailTempleteName1, $mailTempleteName2);
}

public function testGetMessageByOrder()
public function testGetMessageByOrder(): void
{
$routerMock = $this->getMockBuilder(RouterInterface::class)->getMock();
$routerMock->expects($this->any())->method('generate')->willReturn('generatedUrl');
Expand All @@ -62,9 +67,6 @@ public function testGetMessageByOrder()
$domainRouterFactoryMock->expects($this->any())->method('getRouter')->willReturn($routerMock);

$twigMock = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$orderItemPriceCalculationMock = $this->getMockBuilder(
OrderItemPriceCalculation::class,
)->disableOriginalConstructor()->getMock();
$settingMock = $this->getMockBuilder(Setting::class)->disableOriginalConstructor()->getMock();
$settingMock->expects($this->any())->method('getForDomain')->willReturn('[email protected]');
$priceExtensionMock = $this->getMockBuilder(PriceExtension::class)->disableOriginalConstructor()->getMock();
Expand All @@ -82,7 +84,7 @@ public function testGetMessageByOrder()
$settingMock,
$domainRouterFactoryMock,
$twigMock,
$orderItemPriceCalculationMock,
$this->orderItemPriceCalculation,
$this->domain,
$priceExtensionMock,
$dateTimeFormatterExtensionMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ public function testCompanyOrdersList(): void
$responseData = $this->getResponseDataForGraphQlType($response, 'orders');

$expectedOrders = [
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 30, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_LIMITED_USER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 28, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_SELF_MANAGE_USER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 31, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_LIMITED_USER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 29, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_SELF_MANAGE_USER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 27, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_SELF_MANAGE_USER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 25, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_OWNER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 30, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_SELF_MANAGE_USER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 28, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_SELF_MANAGE_USER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 26, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_OWNER_EMAIL],
['uuid' => $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 27, Order::class)->getUuid(), 'email' => CompanyDataFixture::B2B_COMPANY_OWNER_EMAIL],
];

$this->assertSame(6, $responseData['totalCount']);
Expand Down
Loading

0 comments on commit 71ba1be

Please sign in to comment.