Skip to content

Commit ce3d259

Browse files
committed
Merge branch 'MAGETWO-71050' into MPI-PR
2 parents 7ba7d5f + 9521e8c commit ce3d259

File tree

2 files changed

+52
-2
lines changed
  • app/code/Magento/Sales/Model/AdminOrder
  • dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder

2 files changed

+52
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,7 @@ public function importPostData($data)
16791679
*/
16801680
protected function _customerIsInStore($store)
16811681
{
1682-
$customerId = (int)$this->getSession()->getCustomerId();
1683-
$customer = $this->customerRepository->getById($customerId);
1682+
$customer = $this->getQuote()->getCustomer();
16841683

16851684
return $customer->getWebsiteId() == $store->getWebsiteId()
16861685
|| $this->accountManagement->isCustomerInStore($customer->getWebsiteId(), $store->getId());
@@ -1739,6 +1738,7 @@ public function _prepareCustomer()
17391738
/** @var $store \Magento\Store\Model\Store */
17401739
$store = $this->getSession()->getStore();
17411740
$customer = $this->getQuote()->getCustomer();
1741+
17421742
if ($customer->getId() && !$this->_customerIsInStore($store)) {
17431743
/** Create a new customer record if it is not available in the specified store */
17441744
/** Unset customer ID to ensure that new customer will be created */

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Sales\Model\AdminOrder;
77

8+
use Magento\Sales\Api\OrderManagementInterface;
89
use Magento\TestFramework\Helper\Bootstrap;
910
use Magento\Sales\Model\Order;
1011
use Magento\Framework\Registry;
@@ -423,6 +424,55 @@ public function testCreateOrderNewCustomer()
423424
$this->_verifyCreatedOrder($order, $shippingMethod);
424425
}
425426

427+
/**
428+
* Tests order creation with new customer after failed first place order action.
429+
*
430+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
431+
* @magentoDbIsolation enabled
432+
* @magentoAppIsolation enabled
433+
*/
434+
public function testCreateOrderNewCustomerWithFailedFirstPlaceOrderAction()
435+
{
436+
$productIdFromFixture = 1;
437+
$shippingMethod = 'freeshipping_freeshipping';
438+
$paymentMethod = 'checkmo';
439+
$shippingAddressAsBilling = 1;
440+
$customerEmail = '[email protected]';
441+
$orderData = [
442+
'currency' => 'USD',
443+
'account' => ['group_id' => '1', 'email' => $customerEmail],
444+
'billing_address' => array_merge($this->_getValidAddressData(), ['save_in_address_book' => '1']),
445+
'shipping_method' => $shippingMethod,
446+
'comment' => ['customer_note' => ''],
447+
'send_confirmation' => false,
448+
];
449+
$paymentData = ['method' => $paymentMethod];
450+
451+
$this->_preparePreconditionsForCreateOrder(
452+
$productIdFromFixture,
453+
$customerEmail,
454+
$shippingMethod,
455+
$shippingAddressAsBilling,
456+
$paymentData,
457+
$orderData,
458+
$paymentMethod
459+
);
460+
461+
// Emulates failing place order action
462+
$orderManagement = $this->getMockForAbstractClass(OrderManagementInterface::class);
463+
$orderManagement->method('place')
464+
->willThrowException(new \Exception('Can\'t place order'));
465+
Bootstrap::getObjectManager()->addSharedInstance($orderManagement, OrderManagementInterface::class);
466+
try {
467+
$this->_model->createOrder();
468+
} catch (\Exception $e) {
469+
Bootstrap::getObjectManager()->removeSharedInstance(OrderManagementInterface::class);
470+
}
471+
472+
$order = $this->_model->createOrder();
473+
$this->_verifyCreatedOrder($order, $shippingMethod);
474+
}
475+
426476
/**
427477
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
428478
* @magentoDataFixture Magento/Customer/_files/customer.php

0 commit comments

Comments
 (0)