Coder Social home page Coder Social logo

addressfinder / addressfinder-magento Goto Github PK

View Code? Open in Web Editor NEW
7.0 12.0 7.0 1.08 MB

AddressFinder extension for Magento 2

License: Other

PHP 85.87% JavaScript 6.86% HTML 2.72% Shell 4.56%
address shipping delivery autocomplete australia new-zealand magento2 magento plugin verification

addressfinder-magento's Introduction

AddressFinder for Magento 2

The AddressFinder module for Magento 2 allows you to find verified Australian and New Zealand addresses with an intuitive, search-as-you-type interface.

1. Installation

The module may be installed one of two ways:

  1. Composer (recommended)
  2. Manual

1.1 Via Composer

To install the module via Composer, from the root directory of your Magento installation:

composer require addressfinder/module-magento2

This will automatically fetch the latest compatible version of the module available to your Magento installation. From the root directory of your Magento installation:

bin/magento module:enable AddressFinder_AddressFinder
bin/magento setup:upgrade

1.2 Install manually

To install the module manually, download the source code for the latest compatible version of the module:

Magento Version Latest Compatible Version
2.0.* 1.3.0 (download)
2.1.* 1.5.1 (download)
2.2.* 1.5.1 (download)
2.3.* 2.0.4 (download)
2.4.* 2.0.5 (download)

Extract the .zip / .tar.gz you have downloaded. Copy the contents of the top-level folder that was created during extraction into your Magento store in the following location (you must create these folders manually):

app/code/AddressFinder/AddressFinder/

After copying the contents into this location, you should see a structure containing (but not limited to) the following files/folders:

app/code/AddressFinder/AddressFinder/Block/
app/code/AddressFinder/AddressFinder/etc/
app/code/AddressFinder/AddressFinder/Model/
app/code/AddressFinder/AddressFinder/registration.php
app/code/AddressFinder/AddressFinder/...

From the root directory of your Magento installation:

bin/magento module:enable AddressFinder_AddressFinder
bin/magento setup:upgrade

1.3 Production considerations

Although outside the scope of installing this module, if you are running your Magento store in a production environment, you should run the Magento code compiler and deploy static files:

bin/magento setup:di:compile
bin/magento setup:static-content:deploy

2. Updating

The process for updating the module depends on whether you have installed it via Composer or manually.

2.1 Via Composer

To update the module via Composer, from the root directory of your Magento installation:

composer update addressfinder/module-magento2
bin/magento setup:upgrade

If you are running your Magento store in a production environment, refer to Section (1.3) Production Considerations.

2.2 Update manually

To update the module manually, referring to the instructions in Section (1.2) Install Manually to download the latest compatible version and copy the files into your Magento codebase. After you have copied these files in, simply upgrade the extension:

bin/magento setup:upgrade

If you are running your Magento store in a production environment, refer to Section (1.3) Production Considerations.

3. Configuring the module

The module's settings are controlled within Stores -> Configuration -> Services -> AddressFinder.

Most settings in Magento 2 are guarded with sensible defaults. To customise settings, you'll need to uncheck the use system value for any settings you would like to customise.

3.1 Basic functionality

To get the module functioning in its most basic form, you'll need to:

  1. Change Enabled to Yes.
  2. Sign up for a licence key for Australia or New Zealand and enter this in the License field.

3.2 Customisation features

  1. Depending on the theme your Magento store has, you may need to configure the Default Search Country if your checkout has no country selector.
  2. AddressFinder functions across many forms throughout Magento. The default is to enable it in all supported forms, however you may restrict this with the Enable Specific Forms setting.
  3. Turning on Debug Mode will print debug messages from the AddressFinder JavaScript widget to the browser's console.
  4. You may pass custom Widget Options to the JavaScript widget. This must be a JSON object valid for Australia or New Zealand.

4. Forms

The AddressFinder module is installed within Magento by attaching forms. Out of the box, we support the following frontend forms:

  1. Checkout billing address
  2. Checkout shipping address
  3. Customer address book

In addition, we support the following admin forms:

  1. Order billing address
  2. Order shipping address

4.1 Adding a new form (advanced)

Of course, you may wish to add support for a new form. Luckily, this process is fairly straightforward, however a level of Magento development knowledge is assumed.

Important: All of the examples to follow will assume we'll be working with a module called Acme_CustomForm.

4.1.1 Module creation

You'll firstly need your own module create your own module. Begin by creating the following folder structure:

app/code/Acme/CustomForm/
app/code/Acme/CustomForm/etc/
app/code/Acme/CustomForm/Observer/Config/Source/Frontend/
app/code/Acme/CustomForm/Observer/FormConfig/Frontend/

Create a component registration file at app/code/Acme/CustomForm/registration.php:

<?php

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Acme_CustomForm', __DIR__);

And add a module declaration file at app/code/Acme/CustomForm/etc/module.xml:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Acme_CustomForm" setup_version="0.1.0"/>
</config>

4.1.2 Event observers

Within your module, you'll need to create event observers that'll allow us to add our custom forms to the AddressFinder module. We'll create a frontend form for brevity's, however the process is almost identical for admin forms.

Begin by creating an events file at app/code/Acme/CustomForm/etc/events.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

    <!--
        Attach frontend forms
        (to attach admin forms, simply listen to the event named `addressfinder_form_config_admin` instead)
    -->
    <event name="addressfinder_form_config">
        <observer name="acme_store_locator"
                  instance="Acme\CustomForm\Observer\FormConfig\Frontend\AddStoreLocator"/>
    </event>

    <!-- Attach form selector to admin (optional) -->
    <event name="addressfinder_config_source_forms_enabled">
        <observer name="acme_store_locator"
                  instance="Acme\CustomForm\Observer\Config\Source\Frontend\StoreLocator"/>
    </event>

</config>

4.1.3 Form implementation

You'll notice we referred to two new classes within our event observers. We need to implement these classes.:

  1. The first class will be used to define the form
  2. The second class will add the ability to restrict form selection in the admin. The second class is optional; only required if you wish to restrict forms instead of showing all.

Start by creating the form declaration at app/code/Acme/CustomForm/Observer/FormConfig/Frontend/AddStoreLocator.php:

<?php

namespace Acme\CustomForm\Observer\FormConfig\Frontend;

use AddressFinder\AddressFinder\Observer\FormConfig\Base;
use Exception;
use Magento\Framework\Data\Collection;
use Magento\Framework\DataObject;

class AddStoreLocator extends Base
{
    const FORM_ID = 'frontend.store.locator';

    /**
     * @inheritDoc
     *
     * @throws Exception
     */
    protected function addForm(Collection $forms): void
    {
        $forms->addItem(new DataObject([
            // A unique form ID to identify this form within the AddressFinder module
            'id' => self::FORM_ID,

            // A semantic label
            'label' => 'Store Locatork',

            // The selector for where to instantiate the JavaScript widget
            'layoutSelectors' => ['input#street_1'],

            // The country selector that switches the form between AU and NZ
            'countryIdentifier' => 'select[name=country_id]',

            // The search box selector - this is where your users type to trigger the AddressFinder autocomplete
            'searchIdentifier' => 'input#street_1',

            // NZ-specific config
            'nz' => [
                // The value which the `countryIdentifier` is set as to represent NZ
                'countryValue' => 'NZ',

                // Varying element selectors to place the selected address result in
                'elements' => [
                    'address1' => 'input#street_1',
                    'suburb' => 'input#street_2',
                    'city' => 'input[name=city]',
                    'region' => 'input[name=region]',
                    'postcode' => 'input[name=postcode]',
                ],
                'regionMappings' => null,
            ],

            // AU-specific config
            'au' => [
                // The value which the `countryIdentifier` is set as to represent AU
                'countryValue' => 'AU',

                // Varying element selectors to place the selected address result in
                'elements' => [
                    'address1' => 'input#street_1',
                    'address2' => 'input#street_2',
                    'suburb' => 'input[name=city]',

                    // This helper from the base class we extend will allow us to
                    // support free-form state inputs as well as dropdown menus.
                    'state' => $this->getStateMappings('AU')
                        ? 'select[name=region_id]'
                        : 'input[name=region]',
                    'postcode' => 'input[name=postcode]',
                ],

                // State mappings for Australia (if they exist in your Magento installation)
                'stateMappings' => $this->getStateMappings('AU'),
            ],
        ]));
    }
}

Now we've added the form, we can optionally add the ability to restrict form selection to this new form within the admin. By default, all configured forms are enabled, however the user has the ability to restrict this list in the admin.

In order to add our new form to this list, create app/code/Acme/CustomForm/Observer/Config/Source/Frontend/StoreLocator.php:

<?php

namespace Acme\CustomForm\Observer\Config\Source\Frontend;

use Acme\CustomForm\Observer\FormConfig\Frontend\AddStoreLocator;
use Exception;
use Magento\Framework\Data\Collection;
use Magento\Framework\DataObject;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class StoreLocator implements ObserverInterface
{
    /**
     * @inheritDoc
     *
     * @throws Exception
     */
    public function execute(Observer $observer): void
    {
        /** @var Collection $frontend */

        // If you were building an admin form, you'd call `getData('admin')` and append the form to that list
        $frontend = $observer->getEvent()->getData('frontend');

        $frontend->addItem(new DataObject([
            'label' => 'Store Locator',
            'value' => AddStoreLocator::FORM_ID,
        ]));
    }
}

Congratulations! You have now configured up a new form for your store selector to integrate with AddressFinder. ๐ŸŽ‰

5. Debugging JavaScript widget

To debug the JavaScript widget within your Magento store, pull up your browser's JavaScript console and type:

window.addressfinderDebugMode() // Followed by the `return`/`enter` key.

This will reinitialise the widget, with the debug flag set to true, so you can see console logs from the @addressfinder/addressfinder-webpage-tools npm package.

This works in all modern browsers (and IE11 ๐Ÿ’€)

addressfinder-magento's People

Contributors

1mattramsay avatar bencorlett avatar dependabot[bot] avatar liamkarlmitchell avatar naikipl avatar nigelramsay avatar rickardd avatar vprigent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

addressfinder-magento's Issues

Magento 2 Plugin doesn't handle multiple address forms on the payments page

Blocked: Waiting on Ben to provide feedback

If you have more than one payment method on your Magento checkout, AddressFinder will only load for the first form.

Currently we detect whether to reload AddressFinder based on 2 rules - whether all the form elements are still in the dom, and whether the layout selector has a 'display:none' style.

On this payment page the display:none style is applied to a different element. It is difficult to detect which of the forms is active/visible, as they are for the most part identical.

Current solution is to hard code specifics of each form as address form configurations: https://github.com/abletech/addressfinder-magento/pulls. This solution is ok, but potentially quite brittle.

MAGENTO_BUG1
MAGENTO_BUG2
MAGENTO_BUG_3

Incorrect layout selector for Shipping checkout

Our layout selectors are looking for 'li#opc-shipping_method' and 'li#payment' but we have found a customer who has 'div#opc-shipping_method' and 'div#payment' elements. AddressFinder does not work for this customer.

Could these selectors be updated to just '#opc-shipping_method' and '#payment'?

Magento 2.3 compatibility?

The module does not seem to be compatible with Magento 2.3 version.

As per dependency for magento/framework in composer.json
magento/framework: 100.0.*|100.1.*|101.0.*

Running composer require addressfinder/module-magento2 command breaks.
2019-02-11-11-10

Hyva Theme compatibility issues

Hi Team,

We have upgrade our project and we are using Hyva Theme (https://www.hyva.io/) while installing the AddressFinder module we are facing lot of issue.
Just wanted to know do we have hyva compatible module so we can use the AddressFinder.

Thank you
Karuna Khatri

Error with Amasty Recurring Payments model.

I cannot use Amasty RecurringPayments model with Address finder Module.

Getting below error When activating the module.
Magento 2.4.3

    require(['magento_plugin', 'addressfinder', 'domReady!'], function (MagentoPlugin, AddressFinder) {
        var widgetConfig = {"nzKey":"XXX","auKey":"XXX","nzWidgetOptions":null,"auWidgetOptions":null,"debug":false,"defaultCountry":"au"};
        var formsConfig = TypeError: Argument 1 passed to Amasty\RecurringPayments\Model\QuoteValidate::validateQuote() must implement interface Magento\Quote\Api\Data\CartInterface, null given, called in /var/www/html/bsc-magento2.4.-/codepool/vendor/amasty/module-recurring-payments-paypal/Model/Method/Paypal.php on line 63 and defined in /var/www/html/bsc-magento2.4.-/codepool/vendor/amasty/recurring-payments/Model/QuoteValidate.php:44
Stack trace:

getActivePaymentMethodCodes Exception on Checkout page - Magento 2.4.2

After upgrading Magento 2.4 to 2.4.2 the following exception occurs on /checkout/ page load which results in a blank page:

<script>
--
ย  | require(['magento_plugin', 'addressfinder', 'domReady!'], function (MagentoPlugin, AddressFinder) {
ย  | var widgetConfig = {"key":"*******************","options":{"address_params":{"au_paf":"1"}},"debug":true,"default_country":"au"};
ย  | var formsConfig = An error has happened during application run. See exception log for details.

Output in system.log:
[2021-03-06 04:03:36] main.CRITICAL: Error: Call to a member function getPayment() on null in /home/realbasi/madge/vendor/stripe/module-payments/Model/Method/Express.php:29

Stack trace:
#0 /home/realbasi/madge/vendor/magento/module-payment/Helper/Data.php(146): StripeIntegration\Payments\Model\Method\Express->isAvailable(NULL)
#1 /home/realbasi/madge/vendor/addressfinder/module-magento2/Observer/FormConfig/Frontend/AddCheckoutBillingAddress.php(132): Magento\Payment\Helper\Data->getStoreMethods()
#2 /home/realbasi/madge/vendor/addressfinder/module-magento2/Observer/FormConfig/Frontend/AddCheckoutBillingAddress.php(41): AddressFinder\AddressFinder\Observer\FormConfig\Frontend\AddCheckoutBillingAddress->getActivePaymentMethodCodes()
#3 /home/realbasi/madge/vendor/addressfinder/module-magento2/Observer/FormConfig/Base.php(52): AddressFinder\AddressFinder\Observer\FormConfig\Frontend\AddCheckoutBillingAddress->addForm(Object(Magento\Framework\Data\Collection\Interceptor))
#4 /home/realbasi/madge/vendor/magento/framework/Event/Invoker/InvokerDefault.php(88): AddressFinder\AddressFinder\Observer\FormConfig\Base->execute(Object(Magento\Framework\Event\Observer))
#5 /home/realbasi/madge/vendor/magento/framework/Event/Invoker/InvokerDefault.php(74): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(AddressFinder\AddressFinder\Observer\FormConfig\Frontend\AddCheckoutBillingAddress), Object(Magento\Framework\Event\Observer))
#6 /home/realbasi/madge/vendor/magento/framework/Event/Manager.php(66): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer))
#7 /home/realbasi/madge/generated/code/Magento/Framework/Event/Manager/Proxy.php(95): Magento\Framework\Event\Manager->dispatch('addressfinder_f...', Array)
#8 /home/realbasi/madge/vendor/addressfinder/module-magento2/Model/FormConfigProvider.php(75): Magento\Framework\Event\Manager\Proxy->dispatch('addressfinder_f...', Array)
#9 /home/realbasi/madge/vendor/addressfinder/module-magento2/Block/Plugin.php(59): AddressFinder\AddressFinder\Model\FormConfigProvider->get('addressfinder_f...')
#10 /home/realbasi/madge/var/view_preprocessed/pub/static/vendor/addressfinder/module-magento2/view/frontend/templates/plugin.phtml(4): AddressFinder\AddressFinder\Block\Plugin->getFormsConfig()
#11 /home/realbasi/madge/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/home/realbasi/...')

I note you have this on your todo list already so perhaps you're already aware of this issue - but seems you need to update the getActivePaymentMethodCodes() method in AddCheckoutBillingAddress observer to use the Api method instead. After testing with below code the exception no longer occurs and addressfinder works as expected.

    private function getActivePaymentMethodCodes(): array
    {
        $codes = [];

        // @todo Visit working around deprecated code

        $paymentApi = \Magento\Framework\App\ObjectManager::getInstance()
                ->get(\Magento\Payment\Api\PaymentMethodListInterface::class);
        $storeId = \Magento\Framework\App\ObjectManager::getInstance()
                ->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId();

         foreach ($paymentApi->getActiveList($storeId) as $method) {

            try {
                $codes[] = $method->getCode();
            } catch (LocalizedException $e) {
            }
        }

        return $codes;
    }

Result:

<script>
--
ย  | require(['magento_plugin', 'addressfinder', 'domReady!'], function (MagentoPlugin, AddressFinder) {
ย  | var widgetConfig = {"key":"********************","options":{"address_params":{"au_paf":"1"}},"debug":true,"default_country":"au"};
ย  | var formsConfig = [{"id":"frontend.checkout.billing.address.payflow_express","label":"Checkout Billing Address (payflow_express)","layoutSelectors":["li#payment","div[name=\"billingAddresspayflow_express.street.0\"]"],"countryIdentifier":"div[name=\"billingAddresspayflow_express.country_id\"] select[name=country_id]","searchIdentifier":"div[name=\"billingAddresspayflow_express.street.0\"] input[name=\"street[0]\"]","nz":{"countryValue":"NZ","elements":{"address1":"div[name=\"billingAddresspayflow_express.street.0\"] input[name=\"street[0]\"]","address2":"div[name=\"billingAddresspayflow_express.street.1\"] input[name=\"street[1]\"]","suburb":"div[name=\"billingAddresspayflow_express.street.2\"] input[name=\"street[2]\"]","city":"div[name=\"billingAddresspayflow_express.city\"] input[name=city]","region":"div[name=\"billingAddresspayflow_express.region\"] input[name=region]","postcode":"div[name=\"billingAddresspayflow_express.postcode\"] input[name=postcode]"},"regionMappings":null},"au":{"countryValue":"AU","elements":{"address1":"div[name=\"billingAddresspayflow_express.street.0\"] input[name=\"street[0]\"]","address2":"div[name=\"billingAddresspayflow_express.street.1\"] input[name=\"street[1]\"]","suburb":"div[name=\"billingAddresspayflow_express.city\"] input[name=city]","state":"div[name=\"billingAddresspayflow_express.region_id\"] select[name=region_id]","postcode":"div[name=\"billingAddresspayflow_express.postcode\"] input[name=postcode]"},"stateMappings":{"ACT":569,"NSW":570,"NT":576,"QLD":572,"SA":573,"TAS":574,"VIC":571,"WA":575}}},{"id":"frontend.checkout.billing.address.paypal_express_bml","label":"Checkout Billing Address (paypal_express_bml)","layoutSelectors":["li#payment","div[name=\"billingAddresspaypal_express_bml.street.0\"]"],"countryIdentifier":"div[name=\"billingAddresspaypal_express_bml.country_id\"] select[name=country_id]","searchIdentifier":"div[name=\"billingAddresspaypal_express_bml.street.0\"] input[name=\"street[0]\"]","nz":{"countryValue":"NZ","elements":{"address1":"div[name=\"billingAddresspaypal_express_bml.street.0\"] input[name=\"street[0]\"]","address2":"div[name=\"billingAddresspaypal_express_bml.street.1\"] input[name=\"street[1]\"]","suburb":"div[name=\"billingAddresspaypal_express_bml.street.2\"] input[name=\"street[2]\"]","city":"div[name=\"billingAddresspaypal_express_bml.city\"] input[name=city]","region":"div[name=\"billingAddresspaypal_express_bml.region\"] input[name=region]","postcode":"div[name=\"billingAddresspaypal_express_bml.postcode\"] input[name=postcode]"},"regionMappings":null},"au":{"countryValue":"AU","elements":{"address1":"div[name=\"billingAddresspaypal_express_bml.street.0\"] input[name=\"street[0]\"]","address2":"div[name=\"billingAddresspaypal_express_bml.street.1\"] input[name=\"street[1]\"]","suburb":"div[name=\"billingAddresspaypal_express_bml.city\"] input[name=city]","state":"div[name=\"billingAddresspaypal_express_bml.region_id\"] select[name=region_id]","postcode":"div[name=\"billingAddresspaypal_express_bml.postcode\"] input[name=postcode]"},"stateMappings":{"ACT":569,"NSW":570,"NT":576,"QLD":572,"SA":573,"TAS":574,"VIC":571,"WA":575}}},{"id":"frontend.checkout.billing.address.payflow_express_bml","label":"Checkout Billing Address (payflow_express_bml)","layoutSelectors":["li#payment","div[name=\"billingAddresspayflow_express_bml.street.0\"]"],"countryIdentifier":"div[name=\"billingAddresspayflow_express_bml.country_id\"] select[name=country_id]","searchIdentifier":"div[name=\"billingAddresspayflow_express_bml.street.0\"] input[name=\"street[0]\"]","nz":{"countryValue":"NZ","elements":{"address1":"div[name=\"billingAddresspayflow_express_bml.street.0\"] input[name=\"street[0]\"]","address2":"div[name=\"billingAddresspayflow_express_bml.street.1\"] input[name=\"street[1]\"]","suburb":"div[name=\"billingAddresspayflow_express_bml.street.2\"] input[name=\"street[2]\"]","city":"div[name=\"billingAddresspayflow_express_bml.city\"] input[name=city]","region":"div[name=\"billingAddresspayflow_express_bml.region\"] input[name=region]","postcode":"div[name=\"billingAddresspayflow_express_bml.postcode\"] input[name=postcode]"},"regionMappings":null},"au":{"countryValue":"AU","elements":{"address1":"div[name=\"billingAddresspayflow_express_bml.street.0\"] input[name=\"street[0]\"]","address2":"div[name=\"billingAddresspayflow_express_bml.street.1\"] input[name=\"street[1]\"]","suburb":"div[name=\"billingAddresspayflow_express_bml.city\"] input[name=city]","state":"div[name=\"billingAddresspayflow_express_bml.region_id\"] select[name=region_id]","postcode":"div[name=\"billingAddresspayflow_express_bml.postcode\"] input[name=postcode]"},"stateMappings":{"ACT":569,"NSW":570,"NT":576,"QLD":572,"SA":573,"TAS":574,"VIC":571,"WA":575}}},{"id":"frontend.checkout.billing.address.free","label":"Checkout Billing Address (free)","layoutSelectors":
... truncated... 

select2 breaks the search.

Steps to reproduce.

  1. Init select2 on all dropdowns by default (put some *.phtml "before body end" file with JS: $('form .control select').select2()).
  2. Go to the Checkout page
  3. Select NZ country and start typing address

Expected result:

  • AddressFinder shows some result

Actual result:

  • <ul class="af_list"> is empty

Magento 2 - updates to fix state mapping and mutiple payments

Testing issues:

  1. I couldn't get the updates to work on Magento v2.1. In the system.log this error is thrown:

Screen Shot 2019-12-10 at 1 08 48 PM

Seems like the problem is to do with the country variable:
$country = $this->countryInformationAcquirer->getCountryInfo($countryCode);
@bencorlett any ideas?

  1. RESOLVED: For Australian addresses, the suburb value is being populated into a different field. Normally, we add suburb values to the 'city' field, but now it is added to the 'street[2]' field. The image shows 'YAAPEET' in the street[2] field, and the city from a previous New Zealand address I searched remains in the city field.

Screen Shot 2019-12-10 at 12 19 09 PM

Magento refactoring

  • Update webpage tools to v1.8.1
  • Refactor the project structure
  • Plugin JavaScript Widget Config Injection

Add support for billing address for bank transfer payments

We have had a report of the addressfinder-magento plugin not working in a certain scenario.

This is the scenario:

  1. Using "one step checkout" plugin
  2. Selecting "I have a different billing address"
  3. Trying to enter the street address

Note: the widget attached to the shipping address field works as expected.

image

Website that demonstrates the problem: https://www.betterbatt.com.au/

There is a good thread of technical information here in Hubspot: https://app.hubspot.com/live-messages/20223507/inbox/1367525481#comment-editor

Fixing

In short - we need to support an additional form configuration to make this scenario work.

You can see the currently generated formsConfig on the BetterBatt checkout page here:

image

For the widget to work on BetterBatt (billing), we will need an additional formsConfig hash for frontend.checkout.billing.address.shared

Here is the field that our searchIdentifier is attempting to find:

image

The code which defines this data is here: https://github.com/AddressFinder/addressfinder-magento/blob/develop/Observer/FormConfig/Frontend/AddCheckoutBillingAddress.php#L54

This depends on the function getActivePaymentMethodCodes. It appears that the OneStepCheckout people are suggesting that this function should also return shared in its response.

https://github.com/AddressFinder/addressfinder-magento/blob/master/Observer/FormConfig/Frontend/AddCheckoutBillingAddress.php#L127

How can I configure this to be NZ only mode with use nearby locations and add custom JS?

Hello,

I do not have a Country select box on the checkout as the store only services one country NZ, the widget appears to be defaulting to AU.

This module is all minified so I can't easily debug any chance of releasing non minified?
As I would also like to add a custom JS handler to do something with the meta data x,y location.
selected by the user such as.

function onNZAddressSelected(selectedAddress, metaData) {
  console.log(metaData.x, metaData.y);

  // Probably a better way.
$(this.element).parent().parent().parent().parent().parent().find("input[name=af_x]").val(metaData.x);
$(this.element).parent().parent().parent().parent().parent().find("input[name=af_y]").val(metaData.y);
}

widget.nz.on('result:select', onNZAddressSelected);

I have done this before with an older version, of the widget which seems to have since disappeared from github.

Previous was: addressfinder/module-magento2 version 1.1.1

window.AddressFinder._magentoPlugin.widgetConfig shows an AU Key is configured.

Could you please point me in the right direction to make these kinds of configurations if possible?

Kind regards,

Fault with default country on checkout

In some scenarios, the widgetConfig.defaultCountry is not set - and this causes issues when the widget is activated.

image

I believe the root cause of the problem is this line: https://github.com/AddressFinder/addressfinder-magento/blob/develop/view/base/web/js/source/magento-plugin.js#L35

defaultCountry: this.widgetConfig.default_search_country

I think the default_search_country key is confined to PHP, and should not be used in JS/HTML. Here is the place where PHP configuration is prepared for conversion to JS - https://github.com/AddressFinder/addressfinder-magento/blob/develop/Model/WidgetConfigProvider.php#L98

This should be the last place that default_search_country is referred to. From this point onwards, it looks like default_country is the new key. I believe that default_country is translated into JS syntax as defaultCountry Not correct.

And I think that this block of PHP config is invected into the HTML here (note the json_encode function call): https://github.com/AddressFinder/addressfinder-magento/blob/develop/view/frontend/templates/plugin.phtml#L11

Summary

We have 3 different keys which are mis-matched, and need to be understood why - and perhaps fixed/aligned:

  • default_search_country
  • default_country
  • defaultCountry

There is an email trail of attempting to provide a workaround for this problem here: https://app.hubspot.com/live-messages/20223507/inbox/1481277347

The ultimate solution that got it going was change

file: view/frontend/web/js/magento-plugin.js
line: 148
from: defaultCountry: this.widgetConfig.default_search_country
to: defaultCountry: this.widgetConfig.default_country

State Mapping

Hey all :)

I can see that a recent update was aimed at selecting regions/states when they're presented as a dropdown. This code makes an assumption of the internal identifier for each state, IDs 569 through to 575. In a standard Magento installation where there are no additional regions/states are added are actually 512 through to 519. Irrespective of this, I don't think we can rely on the internal identifier for the most part:

Screen Shot 2019-09-04 at 2 00 11 pm

<select class="select" name="region_id" id="O2G8HJQ" aria-describedby="notice-O2G8HJQ" placeholder="">
    <option value="">Please select a region, state or province.</option>
    <option data-title="Australian Capital Territory" value="512">Australian Capital Territory</option>
    <option data-title="New South Wales" value="513">New South Wales</option>
    <option data-title="Northern Territory" value="514">Northern Territory</option>
    <option data-title="Queensland" value="515">Queensland</option>
    <option data-title="South Australia" value="516">South Australia</option>
    <option data-title="Tasmania" value="517">Tasmania</option>
    <option data-title="Victoria" value="518">Victoria</option>
    <option data-title="Western Australia" value="519">Western Australia</option>
</select>

In the Magento 1 extension, I introduced the concept of transformers. These are arbitrary and are used to transform a value returning from the AddressFinder API (e.g. New South Wales) into a value within Magento (e.g. 513, or 570, whatever it is in each installation).

We passed the transformer configuration through from server-side, by pulling out all regions/state mappings.

It might require a sizeable refactor to inject this configuration into the Magento 2 extension. Happy to explore this idea, have you got a preference on the way you'd like to attack it?

  • Ben.

Compatibility with Adobe Commerce 2.4.4

Trying to install the extension via composer with Adobe Commerce 2.4.4 and not able to download the package because of composer dependency on PHP version below 8. Using PHP8.1.

Do you have plans to update the extension?

Magento source maps

The Magento plugin code is currently all minified in the browser, which makes it difficult for anyone except us to debug it. This is not great for open source.

A good solution is to use sourcemaps. This is a special file that connects a minified/uglified version of an asset to the original authored version. You can set this as an option for webpack. There is no performance hit because sourcemaps don't get loaded unless you have dev tools open. This would make it easier for both us and other users to debug ๐ŸŽ‰

There are two steps

  1. Export the non-minified addressfinder-webpage-tools package by. This file can be minified by the plugins themselves.
  2. Add sourcemaps to the webpack config of each of the plugins. There is an example of this already in the WooCommerce plugin.

The changes themselves are small, but testing and deploying will take a while since we are changing the minification process of the webpage tools, and deploying to 3 different platforms

Improve readme for Magento 2 repo

Readme currently has instructions for deploying the Magento 2 plugin. These should be moved to a DEPLOYMENT.md file. The readme should contain helpful information about how to install the Magento 2 plugin, and the guidelines for open source contribution. These guidelines could become the template for the other plugins and would make it more likely for outside developers to submit pull requests

Dockerise Magento installation

Details

Add docker container to simplify maintenance as well as allowing switching Magento version easily.

Set up different localhost URLs for the different versions.

Completion criterias

  • We can easily run a docker container for different computers.
  • We can test different Magento versions by changing the URL in the browser.

Enable users to set a default country

Update to version v1.2.5

Currently we depend on the value of the country select box to set the widget active country. This means that the widget won't work if it is removed. In the WooCommerce plugin we allow users to set a default country for AddressFinder in the config options. We could do something like this for Magento.

To make this change we have to add another field to the Magento admin panel to get the default country.

However, this fix won't solve this issue: #21. This scenario is either

  1. The country field has been visually hidden from the page, but its value is set to Australia, and the customer wants to collect New Zealand addresses.
  2. Country element is removed from the page with javascript after AddressFinder has initialised, but it's value was set to Australia

The fix for this would be a change to the webpage tools. We could initialise the widget with the default country if one is defined, rather than the value of the country element. I'm not sure if we should do this, because in some scenarios the country element and the widget country could end up out of sync

Adjustments required for Magento v2.4 compatibility

The CEv2.4 has been released and the plugin.

The current version of the AddressFinder Magento 2 plugin is not compatible with v2.4.

Release notes: https://devdocs.magento.com/guides/v2.4/release-notes/release-notes-2-4-0-open-source.html

A customer has provided the following information regarding compatibility.

We have developing site on Magento 2.3.5. And using:
"addressfinder/module-magento2": "^1.5"
Now we need to update Magento to 2.4. And this module has errors with composer updating.
Need to add "magento/framework" v103 to the "require" section in "composer.json".

Requires PHP 7.4.9
Extension currently supports up to PHP 7.3.

Our current version is 1.7 and this is the one which we will update.

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.