Skip to content

Commit cbbee19

Browse files
committed
merchandaise return ui tests
1 parent d8a0542 commit cbbee19

6 files changed

Lines changed: 79 additions & 7 deletions

File tree

install-dev/data/xml/feature_flag.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<feature_flag id="front_container_v2" name="front_container_v2" type="env,dotenv,db" label_wording="New front container" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the new front container." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
2424
<feature_flag id="customer_group" name="customer_group" type="env,dotenv,db" label_wording="Customer group" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the customer group page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
2525
<feature_flag id="store" name="store" type="env,dotenv,db" label_wording="Store" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the store page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
26-
<feature_flag id="merchandise_return" name="merchandise_return" type="env,dotenv,db" label_wording="Merchandise return" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the merchandise return page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
26+
<feature_flag id="merchandise_return" name="merchandise_return" type="env,dotenv,db" label_wording="Merchandise return" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the merchandise return page." description_domain="Admin.Advparameters.Help" state="1" stability="stable" />
2727
<feature_flag id="improved_shipment" name="improved_shipment" type="env,dotenv,db" label_wording="Improved shipment" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the newly improved shipment system." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
2828
<feature_flag id="discount" name="discount" type="env,dotenv,db" label_wording="Discount" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the new discount system." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
2929
<feature_flag id="tag" name="tag" type="env,dotenv,db" label_wording="Tag" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the tag page." description_domain="Admin.Advparameters.Help" state="1" stability="stable" />

src/Adapter/OrderReturn/CommandHandler/UpdateOrderReturnStateHandler.php

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88

99
namespace PrestaShop\PrestaShop\Adapter\OrderReturn\CommandHandler;
1010

11+
use Configuration;
12+
use Customer;
13+
use Language;
14+
use Mail;
15+
use Order;
1116
use OrderReturn;
17+
use OrderReturnState;
1218
use PrestaShop\PrestaShop\Adapter\OrderReturn\Repository\OrderReturnRepository;
1319
use PrestaShop\PrestaShop\Adapter\OrderReturnState\Repository\OrderReturnStateRepository;
1420
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler;
1521
use PrestaShop\PrestaShop\Core\Domain\OrderReturn\Command\UpdateOrderReturnStateCommand;
1622
use PrestaShop\PrestaShop\Core\Domain\OrderReturn\CommandHandler\UpdateOrderReturnStateHandlerInterface;
1723
use PrestaShop\PrestaShop\Core\Domain\OrderReturn\Exception\OrderReturnException;
24+
use Symfony\Contracts\Translation\TranslatorInterface;
25+
use Validate;
1826

1927
#[AsCommandHandler]
2028
class UpdateOrderReturnStateHandler implements UpdateOrderReturnStateHandlerInterface
@@ -29,18 +37,26 @@ class UpdateOrderReturnStateHandler implements UpdateOrderReturnStateHandlerInte
2937
*/
3038
private $orderReturnStateRepository;
3139

40+
/**
41+
* @var TranslatorInterface
42+
*/
43+
private $translator;
44+
3245
/**
3346
* UpdateOrderReturnStateHandler constructor.
3447
*
3548
* @param OrderReturnRepository $orderReturnRepository
3649
* @param OrderReturnStateRepository $orderReturnStateRepository
50+
* @param TranslatorInterface $translator
3751
*/
3852
public function __construct(
3953
OrderReturnRepository $orderReturnRepository,
40-
OrderReturnStateRepository $orderReturnStateRepository
54+
OrderReturnStateRepository $orderReturnStateRepository,
55+
TranslatorInterface $translator
4156
) {
4257
$this->orderReturnRepository = $orderReturnRepository;
4358
$this->orderReturnStateRepository = $orderReturnStateRepository;
59+
$this->translator = $translator;
4460
}
4561

4662
/**
@@ -49,9 +65,65 @@ public function __construct(
4965
public function handle(UpdateOrderReturnStateCommand $command): void
5066
{
5167
$orderReturn = $this->orderReturnRepository->get($command->getOrderReturnId());
68+
$previousState = (int) $orderReturn->state;
5269
$orderReturn = $this->updateOrderReturnWithCommandData($orderReturn, $command);
5370

5471
$this->orderReturnRepository->update($orderReturn);
72+
73+
// Notify the customer when the return status actually changes, mirroring the legacy
74+
// AdminReturnController behaviour (the migration had dropped this email).
75+
if ((int) $orderReturn->state !== $previousState) {
76+
$this->sendStateChangeEmail($orderReturn);
77+
}
78+
}
79+
80+
/**
81+
* Sends the "order return status has changed" email to the customer, in the order's language
82+
* and shop context.
83+
*
84+
* @param OrderReturn $orderReturn
85+
*/
86+
private function sendStateChangeEmail(OrderReturn $orderReturn): void
87+
{
88+
$order = new Order((int) $orderReturn->id_order);
89+
$customer = new Customer((int) $orderReturn->id_customer);
90+
91+
if (!Validate::isLoadedObject($order) || !Validate::isLoadedObject($customer)) {
92+
return;
93+
}
94+
95+
$orderReturnState = new OrderReturnState((int) $orderReturn->state);
96+
$orderLanguage = new Language((int) $order->id_lang);
97+
98+
$stateName = $orderReturnState->name[(int) $order->id_lang]
99+
?? $orderReturnState->name[(int) Configuration::get('PS_LANG_DEFAULT')]
100+
?? '';
101+
102+
Mail::Send(
103+
(int) $order->id_lang,
104+
'order_return_state',
105+
$this->translator->trans(
106+
'Your order return status has changed',
107+
[],
108+
'Emails.Subject',
109+
$orderLanguage->locale
110+
),
111+
[
112+
'{lastname}' => $customer->lastname,
113+
'{firstname}' => $customer->firstname,
114+
'{id_order_return}' => (int) $orderReturn->id,
115+
'{state_order_return}' => $stateName,
116+
],
117+
$customer->email,
118+
$customer->firstname . ' ' . $customer->lastname,
119+
null,
120+
null,
121+
null,
122+
null,
123+
_PS_MAIL_DIR_,
124+
true,
125+
(int) $order->id_shop
126+
);
55127
}
56128

57129
/**

src/PrestaShopBundle/Resources/config/services/adapter/order_return.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
arguments:
2323
- '@prestashop.adapter.order_return.repository.order_return_repository'
2424
- '@prestashop.adapter.order_return_state.repository.order_return_state_repository'
25+
- '@translator'
2526

2627
prestashop.adapter.order_return.command_handler.delete_product_from_order_return_handler:
2728
class: 'PrestaShop\PrestaShop\Adapter\OrderReturn\CommandHandler\DeleteProductFromOrderReturnHandler'

tests/UI/campaigns/functional/BO/05_customerService/03_merchandiseReturns/03_updateStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ describe('BO - Customer Service - Merchandise Returns : Update status', async ()
373373
it('should check the updated status in the merchandise returns table', async function () {
374374
await testContext.addContextItem(this, 'testIdentifier', `checkStatus${index}`, baseContext);
375375

376-
const status = await boMerchandiseReturnsPage.getTextColumnFromMerchandiseReturnsTable(page, 'name');
376+
const status = await boMerchandiseReturnsPage.getTextColumnFromMerchandiseReturnsTable(page, 'status');
377377
expect(status).to.eq(test.args.status);
378378
});
379379
});

tests/UI/package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/UI/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"homepage": "https://github.com/PrestaShop/PrestaShop/tree/develop/tests/UI#readme",
113113
"dependencies": {
114114
"@faker-js/faker": "^10.4.0",
115-
"@prestashop-core/ui-testing": "https://github.com/PrestaShop/ui-testing-library#main",
115+
"@prestashop-core/ui-testing": "https://github.com/tleon/ui-testing-library#merchandise-return-feature-flag",
116116
"chai": "^6.2.2",
117117
"chai-string": "^2.0.0",
118118
"dotenv": "^17.4.1",

0 commit comments

Comments
 (0)