Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coupling beetwen Magento_Checkout::js/view/shipping.js:validateShippingInformation() and layout definition or view. #22416

Closed
funkyproject opened this issue Apr 18, 2019 · 6 comments · Fixed by #25541
Assignees
Labels
Area: Frontend Component: Checkout Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@funkyproject
Copy link

Summary

On checkout shipping step, I reorganized the shipping address form and moved the postCode and countryId fields into a group.

I can't validate the shipping address without overriding the Magento_Checkout:js/view/shipping.js file and particulary the validateShippingInformation().

country = registry.get(this.parentName + '.shippingAddress.shipping-address-fieldset.country_id'),

In my case, I need to change this to :

country = registry.get(this.parentName + '.shippingAddress.shipping-address-fieldset.address_group.country_id'),

Preconditions

  1. Magento CE 2.3.1

Steps to reproduce

  1. Move the country_id field of shipping form into checkout.
  2. validate the shipping address.

Examples (*)

This is the layoutProcessorPlugin for reorganize the shipping and billing form:

use Magento\Checkout\Block\Checkout\LayoutProcessor;

/**
 * Alter  Layout Processor and change shipping form
 */
class LayoutProcessorPlugin
{
    /**
     * Change jsLayout after process.
     *
     * @param LayoutProcessor $subject
     * @param array $jsLayout
     *
     * @return array
     *
     * @SuppressWarnings("unused")
     */
    public function afterProcess(LayoutProcessor $subject, $jsLayout): array
    {
        $this->updateShippingForm($jsLayout);
        $this->updateBillingForm($jsLayout);
        $this->moveBillingForm($jsLayout);

        return $jsLayout;
    }

    /**
     * Update shipping form.
     *
     * @param array $jsLayout
     */
    private function updateShippingForm(&$jsLayout): void
    {
        $fieldSet = &$jsLayout['components']['checkout']['children']
        ['steps']['children']['shipping-step']['children']['shippingAddress']
        ['children']['shipping-address-fieldset']['children'];

        $this->updateAddressForm($fieldSet, true);
    }

    /**
     * Update billing form.
     *
     * @param array $jsLayout
     */
    private function updateBillingForm(&$jsLayout): void
    {
        $fieldSet = &$jsLayout['components']['checkout']['children']
        ['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']
        ['billing-address-form']['children']['form-fields']['children'];

        $this->updateAddressForm($fieldSet, false);
    }

    /**
     * Update address form.
     *
     * @param array $fieldSet
     * @param bool $isShipping
     *
     * @SuppressWarnings(PHPMD)
     */
    private function updateAddressForm(&$fieldSet, bool $isShipping): void
    {
        $sort = [
            'prefix'             => ['sortOrder' => 5],
            'firstname_lastname' => ['sortOrder' => 10],
            'company_group'      => ['sortOrder' => 20],
            'address_group'      => ['sortOrder' => 200],
            'last_group'         => ['sortOrder' => 220],
            'region_id'          => ['sortOrder' => 210]
        ];

        $fieldSet['email'] = $fieldSet['firstname'];
        $fieldSet['email']['type'] = 'email';
        $fieldSet['email']['label'] = __('Email');
        $fieldSet['email']['dataScope'] = 'shippingAddress.email';

        $fieldSet['prefix']['component'] = 'Magento_Ui/js/form/element/checkbox-set';
        $fieldSet['prefix']['multiple'] = false;
        $fieldSet['prefix']['config']['template'] = 'ui/form/element/checkbox-set';
        $fieldSet['prefix']['config']['elementTpl'] = 'ui/form/components/single/radio';

        $fieldSet['firstname']['sortOrder'] = 2;
        $fieldSet['lastname']['sortOrder'] = 1;

        $fieldSet['postcode']['validation']['domtom'] = true;

        unset($fieldSet['telephone']['config']['tooltip']);
        $groups = [];
        $groups['firstname_lastname'] = [
            'component' => 'Magento_Ui/js/form/components/group',
            'label'     => [],
            'dataScope' => '',
            'provider'  => 'checkoutProvider',
            'sortOrder' => 1,
            'type'      => 'group',
            'config'    => [
                'template'          => 'ui/group/group',
                'additionalClasses' => 'form__row form__row--two'
            ],
            '_children' => ['lastname', 'firstname']
        ];

        $groups['company_group'] = [
            'component' => 'Magento_Ui/js/form/components/group',
            'label'     => [],
            'dataScope' => '',
            'provider'  => 'checkoutProvider',
            'sortOrder' => 2,
            'type'      => 'group',
            'config'    => [
                'template'          => 'ui/group/group',
                'additionalClasses' => 'form__row form__row--two'
            ],
            '_children' => ['company']
        ];

        $groups['address_group'] = [
            'component' => 'Magento_Ui/js/form/components/group',
            'label'     => [],
            'dataScope' => '',
            'provider'  => 'checkoutProvider',
            'sortOrder' => 2,
            'type'      => 'group',
            'config'    => [
                'template'          => 'ui/group/group',
                'additionalClasses' => 'form__row form__row--three'
            ],
            '_children' => ['postcode', 'city', 'country_id']
        ];

        $groups['last_group'] = [
            'component' => 'Magento_Ui/js/form/components/group',
            'label'     => [],
            'dataScope' => '',
            'provider'  => 'checkoutProvider',
            'sortOrder' => 2,
            'type'      => 'group',
            'config'    => [
                'template'          => 'ui/group/group',
                'additionalClasses' => 'form__row form__row--three'
            ],
            '_children' => ['telephone', 'email']
        ];

        $fieldSet['postcode']['config']['additionalClasses'] = 'field--15';
        $fieldSet['postcode']['sortOrder'] = 1;
        $fieldSet['city']['config']['additionalClasses'] = 'field--30';
        $fieldSet['city']['sortOrder'] = 2;
        $fieldSet['country_id']['config']['additionalClasses'] = 'field--48';
        $fieldSet['country_id']['sortOrder'] = 3;
        $fieldSet['email']['sortOrder'] = 2;
        $fieldSet['telephone']['sortOrder'] = 1;

        $fieldSet['street']['children'][0]['label'] = __('Address');
        $fieldSet['street']['children'][1]['label'] = __('Additional address');
        unset($fieldSet['street']['children'][2]);

        foreach ($groups as $name => $group) {
            $group['children'] = [];
            foreach ($group['_children'] as $childrenName) {
                $group['children'][$childrenName] = $fieldSet[$childrenName];
                unset($fieldSet[$childrenName]);
            }
            $fieldSet[$name] = $group;
        }

        foreach ($sort as $item => $config) {
            $fieldSet[$item] = array_merge($fieldSet[$item], $config);
        }

        unset($fieldSet['region_id']);
    }

    /**
     * Move billing form.
     *
     * @param array $jsLayout
     */
    private function moveBillingForm(&$jsLayout): void
    {
        $billingStep = &$jsLayout['components']['checkout']['children']['steps']['children']
        ['billing-step']['children']['payment']['children'];

        $afterMethods = $billingStep['afterMethods']['children'];
        $billingStep['afterMethods']['children'] = [];

        unset($afterMethods['discount']);
        $billingStep['beforeMethods']['children'] = array_merge(
            $billingStep['beforeMethods']['children'],
            $afterMethods
        );
    }
}

Proposed solution

No idea, but if we could set an alias for the uiRegistry, We could decoupling the view and validation logic.

@m2-assistant
Copy link

m2-assistant bot commented Apr 18, 2019

Hi @funkyproject. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@funkyproject do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Apr 18, 2019
@sudhanshu-bajaj sudhanshu-bajaj changed the title Coupling beetwen Magento_Checkout::js/view/shipping.js:validateShippingInformation() and layout definotion or view. Coupling beetwen Magento_Checkout::js/view/shipping.js:validateShippingInformation() and layout definition or view. Apr 18, 2019
@ghost ghost self-assigned this Apr 26, 2019
@m2-assistant
Copy link

m2-assistant bot commented Apr 26, 2019

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@ghost ghost added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Apr 26, 2019
@ghost ghost removed their assignment Sep 27, 2019
@sdzhepa sdzhepa added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Oct 4, 2019
@ghost ghost assigned krzksz Nov 9, 2019
@krzksz
Copy link
Contributor

krzksz commented Nov 9, 2019

Hey @funkyproject, thanks for finding this out!

Indeed, having paths to different components hardcoded in the source is not in line with Magento best practices. I took some time and applies some changes in https://github.com/magento/magento2/pull/25541/files that I found the most sensible. With it, you should be able to pass adjusted paths to country components through configuration which you seem to be customizing anyway.

Waiting for your feedback regarding this proposed solution.

@krzksz krzksz added Component: Checkout Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 9, 2019
@ghost ghost removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Nov 9, 2019
@ghost
Copy link

ghost commented Nov 9, 2019

✅ Confirmed by @krzksz
Thank you for verifying the issue! 👍 Your confirmation will help us to acknowledge and process this report.

@m2-assistant
Copy link

m2-assistant bot commented Nov 21, 2019

Hi @krzksz. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@VladimirZaets
Copy link
Contributor

Hi @funkyproject. Thank you for your report.
The issue has been fixed in #25541 by @krzksz in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.0 release.

@VladimirZaets VladimirZaets added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Component: Checkout Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants