diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..de16bc5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.bat] +end_of_line = crlf diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..545afb5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,35 @@ +# Define the line ending behavior of the different file extensions +# Set the default behavior, in case people don't have core.autocrlf set. +* text text=auto eol=lf +*.php diff=php + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary +*.gif binary +*.jpeg binary +*.zip binary +*.phar binary +*.ttf binary +*.woff binary +*.woff2 binary +*.eot binary +*.ico binary +*.mo binary +*.pdf binary +*.xsd binary +*.exe binary + +# Remove files for archives generated using `git archive` +architecture-baseline.json export-ignore +dependency.json export-ignore +phpstan.json export-ignore +phpstan.neon export-ignore +psalm-report.json export-ignore linguist-generated=true +tooling.yml export-ignore +.coveralls.yml export-ignore +.travis.yml export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.github/ export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4c974e2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: CI + +on: + pull_request: + push: + branches: + - master + workflow_dispatch: + +jobs: + validation: + name: "Validation" + runs-on: ubuntu-18.04 + strategy: + fail-fast: false + matrix: + include: + - php: '7.4' + + env: + APPLICATION_ENV: devtest + APPLICATION_STORE: DE + PROJECT: computop-shipment + + steps: + - uses: actions/checkout@v2 + + - name: Configure sysctl limits + run: | + sudo swapoff -a + sudo sysctl -w vm.swappiness=1 + sudo sysctl -w fs.file-max=262144 + sudo sysctl -w vm.max_map_count=262144 + - name: Composer get cache directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Composer cache + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Composer validate + run: composer validate + + - name: Composer install + run: | + composer --version + composer install + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, intl + tools: composer:v2 + + - name: Run CodeStyle checks + run: composer cs-check + + - name: PHPStan setup + run: composer stan-setup + + - name: Run PHPStan + run: composer stan diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..556a403 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# IDEs +/.idea +/.project +/nbproject +/.buildpath +/.settings +*.sublime-* +*.AppleDouble +*.AppleDB +*.AppleDesktop +/vendor/ +composer.lock +composer.phar +phpunit.phar diff --git a/.license b/.license new file mode 100644 index 0000000..cf29a25 --- /dev/null +++ b/.license @@ -0,0 +1,4 @@ +/** + * MIT License + * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. + */ diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..fd9a87d --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,24 @@ +build: + environment: + php: '7.4' + + tests: + override: + - true # disable test execution on scrutinizer + + nodes: + analysis: + tests: + override: + - php-scrutinizer-run + +checks: + php: + code_rating: true + +filter: + excluded_paths: + - config/* + - tests/* + - src/Generated/* + - src/Pyz/* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..73dcc7b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016-present Spryker Systems GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 49ff36a..85d0860 100644 --- a/README.md +++ b/README.md @@ -1 +1,20 @@ -# computop-shipment +# ComputopShipment Module + +[![CI](https://github.com/spryker-eco/computop-shipment/actions/workflows/ci.yml/badge.svg)](https://github.com/spryker-eco/computop-shipment/actions/workflows/ci.yml) +[![Latest Stable Version](https://poser.pugx.org/spryker-eco/computop-shipment/v/stable.svg)](https://packagist.org/packages/spryker-eco/computop-shipment) +[![License](https://img.shields.io/github/license/spryker-eco/computop-shipment.svg?b=master)](https://github.com/spryker-eco/computop-shipment) + +[![CI](https://scrutinizer-ci.com/g/spryker-eco/computop-shipment/badges/build.png?b=master)](https://scrutinizer-ci.com/g/spryker-eco/computop-shipment/build-status/master) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg)](https://php.net/) + +ComputopShipment module provides a connection betweeen Computop and Shipment modules. + +## Installation + +``` +composer require spryker-eco/computop-shipment +``` + +## Documentation + +[Documentation](https://documentation.spryker.com/industry_partners/payment/computop/computop.html) diff --git a/architecture-baseline.json b/architecture-baseline.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/architecture-baseline.json @@ -0,0 +1 @@ +[] diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 0000000..ab9cf57 --- /dev/null +++ b/codeception.yml @@ -0,0 +1,21 @@ +namespace: ComputopShipment + +include: + - tests/SprykerEcoTest/Zed/ComputopShipment + +paths: + tests: tests + support: . + log: tests/_output + data: tests/_data + envs: tests/_envs + +settings: + suite_class: \PHPUnit_Framework_TestSuite + colors: true + memory_limit: 1024M + log: true + +coverage: + enabled: true + whitelist: { include: ['src/*'] } diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2593b36 --- /dev/null +++ b/composer.json @@ -0,0 +1,58 @@ +{ + "name": "spryker-eco/computop-shipment", + "type": "library", + "description": "ComputopShipment module", + "license": "MIT", + "require": { + "php": ">=7.4", + "spryker-eco/computop-extension": "^1.0.0", + "spryker/kernel": "^3.30.0", + "spryker/shipment": "^8.0.0", + "spryker/zed-request": "^3.0.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12", + "spryker/code-sniffer": "^0.16", + "spryker/propel": "^3.0.0", + "spryker/quote": "^2.0.0", + "spryker/store": "^1.0.0", + "spryker/testify": "^3.0.0" + }, + "suggest": { + "spryker/quote": "If you want to use DefaultShippingMethodQuoteTransferExpanderPlugin. Minimum required version 1.2.0" + }, + "autoload": { + "psr-4": { + "SprykerEco\\": "src/SprykerEco/" + } + }, + "autoload-dev": { + "psr-4": { + "SprykerEcoTest\\": "tests/SprykerEcoTest/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "cs-check": "phpcs -p -s --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/ tests/", + "cs-fix": "phpcbf -p --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/ tests/", + "stan": "phpstan analyse -c phpstan.neon -l 8 src/", + "stan-setup": "cp composer.json composer.backup && COMPOSER_MEMORY_LIMIT=-1 composer require --dev phpstan/phpstan:^0.12 && mv composer.backup composer.json" + }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/spryker-eco/computop-extension" + } + ], + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "config": { + "preferred-install": "dist", + "sort-packages": true, + "process-timeout": 600 + } +} diff --git a/config/config.dist.php b/config/config.dist.php new file mode 100644 index 0000000..6a5415e --- /dev/null +++ b/config/config.dist.php @@ -0,0 +1,8 @@ + variable ", + "file_name": "vendor/spryker-eco/computop-shipment/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteDefaultShipmentExpander.php", + "snippet": " if ($quoteTransfer->getItems()->count() === 0 || $this->isQuoteHasShipment($quoteTransfer)) {", + "selected_text": "count", + "error_level": 3, + "shortcode": 113, + "other_references": null + }, + { + "severity": "info", + "line_from": 50, + "line_to": 50, + "type": "PossiblyNullReference", + "message": "Cannot call method getMethod on possibly null value", + "file_name": "vendor/spryker-eco/computop-shipment/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteDefaultShipmentExpander.php", + "snippet": " if ($itemTransfer->getShipment() !== null && $itemTransfer->getShipment()->getMethod() !== null) {", + "selected_text": "getMethod", + "error_level": 3, + "shortcode": 83, + "other_references": null + }, + { + "severity": "info", + "line_from": 89, + "line_to": 89, + "type": "InvalidScalarArgument", + "message": "Argument 1 of Generated\\Shared\\Transfer\\ShipmentTransfer::setShipmentSelection expects null|string, int|null provided", + "file_name": "vendor/spryker-eco/computop-shipment/src/SprykerEco/Zed/ComputopShipment/Business/QuoteShipmentExpander/QuoteDefaultShipmentExpander.php", + "snippet": " ->setShipmentSelection($shipmentMethodTransfer->getIdShipmentMethod())", + "selected_text": "$shipmentMethodTransfer->getIdShipmentMethod()", + "error_level": 4, + "shortcode": 12, + "other_references": null + } + ], + "deprecation": [] +} diff --git a/src/SprykerEco/Client/ComputopShipment/ComputopShipmentDependencyProvider.php b/src/SprykerEco/Client/ComputopShipment/ComputopShipmentDependencyProvider.php new file mode 100644 index 0000000..536106a --- /dev/null +++ b/src/SprykerEco/Client/ComputopShipment/ComputopShipmentDependencyProvider.php @@ -0,0 +1,48 @@ +addZedRequestClient($container); + + return $container; + } + + /** + * @param \Spryker\Client\Kernel\Container $container + * + * @return \Spryker\Client\Kernel\Container + */ + protected function addZedRequestClient(Container $container): Container + { + $container->set(static::CLIENT_ZED_REQUEST, function (Container $container) { + return new ComputopShipmentToZedRequestClientBridge($container->getLocator()->zedRequest()->client()); + }); + + return $container; + } +} diff --git a/src/SprykerEco/Client/ComputopShipment/ComputopShipmentFactory.php b/src/SprykerEco/Client/ComputopShipment/ComputopShipmentFactory.php new file mode 100644 index 0000000..44dbdb7 --- /dev/null +++ b/src/SprykerEco/Client/ComputopShipment/ComputopShipmentFactory.php @@ -0,0 +1,42 @@ +getZedRequestClient()); + } + + /** + * @return \SprykerEco\Client\ComputopShipment\Dependency\Client\ComputopShipmentToZedRequestClientInterface + */ + public function getZedRequestClient(): ComputopShipmentToZedRequestClientInterface + { + return $this->getProvidedDependency(ComputopShipmentDependencyProvider::CLIENT_ZED_REQUEST); + } + + /** + * @return \SprykerEco\Client\ComputopShipment\QuoteShipmentExpander\QuoteShipmentExpanderInterface + */ + public function createQuoteShipmentExpander(): QuoteShipmentExpanderInterface + { + return new QuoteDefaultShipmentExpander($this->createZedStub()); + } +} diff --git a/src/SprykerEco/Client/ComputopShipment/Dependency/Client/ComputopShipmentToZedRequestClientBridge.php b/src/SprykerEco/Client/ComputopShipment/Dependency/Client/ComputopShipmentToZedRequestClientBridge.php new file mode 100644 index 0000000..329d334 --- /dev/null +++ b/src/SprykerEco/Client/ComputopShipment/Dependency/Client/ComputopShipmentToZedRequestClientBridge.php @@ -0,0 +1,38 @@ +zedRequestClient = $zedRequestClient; + } + + /** + * @param string $url + * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $object + * @param array|null $requestOptions + * + * @return \Spryker\Shared\Kernel\Transfer\TransferInterface + */ + public function call($url, TransferInterface $object, $requestOptions = null) + { + return $this->zedRequestClient->call($url, $object, $requestOptions); + } +} diff --git a/src/SprykerEco/Client/ComputopShipment/Dependency/Client/ComputopShipmentToZedRequestClientInterface.php b/src/SprykerEco/Client/ComputopShipment/Dependency/Client/ComputopShipmentToZedRequestClientInterface.php new file mode 100644 index 0000000..a0c2605 --- /dev/null +++ b/src/SprykerEco/Client/ComputopShipment/Dependency/Client/ComputopShipmentToZedRequestClientInterface.php @@ -0,0 +1,22 @@ +getFactory()->createQuoteShipmentExpander()->expand($quoteTransfer); + } +} diff --git a/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteDefaultShipmentExpander.php b/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteDefaultShipmentExpander.php new file mode 100644 index 0000000..99b1169 --- /dev/null +++ b/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteDefaultShipmentExpander.php @@ -0,0 +1,57 @@ +computopShipmentStub = $computopShipmentStub; + } + + /** + * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer + * + * @return \Generated\Shared\Transfer\QuoteTransfer + */ + public function expand(QuoteTransfer $quoteTransfer): QuoteTransfer + { + if ($quoteTransfer->getItems()->count() === 0 || $this->isQuoteHasShipment($quoteTransfer)) { + return $quoteTransfer; + } + + return $this->computopShipmentStub->expandQuoteWithDefaultShippingMethod($quoteTransfer); + } + + /** + * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer + * + * @return bool + */ + protected function isQuoteHasShipment(QuoteTransfer $quoteTransfer): bool + { + foreach ($quoteTransfer->getItems() as $itemTransfer) { + if ($itemTransfer->getShipment() !== null && $itemTransfer->getShipment()->getMethod() !== null) { + return true; + } + } + + return false; + } +} diff --git a/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteShipmentExpanderInterface.php b/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteShipmentExpanderInterface.php new file mode 100644 index 0000000..2365aa9 --- /dev/null +++ b/src/SprykerEco/Client/ComputopShipment/QuoteShipmentExpander/QuoteShipmentExpanderInterface.php @@ -0,0 +1,20 @@ +zedRequestClient = $zedRequestClient; + } + + /** + * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer + * + * @return \Generated\Shared\Transfer\QuoteTransfer + */ + public function expandQuoteWithDefaultShippingMethod(QuoteTransfer $quoteTransfer): QuoteTransfer + { + /** @var \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer */ + $quoteTransfer = $this->zedRequestClient->call('/computop-shipment/gateway/expand-quote-with-default-shipping-method', $quoteTransfer); + + return $quoteTransfer; + } +} diff --git a/src/SprykerEco/Client/ComputopShipment/Zed/ComputopShipmentStubInterface.php b/src/SprykerEco/Client/ComputopShipment/Zed/ComputopShipmentStubInterface.php new file mode 100644 index 0000000..6a27a03 --- /dev/null +++ b/src/SprykerEco/Client/ComputopShipment/Zed/ComputopShipmentStubInterface.php @@ -0,0 +1,20 @@ +addShipmentClient($container); + + return $container; + } + + /** + * @param \Spryker\Yves\Kernel\Container $container + * + * @return \Spryker\Yves\Kernel\Container + */ + protected function addShipmentClient(Container $container): Container + { + $container->set(static::CLIENT_SHIPMENT, function (Container $container) { + return new ComputopShipmentToShipmentClientBridge($container->getLocator()->shipment()->client()); + }); + + return $container; + } +} diff --git a/src/SprykerEco/Yves/ComputopShipment/ComputopShipmentFactory.php b/src/SprykerEco/Yves/ComputopShipment/ComputopShipmentFactory.php new file mode 100644 index 0000000..edebdcb --- /dev/null +++ b/src/SprykerEco/Yves/ComputopShipment/ComputopShipmentFactory.php @@ -0,0 +1,22 @@ +getProvidedDependency(ComputopShipmentDependencyProvider::CLIENT_SHIPMENT); + } +} diff --git a/src/SprykerEco/Yves/ComputopShipment/Dependency/ComputopShipmentToShipmentClientBridge.php b/src/SprykerEco/Yves/ComputopShipment/Dependency/ComputopShipmentToShipmentClientBridge.php new file mode 100644 index 0000000..426e3fa --- /dev/null +++ b/src/SprykerEco/Yves/ComputopShipment/Dependency/ComputopShipmentToShipmentClientBridge.php @@ -0,0 +1,36 @@ +shipmentClient = $shipmentClient; + } + + /** + * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer + * + * @return \Generated\Shared\Transfer\QuoteTransfer + */ + public function expandQuoteWithShipmentGroups(QuoteTransfer $quoteTransfer): QuoteTransfer + { + return $this->shipmentClient->expandQuoteWithShipmentGroups($quoteTransfer); + } +} diff --git a/src/SprykerEco/Yves/ComputopShipment/Dependency/ComputopShipmentToShipmentClientInterface.php b/src/SprykerEco/Yves/ComputopShipment/Dependency/ComputopShipmentToShipmentClientInterface.php new file mode 100644 index 0000000..2dd8de3 --- /dev/null +++ b/src/SprykerEco/Yves/ComputopShipment/Dependency/ComputopShipmentToShipmentClientInterface.php @@ -0,0 +1,20 @@ +getFactory()->getShipmentClient()->expandQuoteWithShipmentGroups($quoteTransfer); + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentBusinessFactory.php b/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentBusinessFactory.php new file mode 100644 index 0000000..c0141f5 --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentBusinessFactory.php @@ -0,0 +1,39 @@ +getConfig(), + $this->getShipmentFacade() + ); + } + + /** + * @return \SprykerEco\Zed\ComputopShipment\Dependency\ComputopShipmentToShipmentFacadeInterface + */ + public function getShipmentFacade(): ComputopShipmentToShipmentFacadeInterface + { + return $this->getProvidedDependency(ComputopShipmentDependencyProvider::FACADE_SHIPMENT); + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentFacade.php b/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentFacade.php new file mode 100644 index 0000000..f28a61b --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentFacade.php @@ -0,0 +1,33 @@ +getFactory() + ->createQuoteDefaultShipmentExpander() + ->expand($quoteTransfer); + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentFacadeInterface.php b/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentFacadeInterface.php new file mode 100644 index 0000000..e94ef3a --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/Business/ComputopShipmentFacadeInterface.php @@ -0,0 +1,26 @@ +computopShipmentConfig = $computopShipmentConfig; + $this->shipmentFacade = $shipmentFacade; + } + + /** + * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer + * + * @throws \SprykerEco\Zed\ComputopShipment\Business\Exception\ComputopDefaultShipmentException + * + * @return \Generated\Shared\Transfer\QuoteTransfer + */ + public function expand(QuoteTransfer $quoteTransfer): QuoteTransfer + { + $quoteTransfer->setDefaultShipmentSelected(true); + + $defaultShipmentMethodKey = $this->computopShipmentConfig->getDefaultShipmentMethodKey(); + $defaultShipmentMethodTransfer = $this->shipmentFacade->findShipmentMethodByKey($defaultShipmentMethodKey); + if ($defaultShipmentMethodTransfer === null || $defaultShipmentMethodTransfer->getIsActive() === false) { + throw new ComputopDefaultShipmentException( + sprintf('Default shipment method "%s" is not available!', $defaultShipmentMethodKey) + ); + } + + $itemShipmentTransfer = $this->createShipmentTransfer($defaultShipmentMethodTransfer); + $quoteTransfer = $this->addShipmentToQuoteItems($quoteTransfer, $itemShipmentTransfer); + $quoteTransfer = $this->shipmentFacade->expandQuoteWithShipmentGroups($quoteTransfer); + + return $quoteTransfer; + } + + /** + * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer + * @param \Generated\Shared\Transfer\ShipmentTransfer $shipmentTransfer + * + * @return \Generated\Shared\Transfer\QuoteTransfer + */ + protected function addShipmentToQuoteItems(QuoteTransfer $quoteTransfer, ShipmentTransfer $shipmentTransfer): QuoteTransfer + { + foreach ($quoteTransfer->getItems() as $itemTransfer) { + $itemTransfer->setShipment($shipmentTransfer); + } + + return $quoteTransfer; + } + + /** + * @param \Generated\Shared\Transfer\ShipmentMethodTransfer $shipmentMethodTransfer + * + * @return \Generated\Shared\Transfer\ShipmentTransfer + */ + protected function createShipmentTransfer(ShipmentMethodTransfer $shipmentMethodTransfer): ShipmentTransfer + { + return (new ShipmentTransfer()) + ->setShipmentSelection($shipmentMethodTransfer->getIdShipmentMethod()) + ->setMethod($shipmentMethodTransfer) + ->setShippingAddress(new AddressTransfer()); + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/Business/QuoteShipmentExpander/QuoteShipmentExpanderInterface.php b/src/SprykerEco/Zed/ComputopShipment/Business/QuoteShipmentExpander/QuoteShipmentExpanderInterface.php new file mode 100644 index 0000000..a5caf81 --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/Business/QuoteShipmentExpander/QuoteShipmentExpanderInterface.php @@ -0,0 +1,20 @@ +getFacade()->expandQuoteWithDefaultShippingMethod($quoteTransfer); + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/ComputopShipmentConfig.php b/src/SprykerEco/Zed/ComputopShipment/ComputopShipmentConfig.php new file mode 100644 index 0000000..9579f19 --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/ComputopShipmentConfig.php @@ -0,0 +1,24 @@ +get(ComputopShipmentConstants::PAYPAL_EXPRESS_DEFAULT_SHIPMENT_METHOD_KEY); + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/ComputopShipmentDependencyProvider.php b/src/SprykerEco/Zed/ComputopShipment/ComputopShipmentDependencyProvider.php new file mode 100644 index 0000000..63a72b5 --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/ComputopShipmentDependencyProvider.php @@ -0,0 +1,48 @@ +addShipmentFacade($container); + + return $container; + } + + /** + * @param \Spryker\Zed\Kernel\Container $container + * + * @return \Spryker\Zed\Kernel\Container + */ + protected function addShipmentFacade(Container $container): Container + { + $container->set(static::FACADE_SHIPMENT, function (Container $container) { + return new ComputopShipmentToShipmentFacadeBridge($container->getLocator()->shipment()->facade()); + }); + + return $container; + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/Dependency/ComputopShipmentToShipmentFacadeBridge.php b/src/SprykerEco/Zed/ComputopShipment/Dependency/ComputopShipmentToShipmentFacadeBridge.php new file mode 100644 index 0000000..14cddde --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/Dependency/ComputopShipmentToShipmentFacadeBridge.php @@ -0,0 +1,47 @@ +shipmentFacade = $shipmentFacade; + } + + /** + * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer + * + * @return \Generated\Shared\Transfer\QuoteTransfer + */ + public function expandQuoteWithShipmentGroups(QuoteTransfer $quoteTransfer): QuoteTransfer + { + return $this->shipmentFacade->expandQuoteWithShipmentGroups($quoteTransfer); + } + + /** + * @param string $shipmentMethodKey + * + * @return \Generated\Shared\Transfer\ShipmentMethodTransfer|null + */ + public function findShipmentMethodByKey(string $shipmentMethodKey): ?ShipmentMethodTransfer + { + return $this->shipmentFacade->findShipmentMethodByKey($shipmentMethodKey); + } +} diff --git a/src/SprykerEco/Zed/ComputopShipment/Dependency/ComputopShipmentToShipmentFacadeInterface.php b/src/SprykerEco/Zed/ComputopShipment/Dependency/ComputopShipmentToShipmentFacadeInterface.php new file mode 100644 index 0000000..2967916 --- /dev/null +++ b/src/SprykerEco/Zed/ComputopShipment/Dependency/ComputopShipmentToShipmentFacadeInterface.php @@ -0,0 +1,28 @@ +tester->setConfig(ComputopShipmentConstants::PAYPAL_EXPRESS_DEFAULT_SHIPMENT_METHOD_KEY, static::CORRECT_SHIPMENT_METHOD_KEY); + $quoteTransfer = $this->tester->haveQuoteWithItems(); + + //Act + $quoteTransfer = $this->tester->getFacade()->expandQuoteWithDefaultShippingMethod($quoteTransfer); + + //Assert + $this->assertNotNull($quoteTransfer->getShipment()); + $this->assertSame(static::CORRECT_SHIPMENT_METHOD_KEY, $quoteTransfer->getShipment()->getMethod()->getShipmentMethodKey()); + } + + /** + * @return void + */ + public function testExpandQuoteWithDefaultShippingMethodThrowsExceptionWhenShipmentMethodNotFound(): void + { + //Arrange + $this->tester->setConfig(ComputopShipmentConstants::PAYPAL_EXPRESS_DEFAULT_SHIPMENT_METHOD_KEY, static::INCORRECT_SHIPMENT_METHOD_KEY); + $quoteTransfer = $this->tester->haveQuoteWithItems(); + + //Assert + $this->expectException(ComputopDefaultShipmentException::class); + + //Act + $quoteTransfer = $this->tester->getFacade()->expandQuoteWithDefaultShippingMethod($quoteTransfer); + } +} diff --git a/tests/SprykerEcoTest/Zed/ComputopShipment/_support/ComputopShipmentBusinessTester.php b/tests/SprykerEcoTest/Zed/ComputopShipment/_support/ComputopShipmentBusinessTester.php new file mode 100644 index 0000000..91e976b --- /dev/null +++ b/tests/SprykerEcoTest/Zed/ComputopShipment/_support/ComputopShipmentBusinessTester.php @@ -0,0 +1,54 @@ +haveStore([StoreTransfer::NAME => 'DE']); + $quoteTransfer = (new QuoteBuilder()) + ->withStore($storeTransfer->toArray()) + ->withCustomer() + ->withItem() + ->withCurrency() + ->withExpense() + ->build(); + + $quoteTransfer->setPriceMode(''); + + return $quoteTransfer; + } +} diff --git a/tests/SprykerEcoTest/Zed/ComputopShipment/codeception.yml b/tests/SprykerEcoTest/Zed/ComputopShipment/codeception.yml new file mode 100644 index 0000000..25bd469 --- /dev/null +++ b/tests/SprykerEcoTest/Zed/ComputopShipment/codeception.yml @@ -0,0 +1,31 @@ +namespace: SprykerEcoTest\Zed\ComputopShipment + +paths: + tests: . + data: ../../../_data + support: _support + log: ../../../_output + +coverage: + enabled: true + remote: false + whitelist: { include: ['../../../../src/*'] } + +suites: + Business: + path: Business + class_name: ComputopShipmentBusinessTester + modules: + enabled: + - Asserts + - \SprykerTest\Shared\Testify\Helper\Environment + - \SprykerTest\Shared\Testify\Helper\ConfigHelper + - \SprykerTest\Shared\Propel\Helper\TransactionHelper + - \SprykerTest\Shared\Store\Helper\StoreDataHelper + - \SprykerTest\Shared\Testify\Helper\DependencyHelper + - \SprykerTest\Shared\Testify\Helper\ConfigHelper + - \SprykerTest\Shared\Testify\Helper\LocatorHelper: + coreNamespaces: + - Spryker + - SprykerEco + - \SprykerTest\Zed\Testify\Helper\BusinessHelper diff --git a/tooling.yml b/tooling.yml new file mode 100644 index 0000000..08f1960 --- /dev/null +++ b/tooling.yml @@ -0,0 +1,5 @@ +architecture-sniffer: + priority: 2 + +code-sniffer: + level: 1