Skip to content

Commit

Permalink
PIPRES-261: Restrict BO subscription list for all shops (#823)
Browse files Browse the repository at this point in the history
* PIPRES-261: Restrict BO subscription list for all shops

* fixed redundant error mesage
  • Loading branch information
mandan2 authored Oct 3, 2023
1 parent d7b84d5 commit 74197b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Adapter/Shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
13 changes: 13 additions & 0 deletions subscription/Controller/Symfony/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 74197b5

Please sign in to comment.