skip to Main Content

I have a problem when applying magento 2.1.9 to my project.

My attribute is ab_size

I have created that attribute with code blow.

$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
        $entityTypeId = $categorySetup->getEntityTypeId(MagentoCatalogModelProduct::ENTITY);

        foreach ($singleAttributeCodes as $key => $label) {
            $categorySetup->removeAttribute($entityTypeId, $key);
            $categorySetup->addAttribute(
                $entityTypeId,
                $key,
                [
                    'type' => 'varchar',
                    'label' => $label,
                    'input' => 'select',
                    'required' => false,
                    'sort_order' => $sortOrder,
                    'visible' => true,
                    'user_defined' => true,
                    'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
                    'filterable' => 0,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'group' => $group,
                    'apply_to' => 'simple,configurable,bundle,downloadable,grouped',
                ]
            );
        }

With config in the backend.

  1. Enable filter (with result) done
  2. Category Is Anchor done
  3. Reindex done
  4. Enable Category flat done
  5. Enable Product flat done
  6. Reindex all data done
  7. Clear cache done
  8. Use magento clean doesn’t have any extension done
  9. Check with attribute color (done it show in navigation)
  10. Product Price Show
  11. Category Show

    about my system information

  12. CentOS 7.0

  13. Litespeed
  14. Php7.0
  15. Magento CE 2.1.9

I have debugged that the product collection buckets return empty

I think that problem with creating attribute code, has anyone got the same problem.

Thank anyone have tips.

2

Answers


  1. Chosen as BEST ANSWER

    With select attribute we must use type of int..


  2. I think you have messed your attributes with this code.
    Looking at it, it removes all the attributes and adds them but as type varchar, which may not be applicable to all attributes.
    I would suggest resetting your Magento database, and then add the attribute using code like the following.

    As I do not know what you are planning to use this attribute, some of the settings bellow may not apply to your use case.

     $categorySetup->addAttribute(
        MagentoCatalogModelProduct::ENTITY,
            'ab_size',
            [
                'type' => 'varchar',
                'backend' => '',
                'frontend' => '',
                'label' => 'AB Size',
                'input' => 'select',
                'class' => '',
                'source' => '',
                'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
                'global' => MagentoCatalogModelResourceModelEavAttribute::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => 0,
                'searchable' => false,
                'filterable' => true,
                'comparable' => false,
                'visible_on_front' => true,
                'used_in_product_listing' => true,
                'unique' => false,
                'apply_to' => ''
            ]
        );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search