Skip to content

Commit 1f81c2a

Browse files
committed
ACP2E-1200: fixed email order notification sending without being checked
1 parent 735a01b commit 1f81c2a

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
593593
$order->setIncrementId($quote->getReservedOrderId());
594594
}
595595

596+
if (array_key_exists('send_confirmation', $orderData) && false === $orderData['send_confirmation']) {
597+
$order->setCanSendNewEmailFlag(false);
598+
}
599+
596600
$this->submitQuoteValidator->validateOrder($order);
597601

598602
$this->eventManager->dispatch(

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ public function testAssignCustomer(): void
732732
*/
733733
public function testSubmit(): void
734734
{
735-
$orderData = [];
735+
$orderData = ['send_confirmation' => false];
736736
$isGuest = true;
737737
$isVirtual = false;
738738
$customerId = 1;
@@ -827,7 +827,8 @@ public function testSubmit(): void
827827
]
828828
);
829829
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote);
830-
$this->assertEquals($order, $this->model->submit($quote, $orderData));
830+
$test = $this->model->submit($quote, $orderData);
831+
$this->assertEquals($order, $test);
831832
}
832833

833834
/**

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,9 +1982,10 @@ public function createOrder()
19821982
$this->_prepareCustomer();
19831983
$this->_validate();
19841984
$quote = $this->getQuote();
1985+
19851986
$this->_prepareQuoteItems();
19861987

1987-
$orderData = [];
1988+
$orderData = ['send_confirmation' => (bool)$this->getSendConfirmation()];
19881989
if ($this->getSession()->getOrder()->getId()) {
19891990
$oldOrder = $this->getSession()->getOrder();
19901991
$originalId = $oldOrder->getOriginalIncrementId();
@@ -1996,7 +1997,8 @@ public function createOrder()
19961997
'relation_parent_id' => $oldOrder->getId(),
19971998
'relation_parent_real_id' => $oldOrder->getIncrementId(),
19981999
'edit_increment' => $oldOrder->getEditIncrement() + 1,
1999-
'increment_id' => $originalId . '-' . ($oldOrder->getEditIncrement() + 1)
2000+
'increment_id' => $originalId . '-' . ($oldOrder->getEditIncrement() + 1),
2001+
'send_confirmation' => (bool)$this->getSendConfirmation()
20002002
];
20012003
$quote->setReservedOrderId($orderData['increment_id']);
20022004
}
@@ -2010,6 +2012,7 @@ public function createOrder()
20102012
$this->orderManagement->cancel($oldOrder->getEntityId());
20112013
$order->save();
20122014
}
2015+
20132016
if ($this->getSendConfirmation() && !$order->getEmailSent()) {
20142017
$this->emailSender->send($order);
20152018
}

dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ public function testCreateOrderNewCustomerDifferentAddresses()
419419
self::assertEquals($this->model->getQuote()->getCustomerLastname(), $newBillAddress->getLastname());
420420
self::assertEquals($order->getCustomerFirstname(), $newBillAddress->getFirstname());
421421
self::assertEquals($order->getCustomerLastname(), $newBillAddress->getLastname());
422+
self::assertTrue($order->getEmailSent());
422423
$this->verifyCreatedOrder($order, $shippingMethod);
423424
/** @var Customer $customer */
424425
$customer = $this->objectManager->create(Customer::class);
@@ -462,6 +463,7 @@ public function testCreateOrderNewCustomer()
462463
$paymentMethod
463464
);
464465
$order = $this->model->createOrder();
466+
self::assertNull($order->getEmailSent());
465467
//Check, order considering decimal qty in product.
466468
foreach ($order->getItems() as $orderItem) {
467469
self::assertTrue($orderItem->getIsQtyDecimal());
@@ -533,6 +535,7 @@ public function testCreateOrderNewCustomerWithFailedFirstPlaceOrderAction(
533535
);
534536

535537
$order = $this->model->createOrder();
538+
self::assertNull($order->getEmailSent());
536539
$this->verifyCreatedOrder($order, $shippingMethod);
537540
}
538541

@@ -593,6 +596,7 @@ public function testCreateOrderExistingCustomerDifferentAddresses()
593596

594597
$this->model->getQuote()->setCustomer($customerMock);
595598
$order = $this->model->createOrder();
599+
self::assertNull($order->getEmailSent());
596600
$this->verifyCreatedOrder($order, $shippingMethod);
597601
$this->objectManager->get(CustomerRegistry::class)
598602
->remove($order->getCustomerId());
@@ -644,6 +648,7 @@ public function testCreateOrderExistingCustomer()
644648

645649
$this->model->getQuote()->setCustomer($customerMock);
646650
$order = $this->model->createOrder();
651+
self::assertNull($order->getEmailSent());
647652
if ($this->model->getSendConfirmation() && !$order->getEmailSent()) {
648653
$this->emailSenderMock->expects($this->once())
649654
->method('send')
@@ -966,6 +971,7 @@ public function testCreateOrderExistingCustomerWhenDefaultAddressDiffersWithNew(
966971
$this->model->setBillingAddress($orderData['billing_address']);
967972
try {
968973
$order =$this->model->createOrder();
974+
self::assertNull($order->getEmailSent());
969975
$orderData = $order->getData();
970976
self::assertNotEmpty($orderData['increment_id'], 'Order increment ID is empty.');
971977
} catch (\Magento\Framework\Exception\LocalizedException $e) {

0 commit comments

Comments
 (0)