Magento – Magento 2: How to get product custom attribute in product grid

custom-attributesmagento2product-attributeproduct-collectionproduct-grid

How to get product custom attribute in product grid. I have create product attribute as "qty_per_box". But it is not showing in collection.

The following code is not getting custom product attribue.

  /**
    * @return Grid
    */
        protected function _prepareCollection()
        {
            $collection = $this->productFactory->create()->getCollection()->addAttributeToSelect("*");
            $this->setCollection($collection);
            return parent::_prepareCollection();
        }

Best Answer

1/ Magento Admin > Stores > Attributes / Product > Click on your custom attribute > Advanced Attribute Properties > Set "Add to Column Options" to "Yes" and click on "Save attribute" button

enter image description here

2/ Magento Admin > Products > Inventory / Catalog > Select your custom attribute on "Columns box"

enter image description here

Related Topic