Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_express.php
Go to the documentation of this file.
1 <?php
8  \Magento\Framework\App\Config\MutableScopeConfigInterface::class
9 )->setValue(
10  'carriers/flatrate/active',
11  1,
12  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
13 );
15  \Magento\Framework\App\Config\MutableScopeConfigInterface::class
16 )->setValue(
17  'payment/paypal_express/active',
18  1,
19  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
20 );
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 
42  'firstname' => 'testname',
43  'lastname' => 'lastname',
44  'company' => '',
45  'email' => '[email protected]',
46  'street' => [
47  0 => 'test1',
48  1 => '',
49  ],
50  'city' => 'Test',
51  'region_id' => '1',
52  'region' => '',
53  'postcode' => '9001',
54  'country_id' => 'US',
55  'telephone' => '11111111',
56  'fax' => '',
57  'confirm_password' => '',
58  'save_in_address_book' => '1',
59  'use_for_shipping' => '1',
60 ];
61 
63  ->create(\Magento\Quote\Model\Quote\Address::class, ['data' => $billingData]);
64 $billingAddress->setAddressType('billing');
65 
67 $shippingAddress->setId(null)->setAddressType('shipping');
68 $shippingAddress->setShippingMethod('flatrate_flatrate');
69 $shippingAddress->setCollectShippingRates(true);
70 
72 $quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
73 $quote->setCustomerIsGuest(
74  true
75 )->setStoreId(
76  $objectManager->get(
77  \Magento\Store\Model\StoreManagerInterface::class
78  )->getStore()->getId()
79 )->setReservedOrderId(
80  '100000002'
81 )->setBillingAddress(
83 )->setShippingAddress(
85 )->addProduct(
86  $product,
87  10
88 );
89 $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
90 $quote->getShippingAddress()->setCollectShippingRates(true);
91 $quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);
92 
93 $quoteRepository = $objectManager->get(\Magento\Quote\Api\CartRepositoryInterface::class);
95 $quote = $quoteRepository->get($quote->getId());
96 $quote->setCustomerEmail('[email protected]');
$quote
$product
$objectManager
$billingAddress
$shippingAddress
$quoteRepository
$billingData