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
Filter category/product collection by new custom attribute returns 0 results #16367
Comments
Hi @pini-girit. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
where @pini-girit do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
|
@magento-engcom-team give me 2.2.4 instance |
Hi @pini-girit. Thank you for your request. I'm working on Magento 2.2.4 instance for you |
Hi @pini-girit, here is your Magento instance. |
Hello @pini-girit, thank you for your report. |
Hi. We are having exact same issue with Magento CE 2.2.4 version. Can you please let me know the status of this issue. Appreciate |
Hi @irajneeshgupta. Thank you for working on this issue.
|
Hi @shikhamis11. Thank you for working on this issue.
|
Hi @milindsingh. Thank you for working on this issue.
|
Any updates? |
With the same situation it is now working fine for me with Magento 2.3.6 |
✅ Jira issue https://jira.corp.magento.com/browse/AC-1032 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Alfa. Thank you for verifying the issue. |
Hi, @pniel-cohen! You could try to use the left join type to get the expected results: |
Summary of the issue
I created a bool (int) attribute with a default value of 0 for both category & product entities.
I reindexed, cleared cache, etc...
Now, no matter what I do, I can't filter the collection using this attribute. It always returns 0 results, no matter if the value is 0/1/null.
Also, when I tried to debug the issue I found out that my custom attributes are missing from catalog_category_entity_int & therefore - there is no default value for this attribute & the query returns 0 because it uses an inner join with this table (is that normal?).
This is how I created those attributes (I also tried the same with different values for 'global', 'nullable', 'used_in_product_listing', ...):
`
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'attr_code',
[
'type' => 'int',
'label' => 'Attr Label',
'input' => 'boolean',
'required' => false,
'default' => '0',
'sort_order' => 100,
'visible' => false,
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'nullable' => false,
'filterable' => true,
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'attr_code',
[
'type' => 'int',
'sort_order' => 100,
'label' => 'Attr Label',
'input' => 'boolean',
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => '0',
'searchable' => false,
'filterable' => true,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'nullable' => false,
]
);
`
Preconditions
Steps to reproduce
Expected result
$collection->addAttributeToFilter('attr_code', 1);
it should return 0 items.$collection->addAttributeToFilter('attr_code', 0);
it should return all items.items.Actual result
The text was updated successfully, but these errors were encountered: