From 5b95903a42c854543a6f6f7c7a6b25db239244a3 Mon Sep 17 00:00:00 2001 From: mandan2 Date: Tue, 3 Oct 2023 11:34:15 +0300 Subject: [PATCH 1/2] PIPRES-261: Restrict BO subscription list for all shops --- src/Adapter/Shop.php | 4 ++-- .../Controller/Symfony/SubscriptionController.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Adapter/Shop.php b/src/Adapter/Shop.php index cfedbcac2..9a6028605 100644 --- a/src/Adapter/Shop.php +++ b/src/Adapter/Shop.php @@ -19,8 +19,8 @@ public function getShop(): \Shop return \Context::getContext()->shop; } - public function getContext() + public function getContext(): int { - return $this->getShop()->getContext(); + return (int) $this->getShop()->getContext(); } } diff --git a/subscription/Controller/Symfony/SubscriptionController.php b/subscription/Controller/Symfony/SubscriptionController.php index 24596a78f..e0e3991a1 100644 --- a/subscription/Controller/Symfony/SubscriptionController.php +++ b/subscription/Controller/Symfony/SubscriptionController.php @@ -5,6 +5,7 @@ namespace Mollie\Subscription\Controller\Symfony; use Exception; +use Mollie\Adapter\Shop; use Mollie\Subscription\Exception\SubscriptionApiException; use Mollie\Subscription\Filters\SubscriptionFilters; use Mollie\Subscription\Grid\SubscriptionGridDefinitionFactory; @@ -28,6 +29,15 @@ class SubscriptionController extends AbstractSymfonyController */ public function indexAction(SubscriptionFilters $filters, Request $request) { + /** @var Shop $shop */ + $shop = $this->leagueContainer->getService(Shop::class); + + if ($shop->getContext() !== \Shop::CONTEXT_SHOP) { + $this->addFlash('error', $this->module->l('Select the shop that you want to configure')); + + return $this->render('@PrestaShop/Admin/layout.html.twig'); + } + /** @var GridFactoryInterface $currencyGridFactory */ $currencyGridFactory = $this->leagueContainer->getService('subscription_grid_factory'); $currencyGrid = $currencyGridFactory->getGrid($filters); @@ -71,6 +81,7 @@ public function cancelAction(int $subscriptionId): RedirectResponse { /** @var SubscriptionCancellationHandler $subscriptionCancellationHandler */ $subscriptionCancellationHandler = $this->leagueContainer->getService(SubscriptionCancellationHandler::class); + try { $subscriptionCancellationHandler->handle($subscriptionId); } catch (SubscriptionApiException $e) { From 5faaea8d2e89ae0c5e5e714489dc9f9a1855c4dc Mon Sep 17 00:00:00 2001 From: mandan2 Date: Tue, 3 Oct 2023 11:51:49 +0300 Subject: [PATCH 2/2] fixed redundant error mesage --- subscription/Controller/Symfony/SubscriptionController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subscription/Controller/Symfony/SubscriptionController.php b/subscription/Controller/Symfony/SubscriptionController.php index e0e3991a1..ba13cca0d 100644 --- a/subscription/Controller/Symfony/SubscriptionController.php +++ b/subscription/Controller/Symfony/SubscriptionController.php @@ -33,7 +33,9 @@ public function indexAction(SubscriptionFilters $filters, Request $request) $shop = $this->leagueContainer->getService(Shop::class); if ($shop->getContext() !== \Shop::CONTEXT_SHOP) { - $this->addFlash('error', $this->module->l('Select the shop that you want to configure')); + if (!$this->get('session')->getFlashBag()->has('error')) { + $this->addFlash('error', $this->module->l('Select the shop that you want to configure')); + } return $this->render('@PrestaShop/Admin/layout.html.twig'); }