0

I would like to create a custom product attribute in the Product list but I want the attribute to be a dropdown of all the available categories as it's content/list. So it will be displaying the category name as the display in the dropdown and the id of the category as the value. Right now in my Setup Install I only have this

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);        
    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'category_dropdown',
        [
            'type' => 'datetime',
            'backend' => '',
            'frontend' => '',
            'label' => 'Category Items',
            'input' => 'date',
            'class' => '',
            'source' => '',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'visible' => true,
            'required' => false,
            'user_defined' => false,
            'default' => '',
            'searchable' => false,
            'filterable' => false,
            'comparable' => false,
            'visible_on_front' => false,
            'used_in_product_listing' => true,
            'unique' => false,
            'apply_to' => '',
            'show_in_grid' => true,
            'is_used_in_grid' => true,
            'is_visible_in_grid' => true
        ]
    );
}

I have no idea on how to accomplish this. Hope you can give me some samples regarding this implementation. Thanks

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.