diff --git a/README.md b/README.md index a0ae6d6..b6ecd8b 100644 --- a/README.md +++ b/README.md @@ -1,134 +1,139 @@ -

- - - -

+![Logo](github.png) -

Plugin Skeleton

+![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/StudioWaaz/SyliusTntPlugin/build.yml?style=for-the-badge) -

Skeleton for starting Sylius plugins.

+# WaazSyliusTntPlugin -Testing commands -APP_ENV=test symfony php vendor/bin/behat -- [x] translations -- [x] renaming cancel +This plugin allows you to generate shipping labels for TNT carrier. -- [ ] label format -- [ ] dropoff stuff -- [x] configuration default values -- [x] configuration for using g/kg (g by default) -- [ ] data-tnt-select-classes -- [x] behat js -- [ ] complete phpspec -- [ ] README -## Documentation +## Features -For a comprehensive guide on Sylius Plugins development please go to Sylius documentation, -there you will find the Plugin Development Guide, that is full of examples. +- Shipping label export +- Check that the postal code and city match for TNT : for this feature, if the country chosen is 'FR' then the city field becomes a select with city proposals from the tnt webservice -## Quickstart Installation -1. Run `composer create-project sylius/plugin-skeleton ProjectName`. +## Installation + +**Prerequisite**: you must first configure/install the `bitbag/shipping-export-plugin` + +Install plugin with composer + +```bash +composer require waaz/sylius-tnt-plugin +``` +Add plugin dependencies to your `config/bundles.php` file: + +```php +return [ + ... + + Waaz\SyliusTntPlugin\WaazSyliusTntPlugin::class => ['all' => true], +]; +``` + +Add route in your `config/routes/sylius_shop.yaml` file: +```yaml +... +waaz_tnt_shop: + resource: "@WaazSyliusTntPlugin/Resources/config/routing/shop_tnt.yaml" +``` + +Add parameter validation_groups in your `config/services.yaml` file: +```yaml +parameters: + ... + sylius.form.type.checkout_address.validation_groups: ['sylius', 'tnt_address'] +``` + +Run assets install command : `bin/console assets:install` + +Add plugin asset in `templates/bundles/SyliusShopBundle/_scripts.html.twig` file +```twig +{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/shop/js/app.js'} %} +{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/waazsyliustntplugin/js/tnt-city.js'} %} +``` + +## Configuration +You can configure this plugin by creating a file `config/packages/waaz_sylius_tnt_plugin`: +```yml +waaz_sylius_tnt: + username: 'login' # Enter your tnt username here. You should use an environment variable like `%env(TNT_PASSWORD)%` + password: 'password' # Same for password + sandbox: true # Sandbox mode + weightUnit: 'g' # 'g' or 'kg'. Weight unit you use in your shop + citySelectClasses: '' # Classes you want to add to city select field + +``` -2. From the plugin skeleton root directory, run the following commands: - ```bash - $ (cd tests/Application && yarn install) - $ (cd tests/Application && yarn build) - $ (cd tests/Application && APP_ENV=test bin/console assets:install public) - $ (cd tests/Application && APP_ENV=test bin/console doctrine:database:create) - $ (cd tests/Application && APP_ENV=test bin/console doctrine:schema:create) - ``` +## Running Tests -To be able to setup a plugin's database, remember to configure you database credentials in `tests/Application/.env` and `tests/Application/.env.test`. +- PHPSpec -## Usage +```bash +vendor/bin/phpspec run +``` -### Running plugin tests +- Behat (non-JS scenarios) - - PHPUnit +```bash +vendor/bin/behat --strict --tags="~@javascript" +``` - ```bash - vendor/bin/phpunit - ``` +- Behat (JS scenarios) - - PHPSpec + 1. [Install Symfony CLI command](https://symfony.com/download). + + 2. Start Headless Chrome: ```bash - vendor/bin/phpspec run + google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1 ``` - - Behat (non-JS scenarios) + 3. Install SSL certificates (only once needed) and run test application's webserver on `127.0.0.1:8080`: ```bash - vendor/bin/behat --strict --tags="~@javascript" + symfony server:ca:install + APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon ``` - - Behat (JS scenarios) - - 1. [Install Symfony CLI command](https://symfony.com/download). - - 2. Start Headless Chrome: - - ```bash - google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1 - ``` - - 3. Install SSL certificates (only once needed) and run test application's webserver on `127.0.0.1:8080`: - - ```bash - symfony server:ca:install - APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon - ``` - 4. Run Behat: - - ```bash - vendor/bin/behat --strict --tags="@javascript" - ``` - - - Static Analysis - - - Psalm - - ```bash - vendor/bin/psalm - ``` - - - PHPStan - - ```bash - vendor/bin/phpstan analyse -c phpstan.neon -l max src/ - ``` - - Coding Standard - ```bash - vendor/bin/ecs check src + vendor/bin/behat --strict --tags="@javascript" ``` -### Opening Sylius with your plugin - -- Using `test` environment: +- Psalm ```bash - (cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load) - (cd tests/Application && APP_ENV=test bin/console server:run -d public) + vendor/bin/psalm ``` -- Using `dev` environment: +- PHPStan - ```bash - (cd tests/Application && APP_ENV=dev bin/console sylius:fixtures:load) - (cd tests/Application && APP_ENV=dev bin/console server:run -d public) - ``` +```bash +vendor/bin/phpstan analyse -c phpstan.neon -l max src/ +``` + +- Coding Standard + +```bash +vendor/bin/ecs check src +``` + +## Roadmap + +- Pickup point provider (with [setono/sylius-pickup-point-plugin](https://github.com/Setono/SyliusPickupPointPlugin)) +- Manage pickup point expedition (export shipping) + + +## Author + +- [@ehibes](https://www.github.com/ehibes) for [Studio Waaz](https://www.studiowaaz.com) +## License +This plugin's source code is completely free and released under the terms of the MIT license. -Install steps : -config plugin -routing => -config => -sylius.form.type.checkout_address.validation_groups: ['sylius', 'tnt_address'] \ No newline at end of file diff --git a/composer.json b/composer.json index 3b5bc3c..04b92e5 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,11 @@ "description": "This TNT plugin enables you to easily print shipping labels and show available pickup locations for customers to choose from.", "keywords": [ "sylius", - "sylius-plugin" + "sylius-plugin", + "tnt", + "shipping", + "labels", + "pickup" ], "license": "MIT", "require": { diff --git a/github.png b/github.png new file mode 100644 index 0000000..60284d9 Binary files /dev/null and b/github.png differ diff --git a/src/Api/Client.php b/src/Api/Client.php index dab0c85..adfa581 100644 --- a/src/Api/Client.php +++ b/src/Api/Client.php @@ -150,6 +150,7 @@ private function createExpeditionRequest(Sender $sender, Receiver $receiver, Par $expeditionRequest->setSender($sender); $expeditionRequest->setReceiver($receiver); $expeditionRequest->setParcelsRequest([$parcelRequest]); + $expeditionRequest->setLabelFormat($this->shippingGateway->getConfigValue('label_format')); return $expeditionRequest; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 22398f4..829b142 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -42,6 +42,9 @@ protected function addGlobalSection(ArrayNodeDefinition $node): void ->values(['kg', 'g']) ->defaultValue('g') ->end() + ->scalarNode('citySelectClasses') + ->defaultValue('form-control') + ->end() ->end() ; } diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index fc1407f..8b937a0 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -45,7 +45,6 @@ Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], - Waaz\SyliusTntPlugin\WaazSyliusTntPlugin::class => ['all' => true], Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],