1

Working With Magento 2.0.X After successfully overriding vendor/magento/module-checkout/view/frontend/web/template/minicart/content.html in my extension, its giving me error in my browser console

i.e TypeError: getCartParam is not a function.

And after some RND, I have found solution to replace getCartParam to cart and its working fine.

But when I test my extension in M2.1.X it gives me the error

i.e TypeError: cart is not a function

And then I revert back cart to getCartParam and it's working.

So, I have to develop two different extensions for M2.0.X or M2.1.X to achieve compatibility?

Is their any code difference between M2.0.X and M2.1.X?

Why this is happening?

1

So, I have to develop two different extension for M2.0.x or M2.1.x for achieving compatibility?

Is their any code difference between M2.0.X and M2.1.X?

Short answer: Yes and yes a lot.

Long answer (quoting Vinai who gave me a great explanation about it recently):

Disclaimer: this reflects an understanding of things (which might be incomplete)

When developping a module for Magento 2, you need to add composer dependencies on the module your module depends on. In your case, one of this dependency is the magento/module-checkout.

The dependency should be an exact version if you use methods/constants/classes without @api and on the major version if you only use methods with @api.

If a module uses anything non @api (a class name, a method, a constant in a non @api class...) the module should depend on the exact version of the dependency.

For example for Magento 2.1.2:

"require": {"magento/module-checkout":"100.1.2"}

If a module only uses something marked with @api from a module, it is enough to depend on the major version only.

For example:

"require": {"magento/module-checkout":"^100.1.2"}

If a module uses observers or JS UI components, then a dependency on the minor version should be added:

For example:

"require": {"magento/module-checkout":"100.1.*"}

So as an extension developer, here are the steps to take after a Magento upgrade:

  1. upgrade Magento (this might require allowing the new version in the module's composer json)
  2. run the tests you wrote for your module
  3. if they pass, publish a new version of the module with the updated dependency. Now customers using the module are able to upgrade Magento
  4. if they don't pass, fix the issue and goto 2

Ideally, IF (big if) everybody adds the proper dependencies, an installation cannot be upgraded before all modules are compatible with the new version.

This process won't be as simple as it sounds. In theory, extension vendors would use the develop branch / beta / RC versions to run their module tests before a release and make that phase shorter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.