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
I try to bypass this problem, by commenting out the two lines in file /www/magento2/xxx/app/code/Magento/Catalog/Model/CategoryRepository.php
#133 if (!isset($this->instances[$categoryId][$cacheKey])) {
and
#144 }
But another problem happens
Warning: addcslashes() expects parameter 1 to be string, object given in /www/magento2/xxx/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296
$value = addcslashes($value, "\000\032");
here, the input $value is "Magento\Catalog\Model\Category\Interceptor"
1 a:4:{i:0;s:128:"Warning: Illegal offset type in /www/magento2/xxx/app/code/Magento/Catalog/Model/CategoryRepository.php on line 133";i:1;s:4207:"#0 /www/magento2/xxx/app/code/Magento/Catalog/Model/CategoryRepository.php(133): Magento\Framework\App\ErrorHandler->handler(2, 'Illegal offset ...', '/www...', 133, Array)
2 #1 /www/magento2/xxx/app/code/Magento/Catalog/Block/Product/ListProduct.php(114): Magento\Catalog\Model\CategoryRepository->get(Object(Magento\Catalog\Model\Category\Interceptor))
3 #2 /www/magento2/xxx/app/code/Magento/Catalog/Block/Product/ListProduct.php(321): Magento\Catalog\Block\Product\ListProduct->_getProductCollection()
4 #3 /www/magento2/xxx/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php(71): Magento\Catalog\Block\Product\ListProduct->getIdentities()
5 #4 /www/magento2/xxx/lib/internal/Magento/Framework/Interception/Interceptor.php(152): Magento\PageCache\Model\Layout\LayoutPlugin->afterGetOutput(Object(Magento\Framework\View\Layout\Interceptor), '<script type="t...')
6 #5 /www/magento2/xxx/var/generation/Magento/Framework/View/Layout/Interceptor.php(39): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
7 #6 /www/magento2/xxx/lib/internal/Magento/Framework/View/Result/Page.php(243): Magento\Framework\View\Layout\Interceptor->getOutput()
8 #7 /www/magento2/xxx/lib/internal/Magento/Framework/View/Result/Layout.php(164): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
9 #8 /www/magento2/xxx/lib/internal/Magento/Framework/Interception/Interceptor.php(74): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
10 #9 /www/magento2/xxx/lib/internal/Magento/Framework/Interception/Chain/Chain.php(70): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
11 #10 /www/magento2/xxx/lib/internal/Magento/Framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-varnish-...')
12 #11 /www/magento2/xxx/app/code/Magento/PageCache/Model/Controller/Result/VarnishPlugin.php(74): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
13 #12 /www/magento2/xxx/lib/internal/Magento/Framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\Controller\Result\VarnishPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
14 #13 /www/magento2/xxx/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-builtin-...')
15 #14 /www/magento2/xxx/app/code/Magento/PageCache/Model/Controller/Result/BuiltinPlugin.php(67): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
16 #15 /www/magento2/xxx/lib/internal/Magento/Framework/Interception/Interceptor.php(142): Magento\PageCache\Model\Controller\Result\BuiltinPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
17 #16 /www/magento2/xxx/var/generation/Magento/Framework/View/Result/Page/Interceptor.php(26): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
18 #17 /www/magento2/xxx/lib/internal/Magento/Framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
19 #18 /www/magento2/xxx/lib/internal/Magento/Framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
20 #19 /www/magento2/xxx/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
21 #20 {main}";s:3:"url";s:28:"/mimi-all-purpose-short.html";s:11:"script_name";s:10:"/index.php";}
@yssource thank you for your report.
Please, provide the used version. If the problem is actual for a specific tag, please, specify it and be sure that the latest update was used.
Please also provide description according to the template: with steps, actual result and expected result.
According to contributor guide, tickets without response for two weeks should be closed.
Please feel free to reopen if it's needed.
Have the same problem after upgrading to Magento 2.1.0 from 2.0.7, anyone actually figure out what was going on here?
I have the same issue - is there a link to a resolution. M2.1.0.
@elrondb @davidaddison since this ticket is closed i doubt there will be much attention. If you are having this issue though please file a new ticket and provide full information in terms of version used, system information, and steps to reproduce so we can investigate.
Hi I am also facing the same issue when I am trying to call Featured products in product detail page.
Exception #0 (Exception): Warning: Illegal offset type in vendor/magento/module-catalog/Model/CategoryRepository.php on line 133
@kiranmaip Same issues here, how did you fix?
@giusecapo I didn't find any solution till now searching for that
kindly disable Page Cache in your cache management, and check the issue again.
Same issue here. is there any other fix other than disabling page cache ?
I have the same issue, I have three store views in this case
Same problem using Magento 2.1.5
Disabling FPC solves it temporarily. I used my theme working in 2.0.7 and am using it now in a clean install of 2.1.5.
Theses problems didn't occur with default product attributes/category/attribute sets after a clean installation.
After I added my own attributes and sets the problem occured, but I couldn't find out which one by now.
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.
@codekipple They have not. Just tried the same thing and got the same error in CE 2.1.7, one presumes for the same reason. sigh It is quite frustrating how many already fixed bugs I hit in the releases.
I got it in CE 2.1.7 as well.
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'
vendor/magento/module-catalog/Block/Product/ListProduct.php
Line #:112
if (! is_object($this->getCategoryId())) {
The above changes resolved the issue for me.
thankyour @iamkdev ,
I have this problem with amasty shopby module on magento 2.2 and category filter activated, i found the problem in "get" function, in fact this function expect an int parameters how categoryId, but in my case it receive an array.
I contact amasty to resolve problem, and i fixed temporally adding to this function this codeline:
if(is_array($categoryId)){
$categoryId = $categoryId[0];
}
I know this isn't definitive solutions and change core isn't a good idea, i continue to investigate with amasty to resolve the problem.
@elachino - Which file you have added if(is_array($categoryId)){ $categoryId = $categoryId[0]; } this line. Please guide me.
@sasilinux - I added this string in code/Magento/Catalog/Model/CategoryRepository.php, but i found the problem in amasty module finally.
On Magento 2.1 collection filter with array works, category ids filters in my case:
$productCollection->addAttributeToFilter(category_ids, $categoryIds);
But it didn't work on Magento 2.2, i found solution changed it with:
$productCollection->addCategoriesFilter(['in' => $categoryIds]);
I don't know if you have same issue, but if my first update works for you, i suggest to search error in categoryfilters.
@elachino - Thanks for the update. But in which amasty file you have changed it to the following line: $productCollection->addCategoriesFilter(['in' => $categoryIds]);
Beacuse i am also using Magento 2.2 with amasty.
@sasilinux - i posted update to amasty and they fix it in new module version. If you prefer, below you find all:
We changed code in app/code/Amasty/Shopby/Model/Layer/Filter/Category.php
116 if ($setting->isMultiselect() && $request->getParam('id') != $categoryId) {
117 $this->setCurrentValue($categoryIds);
118 $productCollection->addAttributeToFilter(CategoryHelper::ATTRIBUTE_CODE, $categoryIds);
with
116 if ($setting->isMultiselect() && $request->getParam('id') != $categoryId) {
117 $this->setCurrentValue($categoryIds);
118 $productCollection->addCategoriesFilter(['in' => $categoryIds]);
@elachino - It is working for me. Thanks a lot.
@elachino - After placing the above code. Category filter is working fine but other attribute filters are not working.
@sasilinux - i don't think my code break other filter working, we have change only Layer/Filter/Category, did you try if without my code other filters working?
@elachino - Sorry now it is working. It was occurred due to other stuff. Thanks. Also, if you have any suggestions to improve the site performance and search performance via mysql or any other thing. Please guide me. Thanks in advance.
Hello,
can you please unsubscribe our Mail-Address [email protected]
Thank you and best regards,
elektro-plus GmbH
Martin Graf
Von: sasilinux [mailto:[email protected]]
Gesendet: Freitag, 27. Oktober 2017 13:47
An: magento/magento2
Cc: Subscribed
Betreff: Re: [magento/magento2] Warning: Illegal offset type in /www/magento2/xxx/app/code/Magento/Catalog/Model/CategoryRepository.php on line 133 (#5475)
@elachino https://github.com/elachino - Sorry now it is working. It was occurred due to other stuff. Thanks. Also, if you have any suggestions to improve the site performance and search performance via mysql or any other thing. Please guide me. Thanks in advance.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/magento/magento2/issues/5475#issuecomment-339949365 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFoiZ2ZJv55mnO_jmIAJptjWeyWgLvv4ks5swcKKgaJpZM4JFIDT . https://github.com/notifications/beacon/AFoiZwXVbC-bASyjsginVSkYdzmTnTy9ks5swcKKgaJpZM4JFIDT.gif
Still Got the Error on 2.3 Version as well. any way to resolve it?
vendor/magento/module-catalog/Block/Product/ListProduct.php
Line #:112
if (! is_object($this->getCategoryId())) {The above changes resolved the issue for me.
Is it fine to customize the core code from the Magento? not a good approach
Most helpful comment
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.