Skip to content
Snippets Groups Projects
Select Git revision
  • a1543ef9a6aae0803dc7dd7689f0d5f8a1feba58
  • dev default protected
  • prod protected
  • 1.0.58
  • 1.0.57
  • 1.0.52
  • 1.0.56
  • 1.0.51
  • 1.0.50
  • 1.0.33
  • 1.0.32
  • 1.0.31
  • 1.0.30
  • 1.0.29
  • 1.0.28
  • 1.0.27
  • 1.0.26
  • 1.0.25
  • 1.0.24
  • 1.0.23
  • 1.0.22
  • 1.0.21
  • 1.0.20
23 results

LayoutProcessorPlugin.php

Blame
  • LayoutProcessorPlugin.php 2.12 KiB
    <?php
    namespace BobGroup\BobGo\Plugin\Checkout\Block;
    
    use Magento\Checkout\Block\Checkout\LayoutProcessor;
    
    /**
     * Class LayoutProcessorPlugin
     * @package BobGroup\BobGo\Plugin\Checkout\Block
     * This class is supposed to add a new field to the checkout page for the suburb. It is supposed to be used in conjunction with the SaveOrderBeforeSalesModelQuote observer.
     * At the moment, it overrides the 2 Address fields and adds a new 3 Address field to accommodate the suburb on the checkout page( including placeholders).
     * This is not the best way to do it, but it is the only way I could get it to work.
     */
    class LayoutProcessorPlugin
    {
        /**
         * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
         * @param array $jsLayout
         * @return array
         */
    
        public function afterProcess(
            \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
            array  $jsLayout
        ) {
            $suburbAttribute = 'suburb';
            $suburb = [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress.custom_attributes',
                    'customEntry' => null,
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/input',
                    'tooltip' => [
                        'description' => 'Required for shipping accuracy',
                    ],
                ],
                'dataScope' => 'shippingAddress.custom_attributes' . '.' . $suburbAttribute,
                'label' => 'Suburb',
                'provider' => 'checkoutProvider',
                'sortOrder' => 80,
                'validation' => [
                    'required-entry' => true
                ],
                'options' => [],
                'filterBy' => null,
                'customEntry' => null,
                'visible' => true,
                'value' => '' // value field is used to set a default value of the attribute
            ];
    
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'][$suburbAttribute] = $suburb;
    
            return $jsLayout;
        }
    }