Skip to content

Commit 897db78

Browse files
committed
Merge branch 'pt-11491/5.2/fix-shopware-compatibility' into 'master'
PT-11491 - Fix compatibility to older Shopware versions See merge request shopware/5/services/swagpaymentpaypalunified!33
2 parents 7d6d163 + 5e70feb commit 897db78

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

.gitlab-ci.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ variables:
99
WEB_DOCUMENT_ROOT: $CI_PROJECT_DIR/
1010
GIT_STRATEGY: clone
1111
CHECKOUT_SHOPWARE_BRANCH: "5.6"
12+
CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "master"
1213

1314
stages:
1415
- Code Style Check
@@ -76,19 +77,22 @@ SW 5.2:
7677
before_script: []
7778
variables:
7879
CHECKOUT_SHOPWARE_BRANCH: "5.2"
80+
CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.2.11-5.2.27"
7981
only:
8082
- master
8183
script:
8284
- zip -rq plugin.zip .
8385
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.shopware.com/shopware/5/product/shopware.git shopware --depth=1 -b ${CHECKOUT_SHOPWARE_BRANCH}
8486
- unzip -q plugin.zip -d shopware/custom/plugins/SwagPaymentPayPalUnified
8587
- cd shopware
88+
- 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}
8689
- /entrypoint supervisord &>/dev/null &
8790
- cp /usr/local/bin/composer composer.phar
8891
- 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"
8992
- php bin/console sw:plugin:refresh
9093
- php bin/console sw:plugin:list
9194
- php bin/console sw:plugin:install --activate SwagPaymentPayPalUnified
95+
- php bin/console sw:plugin:install --activate SwagCookieConsentManager
9296
- php bin/console sw:cache:clear -e testing
9397
- cd custom/plugins/SwagPaymentPayPalUnified
9498
- php ../../../vendor/bin/phpunit
@@ -105,9 +109,14 @@ SW 5.3:
105109
image: shopware/5-continuous:7.2
106110
variables:
107111
CHECKOUT_SHOPWARE_BRANCH: "5.3"
112+
CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.3.5-5.3.7"
108113
only:
109114
- master
110115
script:
116+
- 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}
117+
- php bin/console sw:plugin:refresh
118+
- php bin/console sw:plugin:install --activate SwagCookieConsentManager
119+
- php bin/console sw:cache:clear -e testing
111120
- cd custom/plugins/SwagPaymentPayPalUnified
112121
- php ../../../vendor/bin/phpunit
113122
--configuration phpunit.xml.dist
@@ -123,9 +132,14 @@ SW 5.4:
123132
image: shopware/5-continuous:7.2
124133
variables:
125134
CHECKOUT_SHOPWARE_BRANCH: "5.4"
135+
CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.4.6"
126136
only:
127137
- master
128138
script:
139+
- 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}
140+
- php bin/console sw:plugin:refresh
141+
- php bin/console sw:plugin:install --activate SwagCookieConsentManager
142+
- php bin/console sw:cache:clear -e testing
129143
- cd custom/plugins/SwagPaymentPayPalUnified
130144
- php ../../../vendor/bin/phpunit
131145
--configuration phpunit.xml.dist
@@ -141,9 +155,14 @@ SW 5.5:
141155
image: shopware/5-continuous:7.2
142156
variables:
143157
CHECKOUT_SHOPWARE_BRANCH: "5.5"
158+
CHECKOUT_COOKIE_CONSENT_MANAGER_BRANCH: "5.5.0-5.5.10"
144159
only:
145160
- master
146161
script:
162+
- 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}
163+
- php bin/console sw:plugin:refresh
164+
- php bin/console sw:plugin:install --activate SwagCookieConsentManager
165+
- php bin/console sw:cache:clear -e testing
147166
- cd custom/plugins/SwagPaymentPayPalUnified
148167
- php ../../../vendor/bin/phpunit
149168
--configuration phpunit.xml.dist
@@ -174,7 +193,7 @@ SW 5.6:
174193
SW 5.7:
175194
stage: Shopware Versions
176195
needs: [PHP analyze]
177-
image: shopware/5-continuous:7.2
196+
image: shopware/5-continuous:7.3
178197
variables:
179198
CHECKOUT_SHOPWARE_BRANCH: "5.7"
180199
only:

Resources/services/subscribers.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
</service>
7272

7373
<service id="paypal_unified.subscriber.cookie_consent"
74-
class="SwagPaymentPayPalUnified\Subscriber\CookieConsent">
74+
class="SwagPaymentPayPalUnified\Subscriber\CookieConsent"
75+
public="true">
7576
<argument type="service" id="snippets"/>
7677
<tag name="shopware.event_subscriber"/>
7778
</service>

Resources/views/frontend/_public/src/js/jquery.swag-paypal-unified.installments-banner.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;(function($, window, undefined) {
1+
;(function($, window, document, undefined) {
22
'use strict';
33

44
$.plugin('swagPayPalUnifiedInstallmentsBanner', {
@@ -78,6 +78,11 @@
7878
return;
7979
}
8080

81+
this.checkGetCookiePreference();
82+
if (this.isPayPalAllowed() === false) {
83+
return;
84+
}
85+
8186
this.applyDataAttributes();
8287
$.publish('plugin/swagPayPalUnifiedInstallmentsBanner/init', this);
8388

@@ -104,6 +109,43 @@
104109
}).render(this.$el.get(0));
105110
},
106111

112+
checkGetCookiePreference: function() {
113+
if ($.isFunction($.getCookiePreference)) {
114+
return;
115+
}
116+
117+
// Polyfill for older shopware versions
118+
$.getCookiePreference = function() {
119+
return false;
120+
};
121+
},
122+
123+
isPayPalAllowed: function() {
124+
var me = this;
125+
126+
me.cookieValue = me.getCookie();
127+
128+
return me.cookieValue || $.getCookiePreference('paypal-cookies');
129+
},
130+
131+
getCookie: function() {
132+
var name = "allowCookie=",
133+
decodedCookie = decodeURIComponent(document.cookie),
134+
cookieArray = decodedCookie.split(';');
135+
136+
for (var i = 0; i < cookieArray.length; i++) {
137+
var cookie = cookieArray[i];
138+
while (cookie.charAt(0) === ' ') {
139+
cookie = cookie.substring(1);
140+
}
141+
if (cookie.indexOf(name) === 0) {
142+
return cookie.substring(name.length, cookie.length);
143+
}
144+
}
145+
146+
return null;
147+
},
148+
107149
destroy: function() {
108150
this._destroy();
109151
}
@@ -114,4 +156,4 @@
114156
});
115157

116158
window.StateManager.addPlugin('*[data-paypalUnifiedInstallmentsBanner="true"]', 'swagPayPalUnifiedInstallmentsBanner');
117-
})(jQuery, window);
159+
})(jQuery, window, document);

Subscriber/CookieConsent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* (c) shopware AG <[email protected]>
44
*

0 commit comments

Comments
 (0)