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..ba13cca0d 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,17 @@ 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) { + 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'); + } + /** @var GridFactoryInterface $currencyGridFactory */ $currencyGridFactory = $this->leagueContainer->getService('subscription_grid_factory'); $currencyGrid = $currencyGridFactory->getGrid($filters); @@ -71,6 +83,7 @@ public function cancelAction(int $subscriptionId): RedirectResponse { /** @var SubscriptionCancellationHandler $subscriptionCancellationHandler */ $subscriptionCancellationHandler = $this->leagueContainer->getService(SubscriptionCancellationHandler::class); + try { $subscriptionCancellationHandler->handle($subscriptionId); } catch (SubscriptionApiException $e) {