1

I need to add a custom attribute column to the child products grid view in configurable products in backend.

enter image description here

My initial findings: Added 2 custom attributes(similar to the sku) to the products and give corresponding values to that.

By editing the below file:

vendor/magento/module-configurable-product/Ui/DataProvider/Product/Form/Modifier/ConfigurablePanel.php

//Added 2 line code to the below function, able to add 2 columns in the grid.

protected function getRows()
{

'oem_sku_container' => $this->getColumn('oem_sku', __('OEM_SKU')),

'internal_sku_container' => $this->getColumn('internal_sku', __('INTERNAL_SKU')),

}

enter image description here

But I didn't get any values of that custom attributes in the column. There is any way to get the value?

0

Step 1: in Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePane page,on

protected function getRows()
{
}

remove 'sku_container' => $this->getColumn('sku', __('SKU')),

and add

'oem_sku_container' => $this->getColumn('oem_sku', __('OEMSKU')),
                    'internal_sku_container' => $this->getColumn('internal_sku', __('INTERNALSKU')),

Step:2

In this page, Magento\Ui\Component\Form

on

 public function getDataSourceData()
    {
  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product
        $type_id =   $product->getTypeId();
        if($type_id ==  'configurable'){
            foreach ($data as $key_id => $data_value) {
                if (array_key_exists('configurable-matrix', $data_value)) {

foreach ($data_value['configurable-matrix'] as $configurableMatrixKey => $configurableMatrix) 
{
                        $sam_pid    =   $configurableMatrix['id'];
                        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

                        $productObj = $objectManager->get('Magento\Catalog\Model\Product')
                        ->load($sam_pid);

                        $product_oem_sku = $productObj->getOemSku();
                        $product_internal_sku = $productObj->getInternalSku();

                        $data[$key_id]['configurable-matrix'][$configurableMatrixKey]['oem_sku']      = $product_oem_sku;
                        $data[$key_id]['configurable-matrix'][$configurableMatrixKey]['internal_sku'] = $product_internal_sku;
                    }
                }
            }
        } 
}
| improve this answer | |
  • How can I rewrite "Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePanel" to my module? – Sameer Bhayani Nov 8 '17 at 7:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.