Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Copyright (c) 2019 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare(strict_types=1);
use Magento\Catalog\Model\Product\Type;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Address;
use Magento\Sales\Model\Order\Item;
use Magento\Sales\Model\Order\Payment;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
$addressData = [
'firstname' => 'guest',
'lastname' => 'guest',
'email' => 'customer@example.com',
'street' => 'street',
'city' => 'Los Angeles',
'region' => 'CA',
'postcode' => '1',
'country_id' => 'US',
'telephone' => '1'
];
$paymentMethods = [
0 => 'checkmo',
1 => 'test_cc',
2 => 'test_cc',
3 => 'invoice',
4 => 'paypal_expr',
5 => 'paypal_expr',
];
$orderStatus = [
0 => 'pending',
1 => 'pending',
2 => 'processing',
3 => 'pending',
4 => 'processing',
5 => 'processing',
];
for ($counter = 0; $counter <= 5; $counter++) {
/** @var $billingAddress Address */
$billingAddress = Bootstrap::getObjectManager()->create(Address::class, ['data' => $addressData]);
$billingAddress->setAddressType('billing');
$shippingAddress = clone $billingAddress;
$shippingAddress->setId(null)->setAddressType('shipping');
/** @var $payment Payment */
$payment = Bootstrap::getObjectManager()->create(Payment::class);
$payment->setMethod($paymentMethods[$counter]);
/** @var $orderItem Item */
$orderItem = Bootstrap::getObjectManager()->create(Item::class);
$orderItem->setProductId($counter)
->setProductType(Type::TYPE_SIMPLE)
->setName('product name')
->setSku('MET0000' . $counter)
->setBasePrice(100 + $counter)
->setQtyOrdered(1)
->setQtyShipped(1)
->setIsQtyDecimal(true);
/** @var StoreManagerInterface $storeManager */
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
/** @var $order Order */
$order = Bootstrap::getObjectManager()->create(Order::class);
$order->addItem($orderItem)
->setIncrementId('METEXAMPLE-10' . $counter)
->setSubtotal(100 + $counter)
->setBaseSubtotal(100 + $counter)
->setCustomerIsGuest(true)
->setCustomerEmail('admin@example.com')
->setStatus($orderStatus[$counter])
->setBillingAddress($billingAddress)
->setShippingAddress($shippingAddress)
->setStoreId($storeManager->getStore()->getId())
->setPayment($payment);
/** @var OrderRepositoryInterface $orderRepository */
$orderRepository = Bootstrap::getObjectManager()->get(OrderRepositoryInterface::class);
$orderRepository->save($order);
}