Skip to content

Commit c23cd8d

Browse files
Merge branch '2.4-develop' into graphql-api-enhancements
2 parents ad07435 + 27147ce commit c23cd8d

File tree

4 files changed

+219
-111
lines changed

4 files changed

+219
-111
lines changed

app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
@@ -167,7 +167,9 @@ public function execute()
167167

168168
$this->_saveShipment($shipment);
169169

170-
if (!empty($data['send_email']) && $this->salesData->canSendNewShipmentEmail()) {
170+
// Pass the specific store ID from the order to check if shipment emails are enabled for that store
171+
if (!empty($data['send_email'])
172+
&& $this->salesData->canSendNewShipmentEmail($shipment->getOrder()->getStoreId())) {
171173
$this->shipmentSender->send($shipment);
172174
}
173175

app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/SaveTest.php

Lines changed: 174 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -385,18 +385,138 @@ public function testExecute(
385385
}
386386
}
387387

388+
/**
389+
* Test that canSendNewShipmentEmail is called with correct store ID
390+
*
391+
* @dataProvider storeIdDataProvider
392+
*/
393+
public function testCanSendNewShipmentEmailWithStoreId(
394+
int $storeId,
395+
bool $sendEmailRequested,
396+
bool $emailEnabledForStore,
397+
bool $shouldSendEmail
398+
): void {
399+
$this->formKeyValidator->expects($this->once())
400+
->method('validate')
401+
->willReturn(true);
402+
403+
$this->request->expects($this->once())
404+
->method('isPost')
405+
->willReturn(true);
406+
407+
$shipmentId = 1000012;
408+
$orderId = 10003;
409+
$shipmentData = ['items' => [], 'send_email' => $sendEmailRequested ? 'on' : ''];
410+
411+
$this->request->expects($this->any())
412+
->method('getParam')
413+
->willReturnMap([
414+
['order_id', null, $orderId],
415+
['shipment_id', null, $shipmentId],
416+
['shipment', null, $shipmentData],
417+
['tracking', null, []]
418+
]);
419+
420+
$order = $this->createPartialMock(Order::class, ['setCustomerNoteNotify', 'getStoreId', '__wakeup']);
421+
$order->expects($this->any())
422+
->method('getStoreId')
423+
->willReturn($storeId);
424+
425+
$shipment = $this->createPartialMock(
426+
Shipment::class,
427+
['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup']
428+
);
429+
$shipment->expects($this->any())
430+
->method('getOrder')
431+
->willReturn($order);
432+
$shipment->expects($this->any())
433+
->method('getOrderId')
434+
->willReturn($orderId);
435+
436+
if ($sendEmailRequested) {
437+
$this->salesData->expects($this->once())
438+
->method('canSendNewShipmentEmail')
439+
->with($storeId)
440+
->willReturn($emailEnabledForStore);
441+
} else {
442+
$this->salesData->expects($this->never())
443+
->method('canSendNewShipmentEmail');
444+
}
445+
446+
if ($shouldSendEmail) {
447+
$this->shipmentSender->expects($this->once())
448+
->method('send')
449+
->with($shipment);
450+
} else {
451+
$this->shipmentSender->expects($this->never())
452+
->method('send');
453+
}
454+
455+
$this->shipmentLoader->expects($this->once())
456+
->method('load')
457+
->willReturn($shipment);
458+
459+
$this->setupCommonMocks($shipment, $order, $orderId);
460+
461+
$this->saveAction->execute();
462+
}
463+
464+
/**
465+
* Test that email is not sent when disabled for specific store but enabled globally
466+
*/
467+
public function testEmailNotSentWhenDisabledForSpecificStore(): void
468+
{
469+
$storeId = 2;
470+
$this->testCanSendNewShipmentEmailWithStoreId(
471+
$storeId,
472+
true,
473+
false,
474+
false
475+
);
476+
}
477+
478+
/**
479+
* Test that email is sent when enabled for specific store even if disabled globally
480+
*/
481+
public function testEmailSentWhenEnabledForSpecificStore(): void
482+
{
483+
$storeId = 2;
484+
$this->testCanSendNewShipmentEmailWithStoreId(
485+
$storeId,
486+
true,
487+
true,
488+
true
489+
);
490+
}
491+
492+
/**
493+
* @return array
494+
*/
495+
public static function storeIdDataProvider(): array
496+
{
497+
return [
498+
'default_store_email_requested_enabled' => [1, true, true, true],
499+
'default_store_email_requested_disabled' => [1, true, false, false],
500+
'custom_store_email_requested_enabled' => [2, true, true, true],
501+
'custom_store_email_requested_disabled' => [2, true, false, false],
502+
'custom_store_email_not_requested' => [2, false, true, false],
503+
'multistore_environment_store_3' => [3, true, true, true],
504+
'multistore_environment_store_5_disabled' => [5, true, false, false],
505+
];
506+
}
507+
388508
/**
389509
* @return array
390510
*/
391511
public static function executeDataProvider(): array
392512
{
393513
/**
394-
* bool $formKeyIsValid
395-
* bool $isPost
396-
* string $sendEmail
397-
* bool $emailEnabled
398-
* bool $shouldEmailBeSent
399-
*/
514+
* bool $formKeyIsValid
515+
* bool $isPost
516+
* string $sendEmail
517+
* bool $emailEnabled
518+
* bool $shouldEmailBeSent
519+
*/
400520
return [
401521
[false, false, '', false, false],
402522
[true, false, '', false, false],
@@ -409,6 +529,52 @@ public static function executeDataProvider(): array
409529
];
410530
}
411531

532+
/**
533+
* Setup common mocks needed for successful execution
534+
*/
535+
private function setupCommonMocks(MockObject $shipment, MockObject $order, int $orderId): void
536+
{
537+
$shipment->expects($this->once())
538+
->method('register')
539+
->willReturnSelf();
540+
541+
$order->expects($this->once())
542+
->method('setCustomerNoteNotify');
543+
544+
$this->labelGenerator->expects($this->any())
545+
->method('create')
546+
->willReturn(true);
547+
548+
$saveTransaction = $this->getMockBuilder(Transaction::class)
549+
->disableOriginalConstructor()
550+
->getMock();
551+
$saveTransaction->method('addObject')->willReturnSelf();
552+
553+
$this->objectManager->expects($this->once())
554+
->method('create')
555+
->with(Transaction::class)
556+
->willReturn($saveTransaction);
557+
558+
$this->objectManager->expects($this->once())
559+
->method('get')
560+
->with(Session::class)
561+
->willReturn($this->session);
562+
563+
$this->session->expects($this->once())
564+
->method('getCommentText')
565+
->with(true);
566+
567+
$this->shipmentValidatorMock->expects($this->once())
568+
->method('validate')
569+
->willReturn($this->validationResult);
570+
571+
$this->validationResult->expects($this->once())
572+
->method('hasMessages')
573+
->willReturn(false);
574+
575+
$this->prepareRedirect(['order_id' => $orderId]);
576+
}
577+
412578
/**
413579
* @param array $arguments
414580
*

app/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@
472472
<item name="primary" xsi:type="string">primary</item>
473473
<item name="first" xsi:type="string">global</item>
474474
</argument>
475+
<argument name="appMode" xsi:type="init_parameter">Magento\Framework\App\State::PARAM_MODE</argument>
475476
</arguments>
476477
</type>
477478
<type name="Magento\Framework\App\ResourceConnection">

0 commit comments

Comments
 (0)