I want to add a column of a newly created boolean attribute, but it doesn’t work, I have read blogs where they give the same advice but it hasn’t worked
I have followed the following steps:
Create boolean attribute:
Extend the Product class from the vendor
appcodeVendorModuleetcadminhtmldi.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCatalogBlockAdminhtmlCategoryTabProduct" type="VendorModuleBlockAdminhtmlCategoryTabProduct"/>
</config>
appcodeVendorModuleBlockAdminhtmlCategoryTabProduct.php
<?php
namespace VendorModuleBlockAdminhtmlCategoryTab;
use MagentoCatalogModelProductAttributeSourceStatus;
use MagentoCatalogModelProductVisibility;
use MagentoFrameworkAppObjectManager;
use MagentoEavModelConfig;
class Product extends MagentoCatalogBlockAdminhtmlCategoryTabProduct
{
protected $visibility;
public function __construct(MagentoBackendBlockTemplateContext $context,
MagentoBackendHelperData $backendHelper,
MagentoCatalogModelProductFactory $productFactory,
MagentoFrameworkRegistry $coreRegistry,
array $data = [],
Visibility $visibility = null,
Status $status = null,
Config $eavConfig)
{
$this->eavConfig = $eavConfig;
$this->visibility = $visibility ?: ObjectManager::getInstance()->get(Visibility::class);
parent::__construct($context, $backendHelper, $productFactory, $coreRegistry, $data, $visibility, $status);
}
public function setCollection($collection)
{
$collection->addAttributeToSelect('destacado_categoria');
parent::setCollection($collection);
}
protected function _prepareColumns()
{
$attribute = $this->eavConfig->getAttribute('catalog_product', 'destacado_categoria');
if ($attribute)
{
$vals = $attribute->getSource()->getAllOptions();
$arr = [];
foreach ($vals as $option)
{
if ($option['label'])
{
$arr[$option['value']] = $option['label'];
}
}
parent::_prepareColumns();
$this->addColumnAfter('destacado_categoria', array(
'header' => __('Destacado Categoría'),
'index' => 'destacado_categoria',
'type' => 'options',
'options' => $arr,
), 'sku');
$this->sortColumnsByOrder();
return $this;
}
}
}
I need a special command line to be able to visualize it?
Please help, thanks!