From 8ae9033d9fb26e695d06078dc0edb67b6169bc14 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Mon, 3 Oct 2016 09:56:02 +0300 Subject: [PATCH 1/7] MAGETWO-56938: CLONE - [Github] API salesOrderRepositoryV1 can't create shipping address #5544 --- .../Magento/Sales/Model/OrderRepository.php | 10 ++++ .../Test/Unit/Model/OrderRepositoryTest.php | 32 ++++++++++ .../Sales/Service/V1/OrderCreateTest.php | 59 ++++++++++++++++++- 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/OrderRepository.php b/app/code/Magento/Sales/Model/OrderRepository.php index 5c14b3fd4433e..1a85860e11b0b 100644 --- a/app/code/Magento/Sales/Model/OrderRepository.php +++ b/app/code/Magento/Sales/Model/OrderRepository.php @@ -146,6 +146,16 @@ public function deleteById($id) */ public function save(\Magento\Sales\Api\Data\OrderInterface $entity) { + /** @var \Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes */ + $extensionAttributes = $entity->getExtensionAttributes(); + if ($entity->getIsNotVirtual() && $extensionAttributes && $extensionAttributes->getShippingAssignments()) { + $shippingAssignments = $extensionAttributes->getShippingAssignments(); + if (count($shippingAssignments) === 1) { + $shipping = $shippingAssignments[0]->getShipping(); + $entity->setShippingAddress($shipping->getAddress()); + $entity->setShippingMethod($shipping->getMethod()); + } + } $this->metadata->getMapper()->save($entity); $this->registry[$entity->getEntityId()] = $entity; return $this->registry[$entity->getEntityId()]; diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php index 5535ac85095c5..647b9cfc3e622 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php @@ -110,4 +110,36 @@ public function testGetList() $this->assertEquals($collectionMock, $this->model->getList($searchCriteriaMock)); } + + public function testSave() + { + $mapperMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order::class) + ->disableOriginalConstructor() + ->getMock(); + $orderEntity = $this->getMock(\Magento\Sales\Model\Order::class, [], [], '', false); + $extensionAttributes = $this->getMock( + \Magento\Sales\Api\Data\OrderExtension::class, ['getShippingAssignments'], [], '', false + ); + $shippingAssignment = $this->getMockBuilder(\Magento\Sales\Model\Order\ShippingAssignment::class) + ->disableOriginalConstructor() + ->setMethods(['getShipping']) + ->getMock(); + $shippingMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Shipping::class) + ->disableOriginalConstructor() + ->setMethods(['getAddress', 'getMethod']) + ->getMock(); + $orderEntity->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes); + $orderEntity->expects($this->once())->method('getIsNotVirtual')->willReturn(true); + $extensionAttributes + ->expects($this->any()) + ->method('getShippingAssignments') + ->willReturn([$shippingAssignment]); + $shippingAssignment->expects($this->once())->method('getShipping')->willReturn($shippingMock); + $shippingMock->expects($this->once())->method('getAddress'); + $shippingMock->expects($this->once())->method('getMethod'); + $this->metadata->expects($this->once())->method('getMapper')->willReturn($mapperMock); + $mapperMock->expects($this->once())->method('save'); + $orderEntity->expects($this->any())->method('getEntityId')->willReturn(1); + $this->model->save($orderEntity); + } } diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php index 1bee8cdfa1780..96037eafef656 100755 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php @@ -41,6 +41,8 @@ protected function prepareOrder() $orderPaymentFactory = $this->objectManager->get(\Magento\Sales\Model\Order\PaymentFactory::class); /** @var \Magento\Sales\Model\Order\AddressRepository $orderAddressRepository */ $orderAddressRepository = $this->objectManager->get(\Magento\Sales\Model\Order\AddressRepository::class); + /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class); $order = $orderFactory->create( ['data' => $this->getDataStructure(\Magento\Sales\Api\Data\OrderInterface::class)] @@ -68,9 +70,36 @@ protected function prepareOrder() $order->setCustomerEmail($email); $order->setBaseGrandTotal(100); $order->setGrandTotal(100); + $order->setShippingDescription('Flat Rate - Fixed'); + $order->setIsVirtual(0); + $order->setStoreId($storeManager->getDefaultStoreView()->getId()); + $order->setBaseDiscountAmount(0); + $order->setBaseShippingAmount(5); + $order->setBaseShippingTaxAmount(0); + $order->setBaseSubtotal(100); + $order->setBaseTaxAmount(0); + $order->setBaseToGlobalRate(1); + $order->setBaseToOrderRate(1); + $order->setDiscountAmount(0); + $order->setShippingAmount(0); + $order->setShippingTaxAmount(0); + $order->setStoreToOrderRate(0); + $order->setBaseToOrderRate(0); + $order->setSubtotal(100); + $order->setTaxAmount(0); + $order->setTotalQtyOrdered(1); + $order->setCustomerIsGuest(1); + $order->setCustomerNoteNotify(0); + $order->setCustomerGroupId(0); + $order->setBaseSubtotalInclTax(100); + $order->setWeight(1); + $order->setBaseCurrencyCode('USD'); + $order->setShippingInclTax(5); + $order->setBaseShippingInclTax(5); $this->addProductOption($orderItem); + $order->setItems([$orderItem->getData()]); $order->setData('payment', $orderPayment->getData()); @@ -82,12 +111,37 @@ protected function prepareOrder() $orderAddressBilling->setFirstname('First Name'); $orderAddressBilling->setTelephone('+00(000)-123-45-57'); $orderAddressBilling->setStreet(['Street']); - $orderAddressBilling->setCountryId(1); + $orderAddressBilling->setCountryId('US'); + $orderAddressBilling->setRegion('California'); $orderAddressBilling->setAddressType('billing'); + $orderAddressBilling->setRegionId(12); + + $orderAddressShipping = $orderAddressRepository->create(); + $orderAddressShipping->setCity('City2'); + $orderAddressShipping->setPostcode('12345'); + $orderAddressShipping->setLastname('Last Name2'); + $orderAddressShipping->setFirstname('First Name2'); + $orderAddressShipping->setTelephone('+00(000)-123-45-57'); + $orderAddressShipping->setStreet(['Street']); + $orderAddressShipping->setCountryId('US'); + $orderAddressShipping->setRegion('California'); + $orderAddressShipping->setAddressType('shipping'); + $orderAddressShipping->setRegionId(12); $orderData = $order->getData(); $orderData['billing_address'] = $orderAddressBilling->getData(); $orderData['billing_address']['street'] = ['Street']; + $address = $orderAddressShipping->getData(); + $address['street'] = ['Street']; + $orderData['extension_attributes']['shipping_assignments'] = + [ + [ + 'shipping' => [ + 'address' => $address, + 'method' => 'Flat Rate - Fixed' + ] + ] + ]; return $orderData; } @@ -172,5 +226,8 @@ public function testOrderCreate() $this->assertTrue((bool)$model->getId()); $this->assertEquals($order['base_grand_total'], $model->getBaseGrandTotal()); $this->assertEquals($order['grand_total'], $model->getGrandTotal()); + $this->assertNotNull($model->getShippingAddress()); + $this->assertTrue((bool)$model->getShippingAddress()->getId()); + $this->assertEquals('Flat Rate - Fixed', $model->getShippingMethod()); } } From e8ef9ce93c938ed44c59264cf1c89eef2797a691 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Mon, 3 Oct 2016 12:14:58 +0300 Subject: [PATCH 2/7] MAGETWO-55342: [GITHUB] Free shiping coupon usage is not tracked #3506 --- .../Observer/SalesOrderAfterPlaceObserver.php | 2 +- .../Observer/SalesOrderAfterPlaceObserverTest.php | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/SalesRule/Observer/SalesOrderAfterPlaceObserver.php b/app/code/Magento/SalesRule/Observer/SalesOrderAfterPlaceObserver.php index e352ede867a69..a75947629db5d 100644 --- a/app/code/Magento/SalesRule/Observer/SalesOrderAfterPlaceObserver.php +++ b/app/code/Magento/SalesRule/Observer/SalesOrderAfterPlaceObserver.php @@ -57,7 +57,7 @@ public function execute(EventObserver $observer) { $order = $observer->getEvent()->getOrder(); - if (!$order || $order->getDiscountAmount() == 0) { + if (!$order || !$order->getAppliedRuleIds()) { return $this; } diff --git a/app/code/Magento/SalesRule/Test/Unit/Observer/SalesOrderAfterPlaceObserverTest.php b/app/code/Magento/SalesRule/Test/Unit/Observer/SalesOrderAfterPlaceObserverTest.php index 0546dce56a3f6..c3d7e41acdf28 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Observer/SalesOrderAfterPlaceObserverTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Observer/SalesOrderAfterPlaceObserverTest.php @@ -121,10 +121,10 @@ public function testSalesOrderAfterPlaceWithoutRuleId() { $observer = $this->getMock(\Magento\Framework\Event\Observer::class, [], [], '', false); $order = $this->initOrderFromEvent($observer); - $discountAmount = 10; + $ruleIds = null; $order->expects($this->once()) - ->method('getDiscountAmount') - ->will($this->returnValue($discountAmount)); + ->method('getAppliedRuleIds') + ->will($this->returnValue($ruleIds)); $this->ruleFactory->expects($this->never()) ->method('create'); @@ -158,14 +158,10 @@ public function testSalesOrderAfterPlace($ruleCustomerId) $ruleId = 1; $couponId = 1; $customerId = 1; - $discountAmount = 10; - $order->expects($this->once()) + $order->expects($this->exactly(2)) ->method('getAppliedRuleIds') ->will($this->returnValue($ruleId)); - $order->expects($this->once()) - ->method('getDiscountAmount') - ->will($this->returnValue($discountAmount)); $order->expects($this->once()) ->method('getCustomerId') ->will($this->returnValue($customerId)); From aef25e7a276bab73c5afb52e0c8410deb51b7d57 Mon Sep 17 00:00:00 2001 From: aakimov Date: Mon, 3 Oct 2016 11:26:08 +0300 Subject: [PATCH 3/7] MAGETWO-59137: Impossible to Create a Catalog Price Rule --- .../view/adminhtml/ui_component/catalog_rule_form.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml b/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml index af60e0247169b..acfd1efa605c7 100644 --- a/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml +++ b/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml @@ -149,7 +149,7 @@ catalog_rule customer_group_ids - \Magento\Customer\Model\Customer\Source\GroupSourceInterface + \Magento\CatalogRule\Model\Rule\CustomerGroupsOptionsProvider From 7a67ac94dd9a925256f2c94b4ebc597f5e949206 Mon Sep 17 00:00:00 2001 From: Oleksandr Miroshnichenko Date: Mon, 3 Oct 2016 17:29:25 +0300 Subject: [PATCH 4/7] MAGETWO-59090: [Github] Admin can't reset password for more than one customer #5260 --- .../Adminhtml/Index/ResetPassword.php | 3 + .../Adminhtml/Index/ResetPasswordTest.php | 52 ++++++++++- .../Model/Plugin/AccountManagement.php | 12 ++- .../Magento/Security/etc/adminhtml/di.xml | 5 ++ .../Adminhtml/Index/ResetPasswordTest.php | 88 +++++++++++++++++++ 5 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php index 45d31dc0e2764..3c3fa73087e4a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php @@ -6,6 +6,7 @@ namespace Magento\Customer\Controller\Adminhtml\Index; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Exception\SecurityViolationException; class ResetPassword extends \Magento\Customer\Controller\Adminhtml\Index { @@ -40,6 +41,8 @@ public function execute() $messages = $exception->getMessage(); } $this->_addSessionErrorMessages($messages); + } catch (SecurityViolationException $exception) { + $this->messageManager->addErrorMessage($exception->getMessage()); } catch (\Exception $exception) { $this->messageManager->addException( $exception, diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php index b7295fb9ceb4f..44444935973d4 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php @@ -143,7 +143,7 @@ protected function setUp() $this->messageManager = $this->getMockBuilder( \Magento\Framework\Message\Manager::class )->disableOriginalConstructor()->setMethods( - ['addSuccess', 'addMessage', 'addException'] + ['addSuccess', 'addMessage', 'addException', 'addErrorMessage'] )->getMock(); $this->resultRedirectFactoryMock = $this->getMockBuilder( @@ -332,6 +332,56 @@ public function testResetPasswordActionCoreException() $this->_testedObject->execute(); } + public function testResetPasswordActionSecurityException() + { + $securityText = 'Security violation.'; + $exception = new \Magento\Framework\Exception\SecurityViolationException(__($securityText)); + $customerId = 1; + $email = 'some@example.com'; + $websiteId = 1; + + $this->_request->expects( + $this->once() + )->method( + 'getParam' + )->with( + $this->equalTo('customer_id'), + $this->equalTo(0) + )->will( + $this->returnValue($customerId) + ); + $customer = $this->getMockForAbstractClass( + \Magento\Customer\Api\Data\CustomerInterface::class, + ['getId', 'getEmail', 'getWebsiteId'] + ); + $customer->expects($this->once())->method('getEmail')->will($this->returnValue($email)); + $customer->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId)); + $this->_customerRepositoryMock->expects( + $this->once() + )->method( + 'getById' + )->with( + $customerId + )->will( + $this->returnValue($customer) + ); + $this->_customerAccountManagementMock->expects( + $this->once() + )->method( + 'initiatePasswordReset' + )->willThrowException($exception); + + $this->messageManager->expects( + $this->once() + )->method( + 'addErrorMessage' + )->with( + $this->equalTo($exception->getMessage()) + ); + + $this->_testedObject->execute(); + } + public function testResetPasswordActionCoreExceptionWarn() { $warningText = 'Warning'; diff --git a/app/code/Magento/Security/Model/Plugin/AccountManagement.php b/app/code/Magento/Security/Model/Plugin/AccountManagement.php index ba1d4af5618b7..c65442ec40020 100644 --- a/app/code/Magento/Security/Model/Plugin/AccountManagement.php +++ b/app/code/Magento/Security/Model/Plugin/AccountManagement.php @@ -25,18 +25,26 @@ class AccountManagement */ protected $securityManager; + /** + * @var int + */ + protected $passwordRequestEvent; + /** * AccountManagement constructor. * * @param \Magento\Framework\App\RequestInterface $request * @param SecurityManager $securityManager + * @param int $passwordRequestEvent */ public function __construct( \Magento\Framework\App\RequestInterface $request, - \Magento\Security\Model\SecurityManager $securityManager + \Magento\Security\Model\SecurityManager $securityManager, + $passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST ) { $this->request = $request; $this->securityManager = $securityManager; + $this->passwordRequestEvent = $passwordRequestEvent; } /** @@ -56,7 +64,7 @@ public function beforeInitiatePasswordReset( $websiteId = null ) { $this->securityManager->performSecurityCheck( - PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, + $this->passwordRequestEvent, $email ); return [$email, $template, $websiteId]; diff --git a/app/code/Magento/Security/etc/adminhtml/di.xml b/app/code/Magento/Security/etc/adminhtml/di.xml index 4cbd3c3adc567..c134638d1266e 100644 --- a/app/code/Magento/Security/etc/adminhtml/di.xml +++ b/app/code/Magento/Security/etc/adminhtml/di.xml @@ -15,6 +15,11 @@ + + + Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST + + diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php new file mode 100644 index 0000000000000..f3571c17ddffe --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php @@ -0,0 +1,88 @@ +passwordResetRequestEventCreate( + \Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST + ); + $this->getRequest()->setPostValue(['customer_id' => '1']); + $this->dispatch('backend/customer/index/resetPassword'); + $this->assertSessionMessages( + $this->equalTo(['The customer will receive an email with a link to reset password.']), + \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS + ); + $this->assertRedirect($this->stringStartsWith($this->baseControllerUrl . 'edit')); + } + + /** + * Checks reset password functionality with default settings, customer and admin reset request events. + * + * @magentoConfigFixture current_store admin/security/limit_password_reset_requests_method 1 + * @magentoConfigFixture current_store admin/security/min_time_between_password_reset_requests 10 + * @magentoConfigFixture current_store contact/email/recipient_email hello@example.com + * @magentoDataFixture Magento/Customer/_files/customer.php + */ + public function testResetPasswordWithSecurityViolationException() + { + $this->passwordResetRequestEventCreate( + \Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST + ); + $this->passwordResetRequestEventCreate( + \Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST + ); + $this->getRequest()->setPostValue(['customer_id' => '1']); + $this->dispatch('backend/customer/index/resetPassword'); + $this->assertSessionMessages( + $this->equalTo( + ['Too many password reset requests. Please wait and try again or contact hello@example.com.'] + ), + \Magento\Framework\Message\MessageInterface::TYPE_ERROR + ); + $this->assertRedirect($this->stringStartsWith($this->baseControllerUrl . 'edit')); + } + + /** + * Create and save reset request event with provided request type. + * + * @param int $requestType + */ + private function passwordResetRequestEventCreate($requestType) + { + $passwordResetRequestEventFactory = $this->_objectManager->get( + \Magento\Security\Model\PasswordResetRequestEventFactory::class + ); + $passwordResetRequestEvent = $passwordResetRequestEventFactory->create(); + $passwordResetRequestEvent + ->setRequestType($requestType) + ->setAccountReference('customer@example.com') + ->setCreatedAt(strtotime('now')) + ->setIp('3232249856') + ->save(); + } +} From 60ed703749a8a53c9abf2eb948efd129940f3b01 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 4 Oct 2016 10:43:05 +0300 Subject: [PATCH 5/7] MAGETWO-58182: [Github] Minicart item count is not updated if switch from https to http #6487 --- app/code/Magento/Theme/view/frontend/web/js/view/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Theme/view/frontend/web/js/view/messages.js b/app/code/Magento/Theme/view/frontend/web/js/view/messages.js index 48507343fe28d..b707659fb3f4c 100644 --- a/app/code/Magento/Theme/view/frontend/web/js/view/messages.js +++ b/app/code/Magento/Theme/view/frontend/web/js/view/messages.js @@ -32,7 +32,7 @@ define([ customerData.set('messages', {}); } - $.cookieStorage.setConf({path: '/', expires: -1}).set('mage-messages', null); + $.cookieStorage.set('mage-messages', ''); } }); }); From 0b88caeb00b918a4df0a43580aaf1d37e711152d Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Wed, 5 Oct 2016 10:55:16 +0300 Subject: [PATCH 6/7] MAGETWO-56938: CLONE - [Github] API salesOrderRepositoryV1 can't create shipping address #5544 --- .../Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php | 6 +++++- .../Magento/Sales/Service/V1/OrderCreateTest.php | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php index 647b9cfc3e622..f6bc3459c0cc3 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php @@ -118,7 +118,11 @@ public function testSave() ->getMock(); $orderEntity = $this->getMock(\Magento\Sales\Model\Order::class, [], [], '', false); $extensionAttributes = $this->getMock( - \Magento\Sales\Api\Data\OrderExtension::class, ['getShippingAssignments'], [], '', false + \Magento\Sales\Api\Data\OrderExtension::class, + ['getShippingAssignments'], + [], + '', + false ); $shippingAssignment = $this->getMockBuilder(\Magento\Sales\Model\Order\ShippingAssignment::class) ->disableOriginalConstructor() diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php index 96037eafef656..1279057089918 100755 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php @@ -31,6 +31,9 @@ protected function setUp() $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); } + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ protected function prepareOrder() { /** @var \Magento\Sales\Model\Order $orderBuilder */ @@ -99,7 +102,6 @@ protected function prepareOrder() $this->addProductOption($orderItem); - $order->setItems([$orderItem->getData()]); $order->setData('payment', $orderPayment->getData()); @@ -139,7 +141,9 @@ protected function prepareOrder() 'shipping' => [ 'address' => $address, 'method' => 'Flat Rate - Fixed' - ] + ], + 'items' => [$orderItem->getData()], + 'stock_id' => null, ] ]; return $orderData; From f2dec8028c5fb458dcd9eea96f3f7c6c8aa297ba Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Wed, 5 Oct 2016 13:18:30 +0300 Subject: [PATCH 7/7] MAGETWO-56938: CLONE - [Github] API salesOrderRepositoryV1 can't create shipping address #5544 --- app/code/Magento/Sales/Model/OrderRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Model/OrderRepository.php b/app/code/Magento/Sales/Model/OrderRepository.php index 1a85860e11b0b..f0477fd76014a 100644 --- a/app/code/Magento/Sales/Model/OrderRepository.php +++ b/app/code/Magento/Sales/Model/OrderRepository.php @@ -150,8 +150,8 @@ public function save(\Magento\Sales\Api\Data\OrderInterface $entity) $extensionAttributes = $entity->getExtensionAttributes(); if ($entity->getIsNotVirtual() && $extensionAttributes && $extensionAttributes->getShippingAssignments()) { $shippingAssignments = $extensionAttributes->getShippingAssignments(); - if (count($shippingAssignments) === 1) { - $shipping = $shippingAssignments[0]->getShipping(); + if (!empty($shippingAssignments)) { + $shipping = array_shift($shippingAssignments)->getShipping(); $entity->setShippingAddress($shipping->getAddress()); $entity->setShippingMethod($shipping->getMethod()); }