diff --git a/src/Model/LandingPage.php b/src/Model/LandingPage.php index dbd264a..b2b4cc0 100644 --- a/src/Model/LandingPage.php +++ b/src/Model/LandingPage.php @@ -12,6 +12,7 @@ use Magento\Framework\Model\AbstractExtensibleModel; use Magento\Framework\Registry; use Magento\Framework\Model\Context; +use Exception; use Magento\Framework\Model\ResourceModel\AbstractResource; /** @@ -346,11 +347,22 @@ public function setFilterAttributes(?string $filterAttributes): LandingPageInter */ public function getUnserializedFilterAttributes(): array { - if ($this->getFilterAttributes() === null) { + $raw = $this->getFilterAttributes(); + if ($raw === null || $raw === '') { return []; } - return unserialize($this->getFilterAttributes()); + try { + $result = unserialize($raw, ['allowed_classes' => false]); + } catch (Exception $e) { + return []; + } + + if (!is_array($result)) { + return []; + } + + return $result; } /** diff --git a/src/Model/UrlFinder.php b/src/Model/UrlFinder.php index 3dfbd9a..35dfbf1 100644 --- a/src/Model/UrlFinder.php +++ b/src/Model/UrlFinder.php @@ -10,6 +10,7 @@ use Emico\AttributeLanding\Api\Data\FilterInterface; use Emico\AttributeLanding\Api\Data\LandingPageInterface; use Emico\AttributeLanding\Api\LandingPageRepositoryInterface; +use Exception; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\CacheInterface; use Magento\Framework\Serialize\SerializerInterface; @@ -150,7 +151,13 @@ protected function loadPageLookupArray(): array $landingPageLookup = []; foreach ($this->landingPageRepository->getList($searchCriteria)->getItems() as $landingPage) { - $hash = $this->createHashForFilters($landingPage->getFilters(), $landingPage->getCategoryId()); + try { + $filters = $landingPage->getFilters(); + } catch (Exception $e) { + continue; + } + + $hash = $this->createHashForFilters($filters, $landingPage->getCategoryId()); /** @phpstan-ignore-next-line */ $storeId = $landingPage->getData('store_id'); /** @phpstan-ignore-next-line */