From 6601a9f3020a9a5f9853f2915d2e655f4712558c Mon Sep 17 00:00:00 2001 From: jisse Reitsma Date: Tue, 6 Feb 2024 16:00:58 +0100 Subject: [PATCH] Pending changes --- CHANGELOG.md | 4 ++++ Util/CategoryProvider.php | 46 +++++++++++++++++++-------------------- composer.json | 2 +- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afde7e2b..ecd2e787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.7.11] - 6 February 2024 +### Fixed +- Fix PHP errors + ## [3.7.10] - 6 February 2024 ### Fixed - Better error handling in CategoryProvider #209 @thomas-kl1 diff --git a/Util/CategoryProvider.php b/Util/CategoryProvider.php index 5398feb1..40a8b4e5 100644 --- a/Util/CategoryProvider.php +++ b/Util/CategoryProvider.php @@ -21,18 +21,18 @@ class CategoryProvider * @var int[] */ private array $categoryIds = []; - + /** * @var CategoryInterface[] */ private array $loadedCategories = []; - + private CategoryListInterface $categoryListRepository; private FilterBuilder $filterBuilder; private SearchCriteriaBuilder $searchCriteriaBuilder; private FilterGroupBuilder $filterGroupBuilder; private StoreManagerInterface $storeManager; - + public function __construct( CategoryListInterface $categoryListRepository, FilterBuilder $filterBuilder, @@ -46,7 +46,7 @@ public function __construct( $this->filterGroupBuilder = $filterGroupBuilder; $this->storeManager = $storeManager; } - + /** * @param int[] $categoryIds * @return void @@ -58,10 +58,10 @@ public function addCategoryIds(array $categoryIds) if (empty($categoryIds)) { return; } - + $this->categoryIds = array_unique(array_merge($this->categoryIds, $categoryIds)); } - + /** * @param int $categoryId * @return CategoryInterface @@ -74,10 +74,10 @@ public function getById(int $categoryId): CategoryInterface return $category; } } - + throw new NotUsingSetProductSkusException('Using getCategoryById() delivers no result'); } - + /** * @return CategoryInterface[] * @throws NoSuchEntityException @@ -87,19 +87,19 @@ public function getLoadedCategories(): array if (empty($this->categoryIds)) { throw new NotUsingSetProductSkusException('Using getCategories() before setCategoryIds()'); } - + $loadCategoryIds = array_diff($this->categoryIds, array_keys($this->loadedCategories)); if (count($loadCategoryIds) > 0) { foreach ($this->loadCategoriesByIds($loadCategoryIds) as $category) { $this->loadedCategories[(int)$category->getId()] = $category; } } - + return array_filter($this->loadedCategories, static function (CategoryInterface $category) { return $category->getIsActive(); }); } - + /** * @param ProductInterface $product * @return CategoryInterface @@ -114,19 +114,19 @@ public function getFirstByProduct(ProductInterface $product): CategoryInterface $category = null; while ($category === null && $productCategoryId = array_shift($productCategoryIds)) { - $subject->addCategoryIds([$productCategoryId]); + $this->addCategoryIds([$productCategoryId]); if ($this->categoryIds) { - $category = $subject->getLoadedCategories()[$productCategoryId] ?? null; + $category = $this->getLoadedCategories()[$productCategoryId] ?? null; } } if ($category instanceof CategoryInterface) { return $category; } - + throw new NoSuchEntityException(__('Product "%1" has no categories', $product->getSku())); } - + /** * @param ProductInterface $product * @return CategoryInterface[] @@ -138,12 +138,12 @@ public function getAllByProduct(ProductInterface $product): array if (empty($productCategoryIds)) { throw new NoSuchEntityException(__('Product "%1" has no categories', $product->getSku())); } - + $this->addCategoryIds($productCategoryIds); return array_intersect_key($this->getLoadedCategories(), array_flip($productCategoryIds)); } - + /** * @param array $categoryIds * @return CategoryInterface[] @@ -160,7 +160,7 @@ private function loadCategoriesByIds(array $categoryIds): array ->setValue($categoryIds) ->create(), ]); - + /** @var FilterGroup $rootCategoryFilterGroup */ $rootCategoryFilterGroup = $this->filterGroupBuilder->create(); $rootCategoryFilterGroup->setFilters([ @@ -170,17 +170,17 @@ private function loadCategoriesByIds(array $categoryIds): array ->setValue('1/' . $this->getRootCategoryId() . '/%') ->create(), ]); - + $this->searchCriteriaBuilder->setFilterGroups([ $entityIdFilterGroup, $rootCategoryFilterGroup, ]); - + $searchCriteria = $this->searchCriteriaBuilder->create(); - + return $this->categoryListRepository->getList($searchCriteria)->getItems(); } - + /** * @param array $categoryIds * @return array @@ -193,7 +193,7 @@ private function filterRootCategoryIdFromCategoryIds(array $categoryIds): array return (int)$categoryId !== $rootCategoryId; }); } - + /** * @return int * @throws NoSuchEntityException diff --git a/composer.json b/composer.json index e82bb0cd..66b50ae3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "yireo/magento2-googletagmanager2", - "version": "3.7.10", + "version": "3.7.11", "license": "OSL-3.0", "type": "magento2-module", "homepage": "https://www.yireo.com/software/magento-extensions/googletagmanager2",