magento2: Warning: Illegal offset type in /www/magento2/xxx/app/code/Magento/Catalog/Model/CategoryRepository.php on line 133
It seems that the issue is related to multi stores and multi views.
If you have the default store view ONLY, then the error won’t be found and you will be redirected to the product page view, and it works fine.
But, if you add a new store view whether it’s enabled or disabled, the issue will appear and the error will be found.
$categoryId is a instance of a Class with a value of "`Magento\Catalog\Model\Category\Interceptor`", which making this warning and crashing the site.
if (!isset($this->instances[$categoryId][$cacheKey])) {
This related to another similar issue #4018
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 32 (2 by maintainers)
Commits related to this issue
- Merge pull request #5475 from magento-tsg/2.4-develop-pr21 [TSG] TESTs Fixes for 2.4 (pr21) (2.4-develop) — committed to magento/magento2 by zakdma 4 years ago
Magneto version: community edition 2.1.6 I came across this error message but it was because I was trying to use the the ‘Magento\Catalog\Block\Product\ListProduct’ block on the product page, by default this block is only used on the category page. The block’s code read like it was able to be used on the product page so I tracked it down to being a bug.
Having a look at the current development branch this bug seems to be fixed with this commit https://github.com/magento/magento2/commit/2b06a484f9020a5d3398d8e09f5e526701ab9629
The error message seems to happen when the setCategoryId() method is called with something inappropriate. In the case of the ‘Magento\Catalog\Block\Product\ListProduct’ block it was trying to use setCategoryId() by passing it an object ‘Magento\Catalog\Model\Category\Interceptor’ instead of an integer representing the category ID. ‘Magento\Catalog\Model\CategoryRepository’ was than throwing an error when trying to use the value set via setCategoryId() in a array cache lookup.
I suspect it will be a similar bug regarding other peoples situations so hopefully the Magento devs have caught these occurrences and the fixes will be in the next release.
vendor/magento/module-catalog/Block/Product/ListProduct.php Line #:112 if (! is_object($this->getCategoryId())) {
The above changes resolved the issue for me.
The fix is tagged with 2.2.0-RC1.4 so it looks like it’s coming with 2.2.0, I ended up just creating my own block for now instead of trying to use ‘Magento\Catalog\Block\Product\ListProduct’