-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUpdateOrder.php
94 lines (75 loc) · 3.15 KB
/
UpdateOrder.php
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
<?php
/* Update order field `product_options` in table `sales_order_item`*/
use Magento\Framework\Exception\NoSuchEntityException;
$file = 'app/bootstrap.php';
require $file;
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
class ZUpdateOrder extends \Magento\Framework\App\Http implements \Magento\Framework\AppInterface
{
protected $orderRepository;
protected $orderStatusRepository;
protected $orderCollectionFactory;
protected $logger;
protected $total;
public function launch()
{
$this->_state->setAreaCode('adminhtml');
$this->orderCollectionFactory = $this->_objectManager->get('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory');
$this->orderRepository = $this->_objectManager->create('\Magento\Sales\Api\OrderRepositoryInterface');
$this->orderStatusRepository = $this->_objectManager->create('\Magento\Sales\Api\OrderStatusHistoryRepositoryInterface');
$this->logger = $this->_objectManager->create('\Psr\Log\LoggerInterface');
$collection = $this->getOrderCollection();
foreach ($collection as $order) {
$this->updateOrder($order->getId());
}
echo __("Total update order update: %1 \n", $this->total);
return $this->_response;
}
public function getOrderCollection()
{
$collection = $this->orderCollectionFactory->create()->addAttributeToSelect('*');
return $collection;
}
public function updateOrder($orderId)
{
$order = null;
try {
$order = $this->orderRepository->get($orderId);
} catch(NoSuchEntityException $exception) {
$this->logger->error($exception->getMessage());
}
if ($order){
$items = $order->getAllitems();
foreach ($items as $item) {
$options = $item->getProductOptions();
if(!$options){
// var_dump($options);
// var_dump($item->getData('product_type'));
$options = [
"info_buyRequest" => [
"uenc"=> "aHR0cHM6Ly9tZWRpY2FsLXRvb2xzLmNvbS9zaG9wL3ZldGVyaW5hcnktc3V0dXJlLWtpdC5odG1s",
"id" => $item->getData('product_id'),
"product" => $item->getData('product_id'),
"selected_configurable_option" => '',
"related_product" => '',
"qty" => 1
// "qty" => $item->getData('qty_ordered')
]
];
$item->setProductOptions($options);
// $item->save();
}
}
try {
$order->save();
$this->total++;
// echo __("Done update order Id: %1 \n", $order->getId());
} catch(\Exception $exception){
$this->logger->critical($exception->getMessage());
}
}
}
}
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('ZUpdateOrder');
$bootstrap->run($app);