Skip to content

Commit

Permalink
Merge branch 'pt-11491/5.2/fix-shopware-compatibility' into 'master'
Browse files Browse the repository at this point in the history
PT-11491 - Fix compatibility to older Shopware versions

See merge request shopware/5/services/swagpaymentpaypalunified!33
  • Loading branch information
DennisGarding committed May 27, 2020
2 parents 7d6d163 + 5e70feb commit 897db78
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
21 changes: 20 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,19 +77,22 @@ 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:
- zip -rq plugin.zip .
- 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion Resources/services/subscribers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
</service>

<service id="paypal_unified.subscriber.cookie_consent"
class="SwagPaymentPayPalUnified\Subscriber\CookieConsent">
class="SwagPaymentPayPalUnified\Subscriber\CookieConsent"
public="true">
<argument type="service" id="snippets"/>
<tag name="shopware.event_subscriber"/>
</service>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;(function($, window, undefined) {
;(function($, window, document, undefined) {
'use strict';

$.plugin('swagPayPalUnifiedInstallmentsBanner', {
Expand Down Expand Up @@ -78,6 +78,11 @@
return;
}

this.checkGetCookiePreference();
if (this.isPayPalAllowed() === false) {
return;
}

this.applyDataAttributes();
$.publish('plugin/swagPayPalUnifiedInstallmentsBanner/init', this);

Expand All @@ -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();
}
Expand All @@ -114,4 +156,4 @@
});

window.StateManager.addPlugin('*[data-paypalUnifiedInstallmentsBanner="true"]', 'swagPayPalUnifiedInstallmentsBanner');
})(jQuery, window);
})(jQuery, window, document);
2 changes: 1 addition & 1 deletion Subscriber/CookieConsent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/**
* (c) shopware AG <[email protected]>
*
Expand Down

0 comments on commit 897db78

Please sign in to comment.