From 80af482dedf01ac94314ec1edea088c8ce746213 Mon Sep 17 00:00:00 2001 From: aleksandrskondratjevs Date: Fri, 4 Mar 2022 10:36:15 +0200 Subject: [PATCH 1/2] Add validation for some pages --- src/Validator/Wishlist.php | 25 +++++++++++++++++++++++++ src/etc/di.xml | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/src/Validator/Wishlist.php b/src/Validator/Wishlist.php index bd52565..381e2a4 100644 --- a/src/Validator/Wishlist.php +++ b/src/Validator/Wishlist.php @@ -21,6 +21,7 @@ class Wishlist implements ValidatorInterface use PathTrait; const SHARED_URL_KEY = 'shared'; + const WISLIST_URL_KEY = 'wishlist'; /** * @var WishlistResourceModel @@ -44,6 +45,10 @@ public function __construct(WishlistResourceModel $wishlistResource, WishlistFac public function validateRequest(RequestInterface $request): bool { + if ($this->checkIfAccountWishlistTab($request)) { + return true; + } + $urlKey = $this->getPathFrontName($request); if ($urlKey !== self::SHARED_URL_KEY) { @@ -68,6 +73,10 @@ protected function checkIsShared(string $sharingKey): bool return true; } + /** + * @param RequestInterface $request + * @return string + */ protected function getSharingKey(RequestInterface $request): string { $path = trim($request->getPathInfo(), '/'); @@ -75,4 +84,20 @@ protected function getSharingKey(RequestInterface $request): string return end($params); } + + /** + * @param RequestInterface $request + * @return bool + */ + public function checkIfAccountWishlistTab(RequestInterface $request): bool + { + $path = trim($request->getPathInfo(), '/'); + $params = explode('/', $path); + + if (count($params) === 1 && $params[0] === self::WISLIST_URL_KEY) { + return true; + } + + return false; + } } diff --git a/src/etc/di.xml b/src/etc/di.xml index 84d87ca..a63aff5 100644 --- a/src/etc/di.xml +++ b/src/etc/di.xml @@ -26,6 +26,10 @@ ScandiPWA\Router\Validator\Wishlist ScandiPWA\Router\Validator\AlwaysPass ScandiPWA\Router\Validator\AlwaysPass + ScandiPWA\Router\Validator\AlwaysPass + ScandiPWA\Router\Validator\AlwaysPass + ScandiPWA\Router\Validator\AlwaysPass + ScandiPWA\Router\Validator\AlwaysPass From 89f0a9d0f7633a99295e2a7f6c1f4da9bf8c2657 Mon Sep 17 00:00:00 2001 From: aleksandrskondratjevs Date: Fri, 4 Mar 2022 10:42:39 +0200 Subject: [PATCH 2/2] Add comments for functions --- src/Validator/Wishlist.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Validator/Wishlist.php b/src/Validator/Wishlist.php index 381e2a4..f6ef00e 100644 --- a/src/Validator/Wishlist.php +++ b/src/Validator/Wishlist.php @@ -43,6 +43,10 @@ public function __construct(WishlistResourceModel $wishlistResource, WishlistFac $this->wishlistFactory = $wishlistFactory; } + /** + * @param RequestInterface $request + * @return bool + */ public function validateRequest(RequestInterface $request): bool { if ($this->checkIfAccountWishlistTab($request)) { @@ -60,6 +64,10 @@ public function validateRequest(RequestInterface $request): bool return $this->checkIsShared($sharingKey); } + /** + * @param string $sharingKey + * @return bool + */ protected function checkIsShared(string $sharingKey): bool { /** @var WishlistModel $wishlist */