|
| 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 | +} |
0 commit comments