quote_express.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');
  7. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  8. \Magento\Framework\App\Config\MutableScopeConfigInterface::class
  9. )->setValue(
  10. 'carriers/flatrate/active',
  11. 1,
  12. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  13. );
  14. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  15. \Magento\Framework\App\Config\MutableScopeConfigInterface::class
  16. )->setValue(
  17. 'payment/paypal_express/active',
  18. 1,
  19. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  20. );
  21. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  22. /** @var $product \Magento\Catalog\Model\Product */
  23. $product = $objectManager->create(\Magento\Catalog\Model\Product::class);
  24. $product->setTypeId('simple')
  25. ->setId(1)
  26. ->setAttributeSetId(4)
  27. ->setName('Simple Product')
  28. ->setSku('simple')
  29. ->setPrice(10)
  30. ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
  31. ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
  32. ->setStockData(
  33. [
  34. 'qty' => 100,
  35. 'is_in_stock' => 1,
  36. 'manage_stock' => 1,
  37. ]
  38. )->save();
  39. $product->load(1);
  40. $billingData = [
  41. 'firstname' => 'testname',
  42. 'lastname' => 'lastname',
  43. 'company' => '',
  44. 'email' => 'test@com.com',
  45. 'street' => [
  46. 0 => 'test1',
  47. 1 => '',
  48. ],
  49. 'city' => 'Test',
  50. 'region_id' => '1',
  51. 'region' => '',
  52. 'postcode' => '9001',
  53. 'country_id' => 'US',
  54. 'telephone' => '11111111',
  55. 'fax' => '',
  56. 'confirm_password' => '',
  57. 'save_in_address_book' => '1',
  58. 'use_for_shipping' => '1',
  59. ];
  60. $billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  61. ->create(\Magento\Quote\Model\Quote\Address::class, ['data' => $billingData]);
  62. $billingAddress->setAddressType('billing');
  63. $shippingAddress = clone $billingAddress;
  64. $shippingAddress->setId(null)->setAddressType('shipping');
  65. $shippingAddress->setShippingMethod('flatrate_flatrate');
  66. $shippingAddress->setCollectShippingRates(true);
  67. /** @var $quote \Magento\Quote\Model\Quote */
  68. $quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
  69. $quote->setCustomerIsGuest(
  70. true
  71. )->setStoreId(
  72. $objectManager->get(
  73. \Magento\Store\Model\StoreManagerInterface::class
  74. )->getStore()->getId()
  75. )->setReservedOrderId(
  76. '100000002'
  77. )->setBillingAddress(
  78. $billingAddress
  79. )->setShippingAddress(
  80. $shippingAddress
  81. )->addProduct(
  82. $product,
  83. 10
  84. );
  85. $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
  86. $quote->getShippingAddress()->setCollectShippingRates(true);
  87. $quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);
  88. $quoteRepository = $objectManager->get(\Magento\Quote\Api\CartRepositoryInterface::class);
  89. $quoteRepository->save($quote);
  90. $quote = $quoteRepository->get($quote->getId());
  91. $quote->setCustomerEmail('admin@example.com');