Skip to content

Commit 7431f26

Browse files
authored
Merge pull request #7221 from magento-performance/MCP-792
[PerfPack] [BUG] Wrong error message is sent in email if order is rejected because of disabled product
2 parents 724953d + 960cd11 commit 7431f26

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ public function savePaymentInformation(
176176
}
177177
$this->limitShippingCarrier($quote);
178178

179+
if (!(int)$quote->getItemsQty()) {
180+
throw new CouldNotSaveException(__('Some of the products are disabled.'));
181+
}
182+
179183
$this->paymentMethodManagement->set($cartId, $paymentMethod);
180184
return true;
181185
}

app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public function testSavePaymentInformationWithoutBillingAddress()
180180
$paymentMock = $this->getMockForAbstractClass(PaymentInterface::class);
181181
$billingAddressMock = $this->getMockForAbstractClass(AddressInterface::class);
182182
$quoteMock = $this->createMock(Quote::class);
183+
$quoteMock->expects($this->any())->method('getItemsQty')->willReturn(1);
183184

184185
$billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
185186

@@ -210,6 +211,7 @@ public function testSavePaymentInformationAndPlaceOrderWithLocalizedException()
210211

211212
$quoteMock = $this->createMock(Quote::class);
212213
$quoteMock->method('getBillingAddress')->willReturn($billingAddressMock);
214+
$quoteMock->expects($this->any())->method('getItemsQty')->willReturn(1);
213215
$this->cartRepositoryMock->method('getActive')->with($cartId)->willReturn($quoteMock);
214216

215217
$quoteIdMask = $this->getMockBuilder(QuoteIdMask::class)
@@ -231,6 +233,35 @@ public function testSavePaymentInformationAndPlaceOrderWithLocalizedException()
231233
$this->model->savePaymentInformationAndPlaceOrder($cartId, $email, $paymentMock, $billingAddressMock);
232234
}
233235

236+
public function testSavePaymentInformationAndPlaceOrderWithDisabledProduct()
237+
{
238+
$this->expectException('Magento\Framework\Exception\CouldNotSaveException');
239+
$this->expectExceptionMessage('Some of the products are disabled.');
240+
$cartId = 100;
241+
$email = '[email protected]';
242+
$paymentMock = $this->getMockForAbstractClass(PaymentInterface::class);
243+
$billingAddressMock = $this->getMockForAbstractClass(AddressInterface::class);
244+
245+
$quoteMock = $this->createMock(Quote::class);
246+
$quoteMock->method('getBillingAddress')->willReturn($billingAddressMock);
247+
$quoteMock->expects($this->any())->method('getItemsQty')->willReturn(0);
248+
$this->cartRepositoryMock->method('getActive')->with($cartId)->willReturn($quoteMock);
249+
250+
$quoteIdMask = $this->getMockBuilder(QuoteIdMask::class)
251+
->addMethods(['getQuoteId'])
252+
->onlyMethods(['load'])
253+
->disableOriginalConstructor()
254+
->getMock();
255+
$this->quoteIdMaskFactoryMock->method('create')->willReturn($quoteIdMask);
256+
$quoteIdMask->method('load')->with($cartId, 'masked_id')->willReturnSelf();
257+
$quoteIdMask->method('getQuoteId')->willReturn($cartId);
258+
259+
$billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
260+
261+
$this->paymentMethodManagementMock->expects($this->never())->method('set')->with($cartId, $paymentMock);
262+
$this->model->savePaymentInformationAndPlaceOrder($cartId, $email, $paymentMock, $billingAddressMock);
263+
}
264+
234265
/**
235266
* @param int $cartId
236267
* @param MockObject $billingAddressMock
@@ -266,6 +297,9 @@ private function getMockForAssignBillingAddress(
266297
$this->cartRepositoryMock->method('getActive')
267298
->with($cartId)
268299
->willReturn($quote);
300+
$quote->expects($this->any())
301+
->method('getItemsQty')
302+
->willReturn(1);
269303
$quote->expects($this->any())
270304
->method('getBillingAddress')
271305
->willReturn($quoteBillingAddress);

setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function findMissingFactories($file, $classReflection, $methodName, $ent
6262
$parameters = $constructor->getParameters();
6363
/** @var $parameter \ReflectionParameter */
6464
foreach ($parameters as $parameter) {
65-
preg_match('/\[\s\<\w+?>\s([\w\\\\]+)/s', $parameter->__toString(), $matches);
65+
preg_match('/\[\s\<\w+?>\s\??([\w\\\\]+)/s', $parameter->__toString(), $matches);
6666
if (isset($matches[1]) && substr($matches[1], -strlen($entityType)) == $entityType) {
6767
$missingClassName = $matches[1];
6868
if ($this->shouldGenerateClass($missingClassName, $entityType, $file)) {

0 commit comments

Comments
 (0)