Skip to content

Commit 813a115

Browse files
author
Adam Skorupka
committed
Release 1.5.0
1 parent 396f126 commit 813a115

16 files changed

Lines changed: 299 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.5.0] - 2024-12-18
4+
### Feature
5+
- Added support for cart recovery for non-logged-in users
6+
37
## [1.4.2] - 2024-10-31
48
### Feature
59
- Change storage from cookie to session

classes/WebserviceSpecificManagementGetresponseModule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private function getPluginDetails()
192192

193193
return json_encode(
194194
[
195-
'plugin_version' => '1.4.2',
195+
'plugin_version' => '1.5.0',
196196
'prestashop_version' => _PS_VERSION_,
197197
'php_version' => phpversion(),
198198
'shops' => $shops,

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<module>
33
<name>grprestashop</name>
44
<displayName><![CDATA[GetResponse]]></displayName>
5-
<version><![CDATA[1.4.2]]></version>
5+
<version><![CDATA[1.5.0]]></version>
66
<description><![CDATA[Add your Prestashop contacts to GetResponse.]]></description>
77
<author><![CDATA[GetResponse]]></author>
88
<tab><![CDATA[emailing]]></tab>

controllers/front/CartRecovery.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
21+
use GetResponse\SharedKernel\CartRecoveryHelper;
22+
23+
if (!defined('_PS_VERSION_')) {
24+
exit;
25+
}
26+
27+
class GrPrestashopCartRecoveryModuleFrontController extends ModuleFrontController
28+
{
29+
public function init()
30+
{
31+
$queryParams = Tools::getAllValues();
32+
33+
if (empty($queryParams['cart_id']) || empty($queryParams['cart_token'])) {
34+
$this->showErrorFlashMessage();
35+
}
36+
$cartId = $queryParams['cart_id'];
37+
38+
if ($queryParams['cart_token'] != CartRecoveryHelper::generateCartToken($cartId)) {
39+
$this->showErrorFlashMessage();
40+
}
41+
42+
$recoveredCart = new Cart($cartId);
43+
if (!Validate::isLoadedObject($recoveredCart)) {
44+
$this->showErrorFlashMessage();
45+
}
46+
47+
$this->context->cart = $recoveredCart;
48+
$this->context->cookie->id_cart = (int) $recoveredCart->id;
49+
50+
$link = $this->context->link ? $this->context->link : new Link();
51+
52+
$redirectLink = $link->getPageLink('cart', null, null, ['action' => 'show']);
53+
Tools::redirect($redirectLink);
54+
}
55+
56+
private function showErrorFlashMessage()
57+
{
58+
$this->errors[] = $this->l('We could not recover your cart');
59+
$this->redirectWithNotifications('index.php');
60+
61+
return;
62+
}
63+
}

controllers/front/index.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
21+
22+
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
23+
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
24+
25+
header("Cache-Control: no-store, no-cache, must-revalidate");
26+
header("Cache-Control: post-check=0, pre-check=0", false);
27+
header("Pragma: no-cache");
28+
29+
header("Location: ../");
30+
exit;

grprestashop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct()
4242
{
4343
$this->name = 'grprestashop';
4444
$this->tab = 'emailing';
45-
$this->version = '1.4.2';
45+
$this->version = '1.5.0';
4646
$this->author = 'GetResponse';
4747
$this->need_instance = 0;
4848
$this->module_key = '311ef191c3135b237511d18c4bc27369';

src/Ecommerce/Application/Adapter/CartAdapter.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use GetResponse\Contact\Application\Adapter\CustomerAdapter;
2424
use GetResponse\Ecommerce\DomainModel\Cart;
2525
use GetResponse\Ecommerce\DomainModel\Line;
26+
use GetResponse\SharedKernel\CartRecoveryHelper;
2627

2728
if (!defined('_PS_VERSION_')) {
2829
exit;
@@ -32,10 +33,11 @@ class CartAdapter
3233
{
3334
/**
3435
* @param $cartId
36+
* @param $visitorUuid
3537
*
3638
* @return Cart
3739
*/
38-
public function getCartById($cartId)
40+
public function getCartById($cartId, $visitorUuid)
3941
{
4042
$prestashopCart = new \Cart($cartId);
4143
$customerAdapter = new CustomerAdapter();
@@ -64,18 +66,17 @@ public function getCartById($cartId)
6466
);
6567
}
6668

67-
$shopCartUrl = version_compare(_PS_VERSION_, '1.7', '>=')
68-
? \Context::getContext()->link->getPageLink('cart', null, null, ['action' => 'show'])
69-
: \Context::getContext()->link->getPageLink('order');
69+
$cartRecoveryUrl = CartRecoveryHelper::getUrl($prestashopCart->id);
7070

7171
return new Cart(
7272
$prestashopCart->id,
7373
$customer,
74+
$visitorUuid,
7475
$lines,
7576
$prestashopCart->getOrderTotal(false),
7677
$prestashopCart->getOrderTotal(true),
7778
$currency->iso_code,
78-
$shopCartUrl,
79+
$cartRecoveryUrl,
7980
$prestashopCart->date_add,
8081
$prestashopCart->date_upd
8182
);

src/Ecommerce/Application/CartService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ public function upsertCart(UpsertCart $command)
5858
return;
5959
}
6060

61+
$visitorUuid = null;
62+
if ($configuration->isGetResponseWebTrackingActive() && isset($_COOKIE['gaVisitorUuid'])) {
63+
$visitorUuid = $_COOKIE['gaVisitorUuid'];
64+
}
65+
6166
$cartAdapter = new CartAdapter();
62-
$cart = $cartAdapter->getCartById($command->getCartId());
67+
$cart = $cartAdapter->getCartById($command->getCartId(), $visitorUuid);
6368

6469
if ($cart->isValuable()) {
6570
$this->messageSenderService->send(

src/Ecommerce/DomainModel/Cart.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class Cart implements \JsonSerializable
3333
private $id;
3434
/** @var Customer */
3535
private $customer;
36+
/** @var ?string */
37+
private $visitorUuid;
3638
/** @var Line[] */
3739
private $lines;
3840
/** @var float */
@@ -51,6 +53,7 @@ class Cart implements \JsonSerializable
5153
public function __construct(
5254
$id,
5355
Customer $customer,
56+
$visitorUuid,
5457
$lines,
5558
$totalPrice,
5659
$totalTaxPrice,
@@ -61,6 +64,7 @@ public function __construct(
6164
) {
6265
$this->id = $id;
6366
$this->customer = $customer;
67+
$this->visitorUuid = $visitorUuid;
6468
$this->lines = $lines;
6569
$this->totalPrice = $totalPrice;
6670
$this->totalTaxPrice = $totalTaxPrice;
@@ -86,6 +90,14 @@ public function getCustomer()
8690
return $this->customer;
8791
}
8892

93+
/**
94+
* @return string
95+
*/
96+
public function getVisitorUuid()
97+
{
98+
return $this->visitorUuid;
99+
}
100+
89101
/**
90102
* @return Line[]
91103
*/
@@ -157,6 +169,7 @@ public function jsonSerialize()
157169
'id' => $this->id,
158170
'contact_email' => $this->customer->getEmail(),
159171
'customer' => $this->customer->jsonSerialize(),
172+
'visitor_uuid' => $this->visitorUuid,
160173
'lines' => $lines,
161174
'total_price' => $this->totalPrice,
162175
'total_price_tax' => $this->totalTaxPrice,
@@ -172,6 +185,6 @@ public function jsonSerialize()
172185
*/
173186
public function isValuable()
174187
{
175-
return $this->id !== 0 && $this->customer->getEmail() !== null;
188+
return $this->id !== 0 && ($this->customer->getEmail() !== null || $this->visitorUuid !== null);
176189
}
177190
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
21+
namespace GetResponse\SharedKernel;
22+
23+
use Context;
24+
25+
class CartRecoveryHelper
26+
{
27+
public static function getUrl($cartId)
28+
{
29+
return Context::getContext()->link->getModuleLink(
30+
'grprestashop',
31+
'CartRecovery',
32+
[
33+
'cart_id' => $cartId,
34+
'cart_token' => self::generateCartToken($cartId),
35+
]
36+
);
37+
}
38+
39+
public static function generateCartToken($cartId)
40+
{
41+
return md5(_COOKIE_KEY_ . 'recover_cart_' . $cartId);
42+
}
43+
}

0 commit comments

Comments
 (0)