Skip to content

Commit 948b71a

Browse files
committed
Merge branch 'pt-11491/5.2/add-cookie-consent' into 'master'
PT-11491 - Add PayPal cookies to consent manager See merge request shopware/5/services/swagpaymentpaypalunified!32
2 parents ea75bd2 + 829711d commit 948b71a

File tree

6 files changed

+128
-1
lines changed

6 files changed

+128
-1
lines changed

Resources/services/subscribers.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
<tag name="shopware.event_subscriber"/>
7171
</service>
7272

73+
<service id="paypal_unified.subscriber.cookie_consent"
74+
class="SwagPaymentPayPalUnified\Subscriber\CookieConsent">
75+
<argument type="service" id="snippets"/>
76+
<tag name="shopware.event_subscriber"/>
77+
</service>
78+
7379
<service id="paypal_unified.subscriber.express_checkout"
7480
class="SwagPaymentPayPalUnified\Subscriber\ExpressCheckout"
7581
public="true">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[en_GB]
2+
cookie/label = "PayPal payments"
3+
4+
[de_DE]
5+
cookie/label = "PayPal-Zahlungen"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474

7575
init: function() {
7676
this.payPalInstallmentsBannerJS = window.payPalInstallmentsBannerJS;
77+
if (this.payPalInstallmentsBannerJS === undefined) {
78+
return;
79+
}
7780

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

Subscriber/CookieConsent.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* (c) shopware AG <[email protected]>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
namespace SwagPaymentPayPalUnified\Subscriber;
10+
11+
use Enlight\Event\SubscriberInterface;
12+
use Shopware\Bundle\CookieBundle\CookieCollection;
13+
use Shopware\Bundle\CookieBundle\Structs\CookieGroupStruct;
14+
use Shopware\Bundle\CookieBundle\Structs\CookieStruct;
15+
use Shopware_Components_Snippet_Manager as SnippetManager;
16+
17+
class CookieConsent implements SubscriberInterface
18+
{
19+
/**
20+
* @var SnippetManager
21+
*/
22+
private $snippetManager;
23+
24+
public function __construct(SnippetManager $snippetManager)
25+
{
26+
$this->snippetManager = $snippetManager;
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public static function getSubscribedEvents()
33+
{
34+
return [
35+
'CookieCollector_Collect_Cookies' => 'addPayPalCookie',
36+
];
37+
}
38+
39+
/**
40+
* @return CookieCollection
41+
*/
42+
public function addPayPalCookie()
43+
{
44+
$collection = new CookieCollection();
45+
$collection->add(new CookieStruct(
46+
'paypal-cookies',
47+
// PayPal Cookies are not handled by Shopware, because they are not set by the plugin.
48+
// Therefore we use a regex which should not affect other cookies
49+
'/^paypal-cookie-consent-manager$/',
50+
$this->snippetManager->getNamespace('frontend/paypal_unified/cookie_consent/cookie')->get('cookie/label'),
51+
CookieGroupStruct::TECHNICAL
52+
));
53+
54+
return $collection;
55+
}
56+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* (c) shopware AG <[email protected]>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
namespace SwagPaymentPayPalUnified\Tests\Functional\Subscriber;
10+
11+
use PHPUnit\Framework\TestCase;
12+
use Shopware\Bundle\CookieBundle\Structs\CookieStruct;
13+
use SwagPaymentPayPalUnified\Subscriber\CookieConsent;
14+
15+
class CookieConsentTest extends TestCase
16+
{
17+
public function test_can_be_created()
18+
{
19+
$subscriber = $this->getSubscriber();
20+
static::assertNotNull($subscriber);
21+
}
22+
23+
public function test_getSubscribedEvents_has_correct_events()
24+
{
25+
$events = CookieConsent::getSubscribedEvents();
26+
static::assertCount(1, $events);
27+
static::assertSame('addPayPalCookie', $events['CookieCollector_Collect_Cookies']);
28+
}
29+
30+
public function test_addPayPalCookie()
31+
{
32+
$cookieCollection = $this->getSubscriber()->addPayPalCookie();
33+
static::assertNotNull($cookieCollection);
34+
35+
/** @var CookieStruct|null $cookie */
36+
$cookie = $cookieCollection->first();
37+
static::assertInstanceOf(CookieStruct::class, $cookie);
38+
static::assertSame('paypal-cookies', $cookie->getName());
39+
}
40+
41+
/**
42+
* @return CookieConsent
43+
*/
44+
private function getSubscriber()
45+
{
46+
return new CookieConsent(Shopware()->Container()->get('snippets'));
47+
}
48+
}

plugin.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
<label lang="de">PayPal</label>
66
<label lang="en">PayPal</label>
77

8-
<version>2.7.0</version>
8+
<version>REPLACE-GLOBAL-WITH-NEXT-VERSION(2.8.0)</version>
99
<copyright>(c) by shopware AG</copyright>
1010
<license>MIT</license>
1111
<link>http://store.shopware.com</link>
1212
<author>shopware AG</author>
1313
<compatibility minVersion="5.2.0" maxVersion="5.99.99"/>
1414

15+
<changelog version="REPLACE-GLOBAL-WITH-NEXT-VERSION">
16+
<changes lang="de">
17+
PT-11491 - PayPal-Cookies zum Consent-Manager hinzugefügt;
18+
</changes>
19+
<changes lang="en">
20+
PT-11491 - Add PayPal cookies to consent manager;
21+
</changes>
22+
</changelog>
23+
1524
<changelog version="2.7.0">
1625
<changes lang="de">
1726
PT-10536 - Behebt Anzeigefehler des Logos in Bestellbestätigungsmail;

0 commit comments

Comments
 (0)