Sergey Bakotin
Sergey Bakotin

Reputation: 469

Is the possible to create plugin, that will support OpenCart 2.3 and 3.0 at the same time?

we have OpenCart Plugin, that support only version 3.0. We have task to add support to previos version of OpenCart 2.3. There is any way how to do it in one plugin? Or do we need create plugin for each version?

Upvotes: 0

Views: 74

Answers (2)

Nancy
Nancy

Reputation: 540

Yes, there are ways to do this. I think it's a huge pain though to maintain fully, and it may cause you a huge support headache. It will require extra files, such as files with code to detect appropriate version of OC first and then necessary functions within those files to point to the various the specific-version folder structures with the appropriate version files. You'll have to then account for the fact that you are making people carry two sets of folders/file structures in their opencart directory when they only need to use one set for the appropriate version for the plugin to be run on. As an example, the marketplace and extension folders are different between both the versions you are mentioning. These are some things to consider.

You'd have to set a global variable of somewhere of some sort to detect and store the OC version first, something along the lines of:

global $oc_version;
$oc_version = (int)str_replace('.','',VERSION);

Then you would have a whole bunch of functions telling oc what to do with your module depending on the oc version detected, such as specifying the path for where to run the module folder from and to run twig or tpl. Something along the lines of:

if ($data['oc_version'] = 2300) 
 // Do Stuff
} elsif ($data['oc_version'] = 3000)
 // Do other stuff
}

However, the issue you'll encounter here with my examples is that if the version someone is using is let's say 3.0.2.0 (and not 3.0) and there are no changes that actually affect your module, then trying to go based on detecting the OC version won't work. You'd have to change your operators, put more thought, etc. Hence, you'll have to keep re-modifying parts of the same code frequently with any minor patch/version release. I don't see how it's saving you any more work going this route.

Upvotes: 3

K. B.
K. B.

Reputation: 1430

theoretically possible using " https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=31589 " and with small modifications in controller files. But I prefer convert tpl to twig.

Upvotes: 0

Related Questions