1

I have one custom module which is working fine for M 2.1.7 in that module, I extend \Magento\Bundle\Model\Product\Type

in M 2.2.4 they added a new class for core file and passed to __construct

that is Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier is a new file or class in M.2.2.4 and used in \Magento\Bundle\Model\Product\Type::__construct

but in M 2.1.7 above class is not used and also not exists

what is the best approach so that my extended class should support both the version that is (M 2.1.7 and aM 2.2.4)?

Note:- I cannot use Plugin because I need to modify the logic in _prepareProduct() which is protected

  • Make 2 versions of your module? – Frank Groot May 18 '18 at 13:13
0

If you're not adding new/custom classes via DI(Dependency Injection) then probably you don't need the __construct() method in your child class otherwise you can use Object Manager directly for all the classes that you want to use and therefore you don't need to modify __construct(). This should work as far as I know. If anyone has a better solution, do let me know.

  • can you post the answer, that is i have 1 module which i installed in both version and should works fine with out any error, and also i am not adding any new class, in m 2.2.4 core module added new class but that class was not in M2.1.7 so it through error how to handle this – Pradeep Kumar May 18 '18 at 19:27
0

Change the construct method of your extended class to match the new construct method. The construct signature can change but it’s better if you keep the beginning of the signature the same and inject your extra classes before the $data array.

Make sure that when you call the parent::__construct(... you use the same order as in the construct of the parent object else you will get errors.

If you need an example let me know, I’ll add it.

Also, I suggest you use a context to inject multiple classes that way you can add/remove injections without having to change all subclasses.

  • How can i solve, Refused to apply style from MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled Uncaught TypeError: Unable to process binding "css: function(){return { empty:cart().summary_count == 0} }" Message: cart is not a function at css (eval at createBindingsStringEvaluator (knockout.js:2624), while upgrading magento ver 2.0.0 to 2.1.7 @ magento.stackexchange.com/q/225412/57334 – zus May 18 '18 at 12:24
  • not sure I understand your comment, this looks like another issue. You should open a new question with this. – drew7721 May 18 '18 at 13:08
  • please add the your solution , but your solution should work fine with out any error in both version, that is i have 1 module which i installed in both version and should works fine – Pradeep Kumar May 18 '18 at 19:26
  • Paste your class, with the ‘__construct’ method, not the other methods and I’ll try to add the solution today. – drew7721 May 22 '18 at 12:49
0

I would suggest best solution is to version your module and use composer to pull in the appropriate version for the current version of Magento.

Alternatively if you can get away with not overriding the constructor then it shouldn't be an issue anymore. Obviously you may need to inject dependencies and the class constructor is the place to do that, so this might not really be acheivable. The other way to get your dependency would be to use the object manager directly outside of the constructor, this is generally not recommend but could be an option if your desperate.

  • tomorrow if we upgrade or any modification was doe we have to release in both right ? – Pradeep Kumar May 18 '18 at 19:22

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.