Skip to content

Commit

Permalink
Merge pull request #697 from magento-mpi/MAGETWO-54389
Browse files Browse the repository at this point in the history
[MPI] Fix PayPal Express Checkout place order method
  • Loading branch information
Yaroslav Onischenko authored Dec 27, 2016
2 parents 5a0cc81 + 696ccdc commit 889ae4a
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 166 deletions.
26 changes: 25 additions & 1 deletion app/code/Magento/Paypal/Model/Express/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

use Magento\Customer\Api\Data\CustomerInterface as CustomerDataObject;
use Magento\Customer\Model\AccountManagement;
use Magento\Framework\App\ObjectManager;
use Magento\Paypal\Model\Config as PaypalConfig;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Quote\Model\Quote\Address;
use Magento\Framework\DataObject;
Expand Down Expand Up @@ -268,6 +270,11 @@ class Checkout
*/
protected $totalsCollector;

/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Customer\Model\Url $customerUrl
Expand Down Expand Up @@ -789,7 +796,8 @@ public function place($token, $shippingMethodCode = null)

$this->ignoreAddressValidation();
$this->_quote->collectTotals();
$order = $this->quoteManagement->submit($this->_quote);
$orderId = $this->quoteManagement->placeOrder($this->_quote->getId());
$order = $this->getOrderRepository()->get($orderId);

if (!$order) {
return;
Expand Down Expand Up @@ -1157,4 +1165,20 @@ protected function prepareGuestQuote()
->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
return $this;
}

/**
* Returns order repository instance
*
* @return OrderRepositoryInterface
* @deprecated
*/
private function getOrderRepository()
{
if ($this->orderRepository === null) {
$this->orderRepository = ObjectManager::getInstance()
->get(OrderRepositoryInterface::class);
}

return $this->orderRepository;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp()
/**
* Verify that an order placed with an existing customer can re-use the customer addresses.
*
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
* @magentoDataFixture Magento/Paypal/_files/quote_express_with_customer.php
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
Expand Down Expand Up @@ -74,7 +74,7 @@ public function testPrepareCustomerQuote()
/**
* Verify that after placing the order, addresses are associated with the order and the quote is a guest quote.
*
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php
* @magentoDataFixture Magento/Paypal/_files/quote_express.php
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
)->setValue(
'carriers/flatrate/active',
1,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
)->setValue(
'payment/paypal_express/active',
1,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $product \Magento\Catalog\Model\Product */
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId('simple')
->setId(1)
->setAttributeSetId(4)
->setName('Simple Product')
->setSku('simple')
->setPrice(10)
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(
[
'qty' => 100,
'is_in_stock' => 1,
]
)->save();
$product->load(1);

$billingData = [
'firstname' => 'testname',
'lastname' => 'lastname',
'company' => '',
'email' => 'test@com.com',
'street' => [
0 => 'test1',
1 => '',
],
'city' => 'Test',
'region_id' => '1',
'region' => '',
'postcode' => '9001',
'country_id' => 'US',
'telephone' => '11111111',
'fax' => '',
'confirm_password' => '',
'save_in_address_book' => '1',
'use_for_shipping' => '1',
];

$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Quote\Model\Quote\Address::class, ['data' => $billingData]);
$billingAddress->setAddressType('billing');

$shippingAddress = clone $billingAddress;
$shippingAddress->setId(null)->setAddressType('shipping');
$shippingAddress->setShippingMethod('flatrate_flatrate');
$shippingAddress->setCollectShippingRates(true);

/** @var $quote \Magento\Quote\Model\Quote */
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
$quote->setCustomerIsGuest(
true
)->setStoreId(
$objectManager->get(
\Magento\Store\Model\StoreManagerInterface::class
)->getStore()->getId()
)->setReservedOrderId(
'100000002'
)->setBillingAddress(
$billingAddress
)->setShippingAddress(
$shippingAddress
)->addProduct(
$product,
10
);
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);

$quoteRepository = $objectManager->get(\Magento\Quote\Api\CartRepositoryInterface::class);
$quoteRepository->save($quote);
$quote = $quoteRepository->get($quote->getId());
$quote->setCustomerEmail('admin@example.com');
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
require __DIR__ . '/../../Customer/_files/customer.php';
require __DIR__ . '/../../Customer/_files/customer_two_addresses.php';

\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

$objectManager->get(
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
)->setValue('carriers/flatrate/active', 1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
->setValue('payment/paypal_express/active', 1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
$customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
$customer = $customerRepository->getById(1);

/** @var $product \Magento\Catalog\Model\Product */
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId('simple')
->setId(1)
->setAttributeSetId(4)
->setName('Simple Product')
->setSku('simple')
->setPrice(10)
->setStockData([
'use_config_manage_stock' => 1,
'qty' => 100,
'is_qty_decimal' => 0,
'is_in_stock' => 100,
])
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->save();
$product->load(1);

$customerBillingAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
$customerBillingAddress->load(1);
$billingAddressDataObject = $customerBillingAddress->getDataModel();
$billingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class);
$billingAddress->importCustomerAddressData($billingAddressDataObject);
$billingAddress->setAddressType('billing');

/** @var \Magento\Customer\Model\Address $customerShippingAddress */
$customerShippingAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
$customerShippingAddress->load(2);
$shippingAddressDataObject = $customerShippingAddress->getDataModel();
$shippingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class);
$shippingAddress->importCustomerAddressData($shippingAddressDataObject);
$shippingAddress->setAddressType('shipping');

$shippingAddress->setShippingMethod('flatrate_flatrate');
$shippingAddress->setCollectShippingRates(true);

/** @var $quote \Magento\Quote\Model\Quote */
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
$quote->setCustomerIsGuest(false)
->setCustomerId($customer->getId())
->setCustomer($customer)
->setStoreId($objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId())
->setReservedOrderId('test02')
->setBillingAddress($billingAddress)
->setShippingAddress($shippingAddress)
->addProduct($product, 10);
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);

/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
$quoteRepository = $objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
$quoteRepository->save($quote);
$quote = $quoteRepository->get($quote->getId());
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,7 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
)->setValue(
'carriers/flatrate/active',
1,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
)->setValue(
'payment/paypal_express/active',
1,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $product \Magento\Catalog\Model\Product */
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId('simple')
->setId(1)
->setAttributeSetId(4)
->setName('Simple Product')
->setSku('simple')
->setPrice(10)
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(
[
'qty' => 100,
'is_in_stock' => 1,
]
)->save();
$product->load(1);

$billingData = [
'firstname' => 'testname',
'lastname' => 'lastname',
'company' => '',
'email' => 'test@com.com',
'street' => [
0 => 'test1',
1 => '',
],
'city' => 'Test',
'region_id' => '1',
'region' => '',
'postcode' => '9001',
'country_id' => 'US',
'telephone' => '11111111',
'fax' => '',
'confirm_password' => '',
'save_in_address_book' => '1',
'use_for_shipping' => '1',
];

$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Quote\Model\Quote\Address::class, ['data' => $billingData]);
$billingAddress->setAddressType('billing');

$shippingAddress = clone $billingAddress;
$shippingAddress->setId(null)->setAddressType('shipping');
$shippingAddress->setShippingMethod('flatrate_flatrate');
$shippingAddress->setCollectShippingRates(true);

/** @var $quote \Magento\Quote\Model\Quote */
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
$quote->setCustomerIsGuest(
true
)->setStoreId(
$objectManager->get(
\Magento\Store\Model\StoreManagerInterface::class
)->getStore()->getId()
)->setReservedOrderId(
'100000002'
)->setBillingAddress(
$billingAddress
)->setShippingAddress(
$shippingAddress
)->addProduct(
$product,
10
);
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);

$quoteRepository = $objectManager->get(\Magento\Quote\Api\CartRepositoryInterface::class);
$quoteRepository->save($quote);
$quote = $quoteRepository->get($quote->getId());
$quote->setCustomerEmail('admin@example.com');
require __DIR__ . '/quote_express.php';

/** @var $service \Magento\Quote\Api\CartManagementInterface */
$service = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
Expand Down
Loading

0 comments on commit 889ae4a

Please sign in to comment.