Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Illegal offset type in /www/magento2/xxx/app/code/Magento/Catalog/Model/CategoryRepository.php on line 133 #5475

Closed
yssource opened this issue Jul 5, 2016 · 32 comments
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update

Comments

@yssource
Copy link

yssource commented Jul 5, 2016

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

@yssource
Copy link
Author

yssource commented Jul 5, 2016

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"

@yssource
Copy link
Author

yssource commented Jul 5, 2016

 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";}

@veloraven
Copy link
Contributor

@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.

@andimov
Copy link
Contributor

andimov commented Aug 15, 2016

According to contributor guide, tickets without response for two weeks should be closed.
Please feel free to reopen if it's needed.

@andimov andimov closed this as completed Aug 15, 2016
@magento2developer
Copy link

magento2developer commented Sep 1, 2016

Have the same problem after upgrading to Magento 2.1.0 from 2.0.7, anyone actually figure out what was going on here?

@davidaddison
Copy link

I have the same issue - is there a link to a resolution. M2.1.0.

@pboisvert
Copy link

@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.

@kiranmaip
Copy link

kiranmaip commented Oct 20, 2016

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

@giusecapo
Copy link

@kiranmaip Same issues here, how did you fix?

@kiranmaip
Copy link

kiranmaip commented Oct 31, 2016

@giusecapo I didn't find any solution till now searching for that

@Umarali33
Copy link

kindly disable Page Cache in your cache management, and check the issue again.

@bobsimage
Copy link

Same issue here. is there any other fix other than disabling page cache ?

@dickrogers
Copy link

I have the same issue, I have three store views in this case

@lfritsche
Copy link

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.

@codekipple
Copy link

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 2b06a48

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.

@lingwooc
Copy link

@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.

@a45b
Copy link

a45b commented Jul 17, 2017

I got it in CE 2.1.7 as well.

@codekipple
Copy link

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'

@a45b
Copy link

a45b commented Jul 18, 2017

vendor/magento/module-catalog/Block/Product/ListProduct.php
Line #:112
if (! is_object($this->getCategoryId())) {

The above changes resolved the issue for me.

@itsmeit268
Copy link

thankyour @iamkdev ,

@elachino
Copy link

elachino commented Oct 3, 2017

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.

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Oct 3, 2017
@sasilinux
Copy link

@elachino - Which file you have added if(is_array($categoryId)){ $categoryId = $categoryId[0]; } this line. Please guide me.

@elachino
Copy link

elachino commented Oct 12, 2017

@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.

@sasilinux
Copy link

@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.

@elachino
Copy link

elachino commented Oct 12, 2017

@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]);

@sasilinux
Copy link

@elachino - It is working for me. Thanks a lot.

@sasilinux
Copy link

@elachino - After placing the above code. Category filter is working fine but other attribute filters are not working.

@elachino
Copy link

@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?

@sasilinux
Copy link

@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.

@elektro-plus
Copy link

elektro-plus commented Oct 27, 2017 via email

@shoaibgits
Copy link

Still Got the Error on 2.3 Version as well. any way to resolve it?

@shoaibgits
Copy link

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

magento-engcom-team pushed a commit that referenced this issue Mar 23, 2020
[TSG] TESTs Fixes for 2.4 (pr21) (2.4-develop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update
Projects
None yet
Development

No branches or pull requests