Today's problem at our web agency in our online shop (Magento 2 CE 2.4.3): The Store Restriction Pro extension from extension developer MagePsycho, which is intended to restrict access to certain pages for specific user groups, was not working as expected. Among other things, the extension allows you to select CMS pages that should remain accessible without registration. However, when the cache was enabled, these pages were not displayed and users were instead redirected to the login page. The configuration made in the Magento backend was therefore not being applied correctly on the frontend.
This happened because, with the Magento cache enabled, the getFullActionName() function did not return the expected value; instead, an empty result was returned. Since the Magento 2 extension checks precisely this action controller and uses it to determine which pages are permitted (if the action controller is empty, it checks the allowed modules), the request was always rejected.
We therefore had to modify the following file:
/app/code/MagePsycho/StoreRestrictionPro/Observer/Frontend/ControllerActionPredispatch.php
We changed the following section of code:
if (in_array($fullActionName, ['cms_index_index', 'cms_page_view']) || 1==1) {
$this->srpHelper->log('::CMS::', true);
if (! $this->srpHelper->isRestrictedCmsPageAccessible()) {
$isCurrentPageRestricted = true;
}
} elseif (in_array($fullActionName, ['catalog_category_view']) || 1==1) {
$this->srpHelper->log('::CATEGORY::', true);
if (! $this->srpHelper->isRestrictedCategoryPageAccessible()) {
$isCurrentPageRestricted = true;
}
} elseif (in_array($fullActionName, ['catalog_product_view']) || 1==1) {
$this->srpHelper->log('::PRODUCT::', true);
if (! $this->srpHelper->isRestrictedProductPageAccessible()) {
$isCurrentPageRestricted = true;
}
} else {
$this->srpHelper->log('::MODULE::', true);
//get all the list of allowed modules
if (! $this->srpHelper->isRestrictedModulePageAccessible()) {
$isCurrentPageRestricted = true;
}
}
replace with
if (
! $this->srpHelper->isRestrictedCmsPageAccessible() &&
! $this->srpHelper->isRestrictedCategoryPageAccessible() &&
! $this->srpHelper->isRestrictedProductPageAccessible() &&
! $this->srpHelper->isRestrictedModulePageAccessible()
) {
$isCurrentPageRestricted = true;
}
It checks all permitted pages and path segments regardless of the page type, and the extension works as intended again. We encountered this issue at our web agency in an online shop running Magento CE 2.4.3.
