Добавить поле в разделе платежный адрес
Я пытаюсь добавить флажок над "адрес выставления счета совпадает с адресом доставки".
Я добавил это в свой плагин layoutprocessor:
protected function addFieldsToSubscribeToNewsletter($jsLayoutResult)
{
$jsLayoutResult['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['billing-address']['children']['subscribe_to_newsletter'] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'BigBridge_Checkout/form/element/checkbox-overwrite'
],
'provider' => 'checkoutProvider',
'dataScope' => 'shippingAddress.custom_attributes.subscribe_to_newsletter',
'description' => __('Subscribe to the newsletter'),
'sortOrder' => '1008',
'validation' => [
'required-entry' => false,
],
'displayArea' => 'checkout-newsletter-subscribe'
];
return $jsLayoutResult;
}
Если я попытаюсь добавить его в поля формы, это сработает, но это неправильное местоположение. (там написано "этап доставки", потому что я переместил его с этапа выставления счетов на этап доставки). Я чувствую, что, возможно, мне нужно сначала создать новый регион, потому что в billing-address.html нет региона для размещения новых полей? Но я не уверен как.
Может ли кто-нибудь указать мне правильное направление?
2 answers
Чтобы добавить пользовательское поле под адресом выставления счета, выполните действия, описанные в следующей статье:
Как добавить пользовательские поля на страницу оформления заказа в Magento2
Вместо адреса отправки вам нужно определить адрес выставления счетов. вот и все.
Это решит ваш запрос.
Я создал контейнер вокруг нового поля, и теперь он работает. В моем LayoutProcessorPlugin я добавил:
protected function addFieldsToSubscribeToNewsletter($jsLayoutResult)
{
if (!$this->customerSession->isLoggedIn()) {
$jsLayoutResult['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['customer-email']['children']['additional-login-form-fields']['children']['subscribe_to_newsletter'] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'BigBridge_Checkout/form/element/checkbox-overwrite'
],
'provider' => 'checkoutProvider',
'dataScope' => 'shippingAddress.custom_attributes.subscribe_to_newsletter',
'description' => __('Subscribe to the newsletter')
];
} else {
$jsLayoutResult['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['billing-address']['children']['subscribe_container'] = [
'component' => 'uiComponent',
'displayArea' => 'subscribe_container'
];
$jsLayoutResult['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['billing-address']['children']['subscribe_container']['children']['subscribe_to_newsletter'] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'BigBridge_Checkout/form/element/checkbox-overwrite'
],
'provider' => 'checkoutProvider',
'dataScope' => 'shippingAddress.custom_attributes.subscribe_to_newsletter',
'description' => __('Subscribe to the newsletter')
];
}
return $jsLayoutResult;
В billing-address.html я добавил:
<!-- ko foreach: getRegion('subscribe_container') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->