oxipay / oxipay-magento-2.x

GNU General Public License v3.0
7 stars 6 forks source link

Installation using Composer #48

Open sam-flexi opened 7 years ago

sam-flexi commented 7 years ago

Update: Issue has been updated with additional information from Dan on the changes they had to make to the original composer.json file

Below is feedback from Iugo on how plugin can be installed using Composer.


Hi again Sam,

Just some quick notes re the Composer side of things for Magento 2 modules.

Composer packages are usually hosted through packagist, but Composer does support adding github/bitbucket repositories and installing packages from there too.

Here's a rough breakdown of commands I might type to install a Magento 2 module via Composer:

cd MAGENTO_ROOT composer config repositories.some-vender-some-module vcs https://github.com/some-vender/some-module composer require some-vendor/some-module ~1.0.6 ./bin/magento module:enable SomeVendor_SomeModule ./bin/magento setup:upgrade ./bin/magento cache:flush && ./bin/magento setup:static-content:deploy

For a Composer package, typically the root of the package is where composer.json and all files at that level are located.

There are a few ways versions can be tracked and associated, but usually this is done with git tags. A tag usually matches semver format, so when someone specifies a version with composer it will grab the git commit which matches that tag.

Semver format is useful, because then you can specify versions like "~1.0.6", which will use the latest version of the package which is equal to or greater than 1.0.6, but less than and not equal to 1.1.0.

It's a pretty broad topic, but updating the OxipayPaymentGateway git repo to work for composer wouldn't be too challenging. Might be something like: • everything in Oxipay/OxipayPaymentGateway would be moved to the root of the repo • Oxipay/OxipayPaymentGateway would be deleted. • release tags would start using semver format (instead of vXX.XX.XX, eg v0.0.14)

We're using this approach for all our custom modules for this project and it works quite nicely for updating production environments.

For people that would download the .zip and manually install, you may need to create the relevant subfolders inside that zip if you decide to do all this.


Changes to composer.json

Here is the original composer.json file:

{ "name": "oxipay/module-oxipay-payment-gateway", "description": "Oxipay Payment Gateway", "require": { "magento/module-sales": "100.0.", "magento/module-checkout": "100.0.", "magento/module-payment": "100.0.", "magento/framework": "100.0.", "magento/magento-composer-installer": "100.0.*" }, "type": "magento2-module", "version": "100.0.3", "license": [ "OSL-3.0", "AFL-3.0" ], "autoload": { "files": [ "registration.php" ], "psr-4": { "Oxipay\OxipayPaymentGateway\": "" } } }

Here is the version I'm using locally:

{ "name": "oxipay/module-oxipay-payment-gateway", "description": "Oxipay Payment Gateway", "require": { "magento/module-sales": "100.1.", "magento/module-checkout": "100.1.", "magento/module-payment": "100.1.", "magento/framework": "100.1." }, "type": "magento2-module", "autoload": { "files": [ "registration.php" ], "psr-4": { "Oxipay\OxipayPaymentGateway\": "" } } }

Summary of the important changes I made: • Remove dependency on magento/magento-composer-installer • Bump all other Magento dependencies up to 100.1. (this is Magento 2.1, 100.0. is Magneto 2.0) • Remove the version property - this is not mandatory, but we track our module versions with git tags The other required change was to place all the files contained in the folder Oxipay/OxipayPaymentGateway into the root of the repository.

This was the bare minimum to get it to install via Composer in our stack.

You would need to consider carefully what the Magento dependencies would be. If the plugin has been tested and confirmed working with Magento 2.0 and 2.1, you might be able to use values similar to the following: "require": { "magento/module-sales": ">=100.0 <100.2", "magento/module-checkout": ">=100.0 <100.2", "magento/module-payment": ">=100.0 <100.2", "magento/framework": ">=100.0 <100.2" },

nntoan commented 5 years ago

Please make it compatible with Magento 2.3.x and PHP 7.2 too.