-
Notifications
You must be signed in to change notification settings - Fork 61
/
OptionsAbstract.php
121 lines (105 loc) · 3.01 KB
/
OptionsAbstract.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace TIG\PostNL\Block\Adminhtml\Shipment;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\View\Element\BlockInterface;
use Magento\Sales\Model\OrderRepository;
use Magento\Framework\Registry;
use Magento\Sales\Model\Order\Shipment;
use TIG\PostNL\Service\Options\ShipmentSupported;
use TIG\PostNL\Config\Source\Options\ProductOptions as ProductOptionSource;
abstract class OptionsAbstract extends Template implements BlockInterface
{
/**
* @var \Magento\Sales\Model\Order
*/
// @codingStandardsIgnoreLine
protected $order;
/**
* @var ShipmentSupported
*/
// @codingStandardsIgnoreLine
protected $productConfig;
/**
* @var ProductOptionSource
*/
// @codingStandardsIgnoreLine
protected $productSource;
/**
* @var OrderRepository
*/
// @codingStandardsIgnoreLine
protected $orderRepository;
/**
* @var Registry
*/
// @codingStandardsIgnoreLine
protected $registry;
/**
* @param Context $context
* @param ShipmentSupported $productOptions
* @param ProductOptionSource $productOptionsSource
* @param OrderRepository $orderRepository
* @param Registry $registry
* @param array $data
*/
public function __construct(
Context $context,
ShipmentSupported $productOptions,
ProductOptionSource $productOptionsSource,
OrderRepository $orderRepository,
Registry $registry,
array $data = []
) {
parent::__construct($context, $data);
$this->productConfig = $productOptions;
$this->productSource = $productOptionsSource;
$this->orderRepository = $orderRepository;
$this->registry = $registry;
}
/**
* @return \Magento\Sales\Api\Data\OrderInterface|\Magento\Sales\Model\Order
*/
// @codingStandardsIgnoreLine
protected function getOrder()
{
if ($this->order) {
return $this->order;
}
$request = $this->getRequest();
$orderId = (int)$request->getParam('order_id');
if (!$orderId) {
$orderId = $this->getShipment()->getOrderId();
}
return $this->order = $this->orderRepository->get($orderId);
}
/**
* @return bool
*/
public function getIsPostNLOrder()
{
$method = $this->getOrder()->getShippingMethod();
return ($method == 'tig_postnl_regular');
}
/**
* @return array
*/
public function getProductOptions()
{
$supportedCodes = $this->productConfig->get($this->getOrder());
$productOptions = [];
foreach ($supportedCodes as $code) {
$productOptions[$code] = $this->productSource->getOptionsByCode($code);
}
return $productOptions;
}
/**
* Retrieve shipment model instance
*
* @return Shipment
*/
public function getShipment()
{
return $this->registry->registry('current_shipment');
}
}