0

I injected this code in LayoutPorcessor of checkout module :

    if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children'])
        ) {
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['subscribe'] = [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/checkbox',
                    'options' => [],
                    'id' => 'delivery-date',
                ],
                'dataScope' => 'shippingAddress.newsletter_subscribe',
                'label' => 'Sign Up for Newsletter',
                'provider' => 'checkoutProvider',
                'visible' => true,
                'checked' => true,
                'validation' => [],
                'sortOrder' => 250,
                'id' => 'newsletter-subscribe',
                'value' => 'subscription',
            ];
        }

I can see the Newsletter checkbox but how can I validate the information to get consumer email in newsletter_suscriber table ?

I modified too : Model/Shipping-save-processor/default.js

saveShippingInformation: function () {
        var payload;

        if (!quote.billingAddress() && quote.shippingAddress().canUseForBilling()) {
            selectBillingAddressAction(quote.shippingAddress());
        }

        var subscribe = $('[name="newsletter_subscribe"]').is(':checked') ? 1 : 0

        payload = {
            addressInformation: {
                'shipping_address': quote.shippingAddress(),
                'billing_address': quote.billingAddress(),
                'shipping_method_code': quote.shippingMethod()['method_code'],
                'shipping_carrier_code': quote.shippingMethod()['carrier_code']
                 extension_attributes:{
                        subscribe: subscribe
                        }
            }
        };

I need your help please! Best regards!

  • HI, thank you for the link but is little different that my exemple :/ I'm still lost... Can you help me show me what I need to do after I putted the layout on LayoutProcessor? I need to validate : 'id' => 'newsletter-subscribe', with JS and after call subscribe function in controller ? I don't know how it work :( – user78027 Mar 27 at 18:08
  • Note : I don't want create a module, I just want implement my code directly checkout module to understand the mechanism of Magento 2. Thank you for your help! – user78027 Mar 27 at 18:08
  • I know that I need to validate the information of LayoutPorcessor with default-validator but after I don't know what to do to have the email in the newsletter table – user78027 Mar 27 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy