Magento 2 developers usually try to choose extensions from a single creator so no conflicts arise between them. But what should you do if a conflict still arises where it shouldn’t? Today we will consider this situation as we have experienced it. We will show how to resolve Magento 2 extension conflict between two Amasty modules. Navigate using the list below:

Navigation

Suppose there’s a site on Magento 2. It should support the AJAX filtration and infinite scrolling on products listing using AJAX (henceforth referred to as Infinite Scroll).

Amasty Modules Chosen

We chose extensions from Amasty to implement both functionalities: Improved Layered Navigation (Amasty_Shopby) and Infinite Scroll (Amasty_Scroll). We chose these extensions from the same developer on the basis of minimizing conflicts between them, since they affect the same pages: product listings.

This block has a fixed position and lets users know how many pages of products were loaded. If the category or search result returns only one page, the block shouldn’t be shown.

If the aforementioned situation occurred when a filter was applied using AJAX (for example, if a customer wanted to browse only products that are the color black and the results fit on just one page), then this block remained in the browser window, which confused users.

This had to be fixed, and we set out analyzing the code of both modules. Both modules for calling and processing Ajax requests implement jQuery widgets. jQuery widgets are Javascript objects with Function() type. The modules are synchronized in the following way.

mage.amScrollScript widget from Amasty_Scroll has the following constructor:

As you can see, the _initProgressBar method generates the aforementioned block and is called from the _initialize() method. However, _initProgressBar will not be called if the number of pages is equal to 1. This is verified in the _validate() method. The code for deleting the block created when applying an Ajax filter from Amasty_Shopby was not provided in the mage.amScrollScript widget. Amasty must correct this mistake.

Solving Amasty Module Conflicts in Magento 2

Mixin should be used for customizing Magento 2 jQuery widgets without rewriting the original widgets. We will declare it in the requirejs-config.js module file.

If the number of pages is equal to 1, all blocks with the amscroll-navbar class will be deleted from the DOM page. But this mixin won’t work, since the widget always has the NULL value. This is because Amasty implemented the mage.amScrollScript widget based on jQuery standards, not Magento 2 standards. If the widget was implemented based on Magento 2 standards, it would return a self-pointer using:

return $.mage.amScrollScript;

This is not seen in the code of the mage.amScrollScript widget. But a solution to this problem does exist, and it looks as follows:

This alteration successfully deletes the block with the page number from the DOM page when it’s needed.

Summary

Now you know that it could be a situation when choosing some modules you try to set them up, and conflict could appear because of the incompatibility of modules. We hope that our tutorial on how to resolve Magento 2 extension conflict was helpful and you can implement changes to your Magento 2 store. However, if you still have questions on how to solve module conflict or other problems regarding Magento 2 Extension Development, we are here to help you. Write us at support@web4pro.net, and we will take care of your project!

Choose Our Team!

We are here to give you a hand and provide experts in web development and design. Tell us about your needs, ideas, and requirements – we are ready to take a task. Drop us a line, and it will be a perfect beginning for our partnership. Let’s get it started!

Custom Web Development

Frontend Development

Do you have a question?

Or do you want to talk and share some news? We’ll be glad to communicate with you and clarify all you need. Feel free to contact us anytime, and we’ll reply as soon as possible.
Let’s get acquainted and be partners. We’ll be happy to keep in touch with you.