diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4398d3945..7c10ef62f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -45,6 +45,6 @@ jobs: - name: Run unit Tests and Coverage if: ${{ !contains(github.event.pull_request.labels.*.name, 'hotfix') }} - run: task test:coverage + run: task test env: XDEBUG_MODE: coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index a270098bf..50b6904a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## v4.1.2 - 2024-07-16 + +### Changes + +### 🐛 Bug Fixes + +- fix: Avoid change quantity with module pscartdropdown for insurance (#510) +- fix: Issue PS Account with PS 8.1.7 (#506) +- fix: Issue quantity insurance if we change quantity in cart (#508) +- fix: Issue insurance for product not eligible created after import (#509) + +#### Contributors + +@Benjamin-Freoua-Alma, @carine-bonnafous and @github-actions + ## v4.1.1 - 2024-07-10 ### Changes diff --git a/Taskfile.yml b/Taskfile.yml index cc45ff149..f60a22883 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -10,12 +10,40 @@ tasks: cmds: - task -l + brew: + preconditions: + - sh: brew -v + msg: 'This task requires `brew`. Please refer to this documentation: https://brew.sh/' + + pre-commit: + desc: Install pre-commit tool + internal: true + deps: [brew] + status: + - pre-commit --version + cmds: + - brew install pre-commit + + pre-commit:install: + desc: Install and set up pre-commit hooks + deps: [pre-commit] + cmds: + - pre-commit install --hook-type pre-commit --hook-type commit-msg + + tools:install: + desc: Composer install of tools + sources: + - alma/composer.json + - alma/composer.lock + cmds: + - composer install --optimize-autoloader --working-dir=alma + docker:build: desc: Build prestashop docker image cmds: - docker compose build prestashop - test:coverage: + test: desc: Execute Unit Tests with coverage deps: - docker:build @@ -35,14 +63,6 @@ tasks: cmds: - rm -rf ./dist - install-tools: - desc: Composer install of tools - sources: - - alma/composer.json - - alma/composer.lock - cmds: - - composer install --optimize-autoloader --working-dir=alma - lint:ci: desc: Run linter within docker-compose for the CI deps: @@ -53,7 +73,7 @@ tasks: lint: desc: Run linter deps: - - install-tools + - tools:install cmds: - php alma/vendor/bin/php-cs-fixer fix --dry-run --diff alma # Search for variables in smarty templates that are not escaped @@ -66,7 +86,7 @@ tasks: lint:fix: desc: Run linter and apply fix deps: - - install-tools + - tools:install cmds: - php alma/vendor/bin/php-cs-fixer fix alma # Execute autoindex to add index in all folders @@ -78,7 +98,7 @@ tasks: php-compatibility: desc: Check compatibility code deps: - - install-tools + - tools:install cmds: - php ./alma/vendor/bin/phpcs -p alma --standard=PHPCompatibility -s --runtime-set testVersion 5.6-8.1 --ignore=\*/vendor/\* @@ -119,10 +139,11 @@ tasks: desc: Create a release pull request cmds: - gh workflow run release-pull-request.yml - - sleep 2 + - cmd: sleep 2 + silent: true - cmd: echo "Release pull request created, check out https://github.com/alma/{{.REPOSITORY}}/pulls?q=is%3Aopen+is%3Apr+label%3Arelease" silent: true - - cmd: echo "If no pull request is created, check out https://github.com/alma/{{.REPOSITORY}}/actions/workflows/release-pull-request.yml." + - cmd: echo "If no pull request is created, check out https://github.com/alma/{{.REPOSITORY}}/actions/workflows/release-pull-request.yml" silent: true - cmd: echo "Please, review and merge the pull request." silent: true @@ -140,10 +161,11 @@ tasks: Please provide a changelog message. Example: `task hotfix CHANGELOG_MESSAGE='This is a message'`. cmds: - gh workflow run hotfix-pull-request.yml -F changelog-message='{{.CHANGELOG_MESSAGE}}' - - sleep 2 + - cmd: sleep 2 + silent: true - cmd: echo "Hotfix pull request created, check out https://github.com/alma/{{.REPOSITORY}}/pulls?q=is%3Aopen+is%3Apr+label%3Ahotfix" silent: true - - cmd: echo "If no pull request is created, check out https://github.com/alma/{{.REPOSITORY}}/actions/workflows/hotfix-pull-request.yml." + - cmd: echo "If no pull request is created, check out https://github.com/alma/{{.REPOSITORY}}/actions/workflows/hotfix-pull-request.yml" silent: true - cmd: echo "Please, review and merge the pull request." silent: true diff --git a/alma/alma.php b/alma/alma.php index d99bfa66e..2a5a1eeac 100644 --- a/alma/alma.php +++ b/alma/alma.php @@ -33,7 +33,7 @@ class Alma extends PaymentModule { - const VERSION = '4.1.1'; + const VERSION = '4.1.2'; public $_path; public $local_path; @@ -83,7 +83,7 @@ public function __construct() { $this->name = 'alma'; $this->tab = 'payments_gateways'; - $this->version = '4.1.1'; + $this->version = '4.1.2'; $this->author = 'Alma'; $this->need_instance = false; $this->bootstrap = true; diff --git a/alma/config/admin/services.yml b/alma/config/admin/services.yml index ae837ec75..934cf7b48 100644 --- a/alma/config/admin/services.yml +++ b/alma/config/admin/services.yml @@ -1,4 +1,6 @@ services: + _defaults: + public: true ##################### # PS Account @@ -10,4 +12,4 @@ services: alma.ps_accounts_facade: class: 'PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts' arguments: - - '@alma.ps_accounts_installer' \ No newline at end of file + - '@alma.ps_accounts_installer' diff --git a/alma/controllers/hook/FrontHeaderHookController.php b/alma/controllers/hook/FrontHeaderHookController.php index 86503bf22..4bfb857f1 100644 --- a/alma/controllers/hook/FrontHeaderHookController.php +++ b/alma/controllers/hook/FrontHeaderHookController.php @@ -326,6 +326,8 @@ protected function manageAssetVersionForPrestashopBefore17() */ public function manageInsuranceAssetsAfter17() { + $scripts = ''; + if ( $this->insuranceHelper->isInsuranceAllowedInProductPage() && $this->iAmInProductPage() @@ -337,7 +339,7 @@ public function manageInsuranceAssetsAfter17() "modules/$this->moduleName/" . ConstantsHelper::INSURANCE_PRODUCT_CSS_PATH ); - return $this->urlScriptInsuranceModal(); + $scripts .= $this->urlScriptInsuranceModal(); } if ( @@ -352,7 +354,7 @@ public function manageInsuranceAssetsAfter17() ); if ($this->insuranceHelper->isInsuranceAllowedInCartPage()) { - return $this->urlScriptInsuranceModal(); + $scripts .= $this->urlScriptInsuranceModal(); } } @@ -365,7 +367,9 @@ public function manageInsuranceAssetsAfter17() $this->controller->addJS($this->module->_path . ConstantsHelper::INSURANCE_SCRIPT_PATH); - return $this->almaInsuranceIdInHeader(); + $scripts .= $this->almaInsuranceIdInHeader(); + + return $scripts; } /** diff --git a/alma/views/js/alma-cart-insurance.js b/alma/views/js/alma-cart-insurance.js index 18f1ca38d..a41a66dee 100644 --- a/alma/views/js/alma-cart-insurance.js +++ b/alma/views/js/alma-cart-insurance.js @@ -28,6 +28,9 @@ if (window.prestashop != null && window.prestashop.on != null) { prestashop.on("updatedCart", onloadInsuranceItemCartAlma); } + window.addEventListener('message', (e) => { + handleAddInsuranceProductFromWidget(e); + }); }); })(jQuery); @@ -182,10 +185,6 @@ function onloadInsuranceClickEvents() { }); }); - - window.addEventListener('message', (e) => { - handleAddInsuranceProductFromWidget(e); - }); } function handleAddInsuranceProductFromWidget(e) { @@ -218,7 +217,7 @@ function handleAddInsuranceProductFromWidget(e) { } } if (e.data.type === 'almaEligibilityAnswer') { - if (e.data.eligibilityCallResult.length > 0) { + if (e.data.eligibilityCallResponseStatus.response.eligibleProduct && e.data.eligibilityCallResult.length > 0) { $('#' + e.data.iFrameIdForProductWidget).show(); } } diff --git a/alma/views/js/alma-insurance.js b/alma/views/js/alma-insurance.js index b6a2a2883..718c80e04 100644 --- a/alma/views/js/alma-insurance.js +++ b/alma/views/js/alma-insurance.js @@ -1,3 +1,25 @@ +/** + * 2018-2024 Alma SAS + * + * THE MIT LICENSE + * + * 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. + * + * @author Alma SAS + * @copyright 2018-2024 Alma SAS + * @license https://opensource.org/licenses/MIT The MIT License + */ (function ($) { $(function () { loadInsuranceMiniCart(); diff --git a/alma/views/js/alma-product-insurance.js b/alma/views/js/alma-product-insurance.js index 698fbc51c..6601eea0f 100644 --- a/alma/views/js/alma-product-insurance.js +++ b/alma/views/js/alma-product-insurance.js @@ -26,6 +26,7 @@ let selectedAlmaInsurance = null; let addToCartFlow = false; let productDetails = null; let quantity = 1; +let almaEligibilityAnswer = false; (function ($) { $(function () { @@ -97,8 +98,9 @@ function onloadAddInsuranceInputOnProductAlma() { window.addEventListener('message', (e) => { if (e.data.type === 'almaEligibilityAnswer') { + almaEligibilityAnswer = e.data.eligibilityCallResponseStatus.response.eligibleProduct; btnLoaders('stop'); - if (e.data.eligibilityCallResponseStatus.response.eligibleProduct === true) { + if (almaEligibilityAnswer) { let heightIframe = e.data.widgetSize.height; let stringHeightIframe = heightIframe + 'px'; if (heightIframe <= 45) { @@ -108,7 +110,7 @@ function onloadAddInsuranceInputOnProductAlma() { document.getElementById('alma-widget-insurance-product-page').style.height = stringHeightIframe; } else { let addToCart = document.querySelector('.add-to-cart'); - addToCart.removeEventListener("click",insuranceListener) + addToCart.removeEventListener("click", insuranceListener) } } if (e.data.type === 'getSelectedInsuranceData') { @@ -204,8 +206,9 @@ function removeInputInsurance() { } function addModalListenerToAddToCart() { - if (settings.isAddToCartPopupActivated === true) { + if (settings.isAddToCartPopupActivated === true && almaEligibilityAnswer) { let addToCart = document.querySelector('.add-to-cart'); + // If we change the quantity the DOM is reloaded then we need to remove and add the listener again addToCart.removeEventListener("click",insuranceListener) addToCart.addEventListener("click", insuranceListener); }