Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
order_with_guest_and_virtual_product.php
Go to the documentation of this file.
1 <?php
13 
14 require __DIR__ . '/../../../Magento/Catalog/_files/product_virtual.php';
15 require __DIR__ . '/store.php';
16 $addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
17 
18 $objectManager = Bootstrap::getObjectManager();
19 
20 $billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
21 $billingAddress->setAddressType('billing');
22 
24 $payment = $objectManager->create(Payment::class);
25 $payment->setMethod('braintree')
26  ->setLastTransId('00001')
27  ->setAdditionalInformation('avsPostalCodeResponseCode', 'M')
28  ->setAdditionalInformation('avsStreetAddressResponseCode', 'M')
29  ->setAdditionalInformation('cvvResponseCode', 'M');
30 
32 $orderItem1 = $objectManager->create(Item::class);
33 $orderItem1->setProductId($product->getId())
34  ->setSku($product->getSku())
35  ->setName($product->getName())
36  ->setQtyOrdered(1)
37  ->setBasePrice($product->getPrice())
38  ->setPrice($product->getPrice())
39  ->setRowTotal($product->getPrice())
40  ->setProductType($product->getTypeId());
41 
44 
46 $order = $objectManager->create(Order::class);
47 $order->setIncrementId('100000002')
48  ->setState(Order::STATE_PROCESSING)
49  ->setStatus(Order::STATE_PROCESSING)
50  ->setCustomerIsGuest(true)
51  ->setRemoteIp('127.0.0.1')
52  ->setCreatedAt('2016-12-12T12:00:55+0000')
53  ->setOrderCurrencyCode('USD')
54  ->setBaseCurrencyCode('USD')
55  ->setSubtotal($orderAmount)
56  ->setGrandTotal($orderAmount)
57  ->setBaseSubtotal($orderAmount)
58  ->setBaseGrandTotal($orderAmount)
59  ->setCustomerEmail($customerEmail)
60  ->setBillingAddress($billingAddress)
61  ->setStoreId($store->getId())
62  ->addItem($orderItem1)
63  ->setPayment($payment)
64  ->setQuoteId(1);
65 
67 $orderRepository = $objectManager->get(OrderRepositoryInterface::class);
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60