|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Payone\Core\Model\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Customer\Api\CustomerMetadataInterface; |
|
|
|
|
|
|
6
|
|
|
use Magento\Framework\Serialize\Serializer\Json; |
|
|
|
|
|
|
7
|
|
|
use Magento\Checkout\Model\Session; |
|
|
|
|
|
|
8
|
|
|
use Payone\Core\Model\Source\CreditratingCheckType; |
|
9
|
|
|
|
|
10
|
|
|
class GuestCheckoutLayoutProcessor |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var \Magento\Customer\Api\CustomerMetadataInterface |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $customerMetaData; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \Magento\Framework\Serialize\Serializer\Json |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $json; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* PAYONE order helper |
|
24
|
|
|
* |
|
25
|
|
|
* @var \Payone\Core\Helper\Checkout |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $checkoutHelper; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \Magento\Checkout\Model\Session |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $checkoutSession; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var \Magento\Framework\View\Asset\Repository |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
|
|
protected $assetRepo; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* GuestCheckoutLayoutProcessor constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param \Magento\Customer\Api\CustomerMetadataInterface $customerMetadata |
|
43
|
|
|
* @param \Magento\Framework\Serialize\Serializer\Json $json |
|
44
|
|
|
* @param \Payone\Core\Helper\Checkout $checkoutHelper |
|
45
|
|
|
* @param \Magento\Checkout\Model\Session $checkoutSession |
|
46
|
|
|
* @param \Magento\Framework\View\Asset\Repository $assetRepo |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( |
|
49
|
|
|
\Magento\Customer\Api\CustomerMetadataInterface $customerMetadata, |
|
50
|
|
|
\Magento\Framework\Serialize\Serializer\Json $json, |
|
51
|
|
|
\Payone\Core\Helper\Checkout $checkoutHelper, |
|
52
|
|
|
\Magento\Checkout\Model\Session $checkoutSession, |
|
53
|
|
|
\Magento\Framework\View\Asset\Repository $assetRepo |
|
54
|
|
|
) { |
|
55
|
|
|
$this->json = $json; |
|
56
|
|
|
$this->customerMetaData = $customerMetadata; |
|
57
|
|
|
$this->checkoutHelper = $checkoutHelper; |
|
58
|
|
|
$this->checkoutSession = $checkoutSession; |
|
59
|
|
|
$this->assetRepo = $assetRepo; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Check if form has to be extended |
|
64
|
|
|
* Extension needed for guest checkout when Boniversum creditrating is enabled |
|
65
|
|
|
* |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function isExtendedCustomerFormNeeded() |
|
69
|
|
|
{ |
|
70
|
|
|
if ($this->checkoutHelper->getCurrentCheckoutMethod($this->checkoutSession->getQuote()) != \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) { |
|
|
|
|
|
|
71
|
|
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (!$this->checkoutHelper->getConfigParam('enabled', 'creditrating', 'payone_protect')) { |
|
75
|
|
|
return false; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$sBonicheckType = $this->checkoutHelper->getConfigParam('type', 'creditrating', 'payone_protect'); |
|
79
|
|
|
if ($sBonicheckType != CreditratingCheckType::BONIVERSUM_VERITA) { |
|
80
|
|
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject |
|
87
|
|
|
* @param array $jsLayout |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, array $jsLayout) |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
// Only add extra fields to guest checkout |
|
93
|
|
|
if ($this->isExtendedCustomerFormNeeded() === false) { |
|
94
|
|
|
return $jsLayout; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$shippingAddress = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] |
|
98
|
|
|
['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; |
|
99
|
|
|
|
|
100
|
|
|
$this->addGenderField($shippingAddress); |
|
101
|
|
|
$this->addBirthdayField($shippingAddress); |
|
102
|
|
|
|
|
103
|
|
|
return $jsLayout; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param $jsLayout |
|
108
|
|
|
* @return void |
|
109
|
|
|
*/ |
|
110
|
|
|
private function addGenderField(&$jsLayout) |
|
111
|
|
|
{ |
|
112
|
|
|
$options = $this->getGenderOptions() ?: []; |
|
113
|
|
|
$enabled = $this->isEnabled(); |
|
114
|
|
|
if (!empty($options) && $enabled) { |
|
115
|
|
|
$jsLayout['gender'] = [ |
|
116
|
|
|
'component' => 'Magento_Ui/js/form/element/select', |
|
117
|
|
|
'config' => [ |
|
118
|
|
|
'template' => 'ui/form/field', |
|
119
|
|
|
'elementTmpl' => 'ui/form/element/select', |
|
120
|
|
|
'id' => 'gender', |
|
121
|
|
|
'options' => $options |
|
122
|
|
|
], |
|
123
|
|
|
'label' => __('Gender'), |
|
|
|
|
|
|
124
|
|
|
'provider' => 'checkoutProvider', |
|
125
|
|
|
'visible' => true, |
|
126
|
|
|
'validation' => [ |
|
127
|
|
|
'required-entry' => true |
|
128
|
|
|
], |
|
129
|
|
|
'sortOrder' => 10, |
|
130
|
|
|
'id' => 'gender', |
|
131
|
|
|
'dataScope' => 'shippingAddress.gender', |
|
132
|
|
|
]; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param $jsLayout |
|
138
|
|
|
* @return void |
|
139
|
|
|
*/ |
|
140
|
|
|
private function addBirthdayField(&$jsLayout) |
|
141
|
|
|
{ |
|
142
|
|
|
$enabled = $this->isEnabled(); |
|
143
|
|
|
if ($enabled) { |
|
144
|
|
|
$jsLayout['dob'] = [ |
|
145
|
|
|
'component' => 'Magento_Ui/js/form/element/date', |
|
146
|
|
|
'config' => [ |
|
147
|
|
|
'template' => 'ui/form/field', |
|
148
|
|
|
'additionalClasses' => 'date field-dob', |
|
149
|
|
|
'elementTmpl' => 'ui/form/element/date', |
|
150
|
|
|
'id' => 'dob', |
|
151
|
|
|
'options' => [ |
|
152
|
|
|
'changeYear' => true, |
|
153
|
|
|
'changeMonth' => true, |
|
154
|
|
|
'showOn' => "both", |
|
155
|
|
|
'buttonText' => "Select Date", |
|
156
|
|
|
'maxDate' => "-1d", |
|
157
|
|
|
'yearRange' => "-120y:c+nn", |
|
158
|
|
|
'showsTime' => false, |
|
159
|
|
|
'buttonImage' => $this->assetRepo->getUrlWithParams('Magento_Theme::calendar.png', ['_secure' => true]) |
|
160
|
|
|
], |
|
161
|
|
|
], |
|
162
|
|
|
'label' => __('Date of Birth'), |
|
|
|
|
|
|
163
|
|
|
'provider' => 'checkoutProvider', |
|
164
|
|
|
'visible' => true, |
|
165
|
|
|
'validation' => [ |
|
166
|
|
|
'required-entry' => true |
|
167
|
|
|
], |
|
168
|
|
|
'sortOrder' => 1000, |
|
169
|
|
|
'id' => 'dob', |
|
170
|
|
|
'dataScope' => 'shippingAddress.dob', |
|
171
|
|
|
]; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Retrieve customer attribute instance |
|
177
|
|
|
* |
|
178
|
|
|
* @param string $attributeCode |
|
179
|
|
|
* @return \Magento\Customer\Api\Data\AttributeMetadataInterface|null |
|
|
|
|
|
|
180
|
|
|
*/ |
|
181
|
|
|
protected function _getAttribute($attributeCode) |
|
182
|
|
|
{ |
|
183
|
|
|
try { |
|
184
|
|
|
return $this->customerMetaData->getAttributeMetadata($attributeCode); |
|
185
|
|
|
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) { |
|
|
|
|
|
|
186
|
|
|
return null; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return array |
|
192
|
|
|
*/ |
|
193
|
|
|
private function getGenderOptions() |
|
194
|
|
|
{ |
|
195
|
|
|
$optionsData = []; |
|
196
|
|
|
|
|
197
|
|
|
$attribute = $this->_getAttribute('gender'); |
|
198
|
|
|
if ($attribute) { |
|
199
|
|
|
$options = $attribute->getOptions() ?: []; |
|
200
|
|
|
|
|
201
|
|
|
foreach ($options as $option) { |
|
202
|
|
|
$optionsData[] = [ |
|
203
|
|
|
'label' => __($option->getLabel()), |
|
|
|
|
|
|
204
|
|
|
'value' => $option->getValue() |
|
205
|
|
|
]; |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
return $optionsData; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return bool |
|
213
|
|
|
*/ |
|
214
|
|
|
public function isEnabled() |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isVisible() : false; |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths