3

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:

    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Category::ENTITY,
        'my_attribute',
        [
            'type'        => 'int',
            'label'       => 'My Attribute',
            '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,
        'my_attribute',
        [
            'type'                    => 'int',
            'sort_order'              => 100,
            'label'                   => 'My Attribute',
            '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,
        ]
    );


-- Any idea?

  • I'm facing the same issue, the system attribute that I declared in code return 0 value. $filter->getItemsCount() -> 0 – Jared Chu Aug 27 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.