/
LayoutProcessor.php
96 lines (90 loc) · 4.02 KB
/
LayoutProcessor.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
<?php
namespace Magelearn\DeliveryDate\Plugin\Checkout\Block;
use Magelearn\DeliveryDate\Model\Config;
class LayoutProcessor
{
/**
* @var \Magelearn\DeliveryDate\Model\Config
*/
protected $config;
/**
* LayoutProcessor constructor.
*
* @param Config $config
*/
public function __construct(
Config $config
) {
$this->config = $config;
}
/**
* @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* @param array $jsLayout
* @return array
*/
public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
array $jsLayout
) {
$requiredDeliveryDate = $this->config->getRequiredDeliveryDate()?: false;
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shippingAdditional'] = [
'component' => 'uiComponent',
'displayArea' => 'shippingAdditional',
'children' => [
'delivery_date' => [
'component' => 'Magelearn_DeliveryDate/js/view/delivery-date-block',
'displayArea' => 'delivery-date-block',
'deps' => 'checkoutProvider',
'dataScopePrefix' => 'delivery_date',
'children' => [
'form-fields' => [
'component' => 'uiComponent',
'displayArea' => 'delivery-date-block',
'children' => [
'delivery_date' => [
'component' => 'Magelearn_DeliveryDate/js/view/delivery-date',
'config' => [
'customScope' => 'delivery_date',
'template' => 'ui/form/field',
'elementTmpl' => 'Magelearn_DeliveryDate/fields/delivery-date',
'options' => [],
'id' => 'delivery_date',
'data-bind' => ['datetimepicker' => true]
],
'dataScope' => 'delivery_date.delivery_date',
'label' => 'Delivery Date',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => [
'required-entry' => $requiredDeliveryDate
],
'sortOrder' => 10,
'id' => 'delivery_date'
],
'delivery_comment' => [
'component' => 'Magento_Ui/js/form/element/textarea',
'config' => [
'customScope' => 'delivery_date',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/textarea',
'options' => [],
'id' => 'delivery_comment'
],
'dataScope' => 'delivery_date.delivery_comment',
'label' => 'Comment',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => [],
'sortOrder' => 20,
'id' => 'delivery_comment'
]
],
],
]
]
]
];
return $jsLayout;
}
}