From 5e70feb6713e8ac29888b65e29e0e7c8f5e2cb68 Mon Sep 17 00:00:00 2001 From: Michael Telgmann Date: Tue, 26 May 2020 16:43:13 +0200 Subject: [PATCH] PT-11491 - Fix compatibility to older Shopware versions --- .gitlab-ci.yml | 21 ++++++++- Resources/services/subscribers.xml | 3 +- ...swag-paypal-unified.installments-banner.js | 46 ++++++++++++++++++- Subscriber/CookieConsent.php | 2 +- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2cdc68ab..9ed1ed4f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,6 +9,7 @@ variables: WEB_DOCUMENT_ROOT: $CI_PROJECT_DIR/ GIT_STRATEGY: clone CHECKOUT_SHOPWARE_BRANCH: "5.6" + CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "master" stages: - Code Style Check @@ -76,6 +77,7 @@ SW 5.2: before_script: [] variables: CHECKOUT_SHOPWARE_BRANCH: "5.2" + CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.2.11-5.2.27" only: - master script: @@ -83,12 +85,14 @@ SW 5.2: - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.shopware.com/shopware/5/product/shopware.git shopware --depth=1 -b ${CHECKOUT_SHOPWARE_BRANCH} - unzip -q plugin.zip -d shopware/custom/plugins/SwagPaymentPayPalUnified - cd shopware + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.shopware.com/shopware/5/product/swagcookieconsentmanager.git custom/plugins/SwagCookieConsentManager -b ${CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH} - /entrypoint supervisord &>/dev/null & - cp /usr/local/bin/composer composer.phar - ant -f build/build.xml build-unit -Dapp.path="" -Dapp.host="localhost" -Ddb.host="mysql" -Ddb.port=3306 -Ddb.name="shopware" -Ddb.user="app" -Ddb.password="app" - php bin/console sw:plugin:refresh - php bin/console sw:plugin:list - php bin/console sw:plugin:install --activate SwagPaymentPayPalUnified + - php bin/console sw:plugin:install --activate SwagCookieConsentManager - php bin/console sw:cache:clear -e testing - cd custom/plugins/SwagPaymentPayPalUnified - php ../../../vendor/bin/phpunit @@ -105,9 +109,14 @@ SW 5.3: image: shopware/5-continuous:7.2 variables: CHECKOUT_SHOPWARE_BRANCH: "5.3" + CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.3.5-5.3.7" only: - master script: + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.shopware.com/shopware/5/product/swagcookieconsentmanager.git custom/plugins/SwagCookieConsentManager -b ${CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH} + - php bin/console sw:plugin:refresh + - php bin/console sw:plugin:install --activate SwagCookieConsentManager + - php bin/console sw:cache:clear -e testing - cd custom/plugins/SwagPaymentPayPalUnified - php ../../../vendor/bin/phpunit --configuration phpunit.xml.dist @@ -123,9 +132,14 @@ SW 5.4: image: shopware/5-continuous:7.2 variables: CHECKOUT_SHOPWARE_BRANCH: "5.4" + CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.4.6" only: - master script: + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.shopware.com/shopware/5/product/swagcookieconsentmanager.git custom/plugins/SwagCookieConsentManager -b ${CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH} + - php bin/console sw:plugin:refresh + - php bin/console sw:plugin:install --activate SwagCookieConsentManager + - php bin/console sw:cache:clear -e testing - cd custom/plugins/SwagPaymentPayPalUnified - php ../../../vendor/bin/phpunit --configuration phpunit.xml.dist @@ -141,9 +155,14 @@ SW 5.5: image: shopware/5-continuous:7.2 variables: CHECKOUT_SHOPWARE_BRANCH: "5.5" + CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.5.0-5.5.10" only: - master script: + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.shopware.com/shopware/5/product/swagcookieconsentmanager.git custom/plugins/SwagCookieConsentManager -b ${CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH} + - php bin/console sw:plugin:refresh + - php bin/console sw:plugin:install --activate SwagCookieConsentManager + - php bin/console sw:cache:clear -e testing - cd custom/plugins/SwagPaymentPayPalUnified - php ../../../vendor/bin/phpunit --configuration phpunit.xml.dist @@ -174,7 +193,7 @@ SW 5.6: SW 5.7: stage: Shopware Versions needs: [PHP analyze] - image: shopware/5-continuous:7.2 + image: shopware/5-continuous:7.3 variables: CHECKOUT_SHOPWARE_BRANCH: "5.7" only: diff --git a/Resources/services/subscribers.xml b/Resources/services/subscribers.xml index a54ee0fb..c3a5df15 100644 --- a/Resources/services/subscribers.xml +++ b/Resources/services/subscribers.xml @@ -71,7 +71,8 @@ + class="SwagPaymentPayPalUnified\Subscriber\CookieConsent" + public="true"> diff --git a/Resources/views/frontend/_public/src/js/jquery.swag-paypal-unified.installments-banner.js b/Resources/views/frontend/_public/src/js/jquery.swag-paypal-unified.installments-banner.js index 62e4b9bf..2b197c1c 100644 --- a/Resources/views/frontend/_public/src/js/jquery.swag-paypal-unified.installments-banner.js +++ b/Resources/views/frontend/_public/src/js/jquery.swag-paypal-unified.installments-banner.js @@ -1,4 +1,4 @@ -;(function($, window, undefined) { +;(function($, window, document, undefined) { 'use strict'; $.plugin('swagPayPalUnifiedInstallmentsBanner', { @@ -78,6 +78,11 @@ return; } + this.checkGetCookiePreference(); + if (this.isPayPalAllowed() === false) { + return; + } + this.applyDataAttributes(); $.publish('plugin/swagPayPalUnifiedInstallmentsBanner/init', this); @@ -104,6 +109,43 @@ }).render(this.$el.get(0)); }, + checkGetCookiePreference: function() { + if ($.isFunction($.getCookiePreference)) { + return; + } + + // Polyfill for older shopware versions + $.getCookiePreference = function() { + return false; + }; + }, + + isPayPalAllowed: function() { + var me = this; + + me.cookieValue = me.getCookie(); + + return me.cookieValue || $.getCookiePreference('paypal-cookies'); + }, + + getCookie: function() { + var name = "allowCookie=", + decodedCookie = decodeURIComponent(document.cookie), + cookieArray = decodedCookie.split(';'); + + for (var i = 0; i < cookieArray.length; i++) { + var cookie = cookieArray[i]; + while (cookie.charAt(0) === ' ') { + cookie = cookie.substring(1); + } + if (cookie.indexOf(name) === 0) { + return cookie.substring(name.length, cookie.length); + } + } + + return null; + }, + destroy: function() { this._destroy(); } @@ -114,4 +156,4 @@ }); window.StateManager.addPlugin('*[data-paypalUnifiedInstallmentsBanner="true"]', 'swagPayPalUnifiedInstallmentsBanner'); -})(jQuery, window); +})(jQuery, window, document); diff --git a/Subscriber/CookieConsent.php b/Subscriber/CookieConsent.php index 60c458f8..97ab1d05 100644 --- a/Subscriber/CookieConsent.php +++ b/Subscriber/CookieConsent.php @@ -1,4 +1,4 @@ - *