AddressFinder / addressfinder-magento

AddressFinder extension for Magento 2
Other
7 stars 7 forks source link

Too many mutations prevent AddressFinder from working? identifiedFormHelperConfig is empty array. #59

Closed LiamKarlMitchell closed 4 years ago

LiamKarlMitchell commented 4 years ago

When debug mode is switched on I see this console log.

Page is triggering a large amount of mutations, which may prevent AddressFinder from working, and will slow down your store.

Sorry I don't quite understand what this means, would someone be able to elobrate?

This time it is on a Magento 2.3.2 website with a WeltPixel theme installed via composer from this documentation. https://addressfinder.nz/docs/magento/

Address lookup does not appear to be working, although they could have modified the checkout form/template, is this mutations warning onto something here or can I ignore it?

Would having the Magento 2 site in production mode lower mutations and make Address Finder work?

Do I have to tweak these values higher?

    this.millisecondsToIgnoreMutations = 750; // The amount of times the page can mutate in a row without forcing AddressFinder to be reinitialised.
    this.maxMutationTimeoutCount = 20; // The count of the times the page has mutated in a row

image

Or is the DOM modified from what AddressFinder expects?

image

I did see a guide for how to fix that if so on the readme.

bencorlett commented 4 years ago

Hi @LiamKarlMitchell! This is a warning due to how Magento re-renders the DOM on the page using KnockoutJS while AF is also watching this DOM. Your second screenshot is showing Magento's Knockout templates.

I believe this is to be expected on Magento sites, just due to how their templating system works. It shouldn't have an adverse affect in production, those values are set quite low to catch edge-cases. The autocomplete JS is shared amongst many environments (not just Magento), that's why the warning exists.

@katenorquay, not sure if I missed anything?

LiamKarlMitchell commented 4 years ago

Hi @bencorlett thanks for the speedy reply. No that makes sense there must be some other reason that it is not working then? I just thought the Mutations warning might have been a hint as to the reason why.

I just checked the address1 mapping for NZ and it appears to be correct e.g. the selector used in Observer/FormConfig/AddCheckoutShippingAddress.php when I use it with jQuery to toggle the element the input I expect is effected.

jQuery('.form-shipping-address input[name="street[0]"]').toggle()

But when I start typing an address no address lookups are coming through and there is no network lookups for autocomplete results.

Any thoughts or a guide on how I can further debug this?

Magento 2.3.2 Development mode. NZ Free license. addressfinder/module-magento2 v1.4.0 Did the rebuild steps, cleared cache/browser cache etc.

image

Just tried customer address book it does not activate there either. But the JS files are loaded. image

bencorlett commented 4 years ago

Curious, do you see a similar structure to the following when (via your browser's console) logging window.AddressFinder?

Screen Shot 2020-03-18 at 5 21 17 pm

LiamKarlMitchell commented 4 years ago

No I don't it is empty.

I had put it into Production mode this time.

Edit: Ah right set the key back to demo key just to check even with my key it is identifying the address form configurations. Sorry my mistake.

image

So I just need to track down why identifiedFormHelperConfig has nothing defined and possibly write an observer to fix it?

bencorlett commented 4 years ago

Hmm. This is peculiar. Have you by chance copied AF resources (template files, JS, etc) into your own theme? We added the ability to add custom forms in version 1.4.0 and if you've overridden templates, you might have experienced issues potentially?

LiamKarlMitchell commented 4 years ago

I have not copied AF resources into my theme and they are not in the parent theme either.

New site with WeltPixel theme and the AddressFinder module installed with Composer.

Ag search in files within app folder for addressfinder only shows up the module being enabled in the config php.

/opt/containers/sites/devsite/html/app# ag "addressfinder"
etc/config.php
207:        'AddressFinder_AddressFinder' => 1,
bencorlett commented 4 years ago

Could you modify app/code/AddressFinder/AddressFinder/view/frontend/templates/plugin.phtml to look like this?

Screen Shot 2020-03-18 at 5 47 37 pm 1

        console.log({
            "widgetConfig": widgetConfig,
            "formsConfig": formsConfig
        });

Do you get something like this in your browser console?

Screen Shot 2020-03-18 at 5 50 25 pm

LiamKarlMitchell commented 4 years ago

formsConfig is an empty array looks equivalent in widgetConfig other than the key and default_country: "nz"

This block logs out to system.log

==> system.log <==
[2020-03-18 06:59:32] main.ERROR: Could not attach checkout billing address: The country isn't available.. [] []
[2020-03-18 06:59:32] main.ERROR: Could not attach checkout shipping address: The country isn't available.. [] []
[2020-03-18 06:59:32] main.ERROR: Could not attach customer address book: The country isn't available.. [] []
[2020-03-18 06:59:32] main.WARNING: There are no configured forms for AddressFinder. [] []
LiamKarlMitchell commented 4 years ago

So it's the same problem as before maybe? #21 although that time I had a site which had disabled the Country Input.

This time it is right there on the form.

image

LiamKarlMitchell commented 4 years ago

So it is defaulting to AU country when it needs to default to NZ country. #21

The Magento site is locked down to just NZ with only NZ selected in Allow Countries if that makes any difference?

image

I went into the Observer and in its execute method changed the $this->stateMappingProvider->forCountry('AU') to 'NZ' now it appears to work.

Just have to get the domain registered to the license key :)

image

I think these hard coded options need to pull from the configured Default Search Country. I'll try to re-visit it tomorrow if I have time pretty sure its just a matter of getting the correct country code from the configured drop down :) thanks @bencorlett

bencorlett commented 4 years ago

Good spot. The state mapping with NZ isn’t the issue here, but rather exiting when Australia is disabled as a country.

Sent from my iPad

Please excuse my brevity

On 18 Mar 2020, at 6:08 pm, Liam Mitchell notifications@github.com wrote:  So it is defaulting to AU country when it needs to default to NZ country. #21

The Magento site is locked down to just NZ with only NZ selected in Allow Countries if that makes any difference?

I went into the Observer and in its execute method changed the $this->stateMappingProvider->forCountry('AU') to 'NZ' now it appears to work.

Just have to get the domain registered to the license key :)

I think these hard coded options need to pull from the configured Default Search Country.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

LiamKarlMitchell commented 4 years ago

Ah yes, I see that now. Entries for AU and NZ should only be added if those countries are enabled?

As far as I know Magento does not have region mappings for NZ by default so having it null is fine.

SELECT * FROM directory_country_region WHERE code = 'NZ'