Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
magento2-base
dev
tests
integration
testsuite
Magento
Checkout
_files
order_items.php
Go to the documentation of this file.
1
<?php
7
use
Magento\Sales\Model\Order
;
8
use
Magento\TestFramework\Helper\Bootstrap
;
9
10
require
'products.php'
;
11
require
'orders.php'
;
12
13
$objectManager
= Bootstrap::getObjectManager();
14
15
$order
= Bootstrap::getObjectManager()->create(Order::class);
16
$order1
= clone
$order
->loadByIncrementId(
'100000001'
);
17
$order2
= clone
$order
->loadByIncrementId(
'100000002'
);
18
$order3
= clone
$order
->loadByIncrementId(
'100000003'
);
19
21
$productRepository
=
$objectManager
->create(
Magento
\Catalog\Model\ProductRepository::class);
22
$product1
=
$productRepository
->get(
'Simple Product 1 sku'
);
23
$product2
=
$productRepository
->get(
'Simple Product 2 sku'
);
24
$product3
=
$productRepository
->get(
'Simple Product 3 sku'
);
25
$product4
=
$productRepository
->get(
'Simple Product 4 sku'
);
26
27
//@codingStandardsIgnoreStart
28
$productOptionValue
=
'{"info_buyRequest":{"uenc":"aHR0cDovL21hZ2VudG90MjIubG9jYWwvdGVzdC5odG1s","product":"%s","qty":1}}'
;
29
//@codingStandardsIgnoreEnd
30
31
$orderItems
= [
32
[
33
'item_id'
=> 1,
34
'product_id'
=>
$product1
->getId(),
35
'order_id'
=>
$order1
->getId(),
36
'base_price'
=> 90,
37
'price'
=> 90,
38
'row_total'
=> 92,
39
'product_type'
=>
'simple'
,
40
'product_options'
=> sprintf(
$productOptionValue
,
$product1
->getId())
41
],
42
[
43
'item_id'
=> 2,
44
'product_id'
=>
$product2
->getId(),
45
'base_price'
=> 100,
46
'order_id'
=>
$order2
->getId(),
47
'price'
=> 100,
48
'row_total'
=> 102,
49
'product_type'
=>
'simple'
,
50
'product_options'
=> sprintf(
$productOptionValue
,
$product2
->getId())
51
],
52
[
53
'item_id'
=> 3,
54
'product_id'
=>
$product3
->getId(),
55
'base_price'
=> 110,
56
'order_id'
=>
$order3
->getId(),
57
'price'
=> 110,
58
'row_total'
=> 112,
59
'product_type'
=>
'simple'
,
60
'product_options'
=> sprintf(
$productOptionValue
,
$product3
->getId())
61
],
62
[
63
'item_id'
=> 4,
64
'product_id'
=>
$product4
->getId(),
65
'base_price'
=> 123,
66
'order_id'
=>
$order3
->getId(),
67
'price'
=> 123,
68
'row_total'
=> 126,
69
'product_type'
=>
'simple'
,
70
'product_options'
=> sprintf(
$productOptionValue
,
$product4
->getId())
71
],
72
];
73
75
$orderItem
= Bootstrap::getObjectManager()->create(
76
\
Magento
\Sales\Model\
Order
\Item::class
77
);
78
foreach
(
$orderItems
as $orderItemData) {
79
$orderItem
->isObjectNew(
true
);
81
$orderItem
82
->setData($orderItemData)
83
->save();
84
}
Magento\Sales\Model\Order
Definition:
Order.php:54
$productRepository
$productRepository
Definition:
order_items.php:21
$productOptionValue
$productOptionValue
Definition:
order_items.php:28
$product4
$product4
Definition:
order_items.php:25
Magento\TestFramework\Helper\Bootstrap
Definition:
Bootstrap.php:12
Magento\Sales\Model\Order
$objectManager
$objectManager
Definition:
order_items.php:13
$product2
$product2
Definition:
order_items.php:23
$order
$order
Definition:
order_items.php:15
$orderItem
$orderItem
Definition:
order_items.php:75
$orderItems
$orderItems
Definition:
order_items.php:31
$product1
$product1
Definition:
order_items.php:22
$product3
$product3
Definition:
order_items.php:24
$order2
$order2
Definition:
order_items.php:17
$order3
$order3
Definition:
order_items.php:18
Magento
$order1
$order1
Definition:
order_items.php:16