Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
order_with_downloadable_product.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9  \Magento\Sales\Model\Order\Address::class,
10  [
11  'data' => [
12  'firstname' => 'guest',
13  'lastname' => 'guest',
14  'email' => '[email protected]',
15  'street' => 'street',
16  'city' => 'Los Angeles',
17  'region' => 'CA',
18  'postcode' => '1',
19  'country_id' => 'US',
20  'telephone' => '1',
21  ]
22  ]
23 );
24 $billingAddress->setAddressType('billing');
25 
27  \Magento\Sales\Model\Order\Payment::class
28 );
29 $payment->setMethod('checkmo');
30 
33  \Magento\Sales\Model\Order\Item::class
34 );
35 
38  ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
40 $link = $product->getExtensionAttributes()->getDownloadableProductLinks()[0];
41 
42 $orderItem->setProductId(
43  1
44 )->setProductType(
45  \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
46 )->setProductOptions(
47  ['links' => [$link->getId()]]
48 )->setBasePrice(
49  100
50 )->setQtyOrdered(
51  1
52 );
53 
55 $order->setCustomerEmail(
57 )->addItem(
59 )->setIncrementId(
60  '100000001'
61 )->setCustomerIsGuest(
62  true
63 )->setStoreId(
64  1
65 )->setEmailSent(
66  1
67 )->setBillingAddress(
69 )->setPayment(
70  $payment
71 );
72 $order->save();