Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_express_with_customer.php
Go to the documentation of this file.
1 <?php
6 require __DIR__ . '/../../Customer/_files/customer.php';
7 require __DIR__ . '/../../Customer/_files/customer_two_addresses.php';
8 
10 
12 
13 $objectManager->get(
14  \Magento\Framework\App\Config\MutableScopeConfigInterface::class
15 )->setValue('carriers/flatrate/active', 1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
16 $objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
17  ->setValue('payment/paypal_express/active', 1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
18 
20 $customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
22 
24 $product = $objectManager->create(\Magento\Catalog\Model\Product::class);
25 $product->setTypeId('simple')
26  ->setId(1)
27  ->setAttributeSetId(4)
28  ->setName('Simple Product')
29  ->setSku('simple')
30  ->setPrice(10)
31  ->setStockData([
32  'use_config_manage_stock' => 1,
33  'qty' => 100,
34  'is_qty_decimal' => 0,
35  'is_in_stock' => 100,
36  ])
37  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
38  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
39  ->save();
40 $product->load(1);
41 
42 $customerBillingAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
45 $billingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class);
46 $billingAddress->importCustomerAddressData($billingAddressDataObject);
47 $billingAddress->setAddressType('billing');
48 
50 $customerShippingAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
53 $shippingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class);
54 $shippingAddress->importCustomerAddressData($shippingAddressDataObject);
55 $shippingAddress->setAddressType('shipping');
56 
57 $shippingAddress->setShippingMethod('flatrate_flatrate');
58 $shippingAddress->setCollectShippingRates(true);
59 
61 $quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
62 $quote->setCustomerIsGuest(false)
63  ->setCustomerId($customer->getId())
64  ->setCustomer($customer)
65  ->setStoreId($objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId())
66  ->setReservedOrderId('test02')
67  ->setBillingAddress($billingAddress)
68  ->setShippingAddress($shippingAddress)
69  ->addProduct($product, 10);
70 $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
71 $quote->getShippingAddress()->setCollectShippingRates(true);
72 $quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);
73 
75 $quoteRepository = $objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
77 $quote = $quoteRepository->get($quote->getId());
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60