11

It would be very convenient to include multiple versions of code in a composer'd module and have composer work out which version to deploy, based on the Magento version of the installation target.

For example, for Magento > 1.7, use the system.xml which includes tooltip, nested group and other modern features but for older versions of Magento, use a stripped-down version of the file which doesn't include those (breaking) declarations.

This approach could work for numerous other files in a standard module structure too.

The options for composer deployment are map, modman or package.xml AFAIK, none of which have any intelligence regarding the target system. The package.xml option is very unlikely to change but map could...

It seems to me that there would be a lot of extension developers that would benefit from the graceful degradation approach. Has anyone found a work-around for this?

1 Answer 1

8

I don't have a workaround and it wasn't an issue for me yet, but I have a proposal that could work:

  1. You need to maintain separate version branches to target different Magento versions. Deploying different files in the same version depending on some composer magic is not going to work well. So your extesion could have a 1.x branch for compatibility with older Magento versions (for example up to 1.6) and a 2.x branch for more modern versions. Add version tags accordingly. Of course you can maintain as many branches as you want and write the best code for each Magento version but IMHO this is not worth the effort and one "modern" and one "legacy" branch should suffice. It's up to you, how far you want to be backwards compatible with the "modern" branch, it can even be just the latest minor version.
  2. Add a requirement for Magento like this:

    "require": {
        "magento/magento-ce": "1.4-1.7"
    }
    

    and

    "require": {
        "magento/magento-ce": ">=1.8"
    }
    
  3. Now comes the downside, the part where you don't have full influence anymore: There is no official magento/magento-ce package, so the users of your extension will probably install Magento from a community managed mirror like https://github.com/firegento/magento-ce or from their own repository. These must replace the "virtual" magento/magento-ce package of the same version (there is a placeholder self.version, so that you don't need to adjust the composer.json for each version update):

    "replace": {
        "magento/magento-ce": "self.version"
    }
    

This will only work well if the convention above gets widely accepted and only for users who actually install Magento itself via composer dependency, which probably is not the majority.

So a more realistic approach is to just follow step 1 and advise your users to require a different branch / differnt major version, if they run a Magento version older than 1.x.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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