1

I am trying to create a grid that should be shown on clicking a custom tab of admin catalog edit page.

1. Created catalog_product_new.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="product_form">
        <block class="Vendor\Module\Block\Adminhtml\Product\Edit\Tab\Customtab" after="review" name="product.customtab" as="customtab" >
            <arguments>
                <argument name="config" xsi:type="array">
                    <item name="label" xsi:type="string" translate="true">Custome Tab</item>
                    <item name="collapsible" xsi:type="boolean">true</item>
                    <item name="opened" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="string">5</item>
                    <item name="canShow" xsi:type="boolean">true</item>
                    <item name="componentType" xsi:type="string">fieldset</item>
                </argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

2. Created Customtab.php

<?php
namespace Venodr\Module\Block\Adminhtml\Product\Edit\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;

class Customtab extends \Magento\Framework\View\Element\Template {

    protected $_template = 'catalog/product/edit/sample.phtml';
    protected $_coreRegistry = null;
    protected $_customtabFactory;
    public function __construct(
    Context $context, Registry $registry, \Vendor\Module\Model\CustomtabFactory $customtabFactory, array $data = []
    ) {
        $this->_coreRegistry = $registry;
        $this->_customtabFactory = $customtabFactory;
        parent::__construct($context, $data);
    }
    public function getProduct() {
        return $this->_coreRegistry->registry('current_product');
    }
    public function getCustomData($item_id) {
        $model = $this->_customtabFactory->create();
        $modelData = $model->getCollection();
        $modelData->addFilter('item_id', array('eq' => $item_id));

        $data = $modelData->getData();
        return $data;
    }
}

3. Created sample.phtml

$product =  $block->getProduct();
$item_id = $product->getId();
$customdata =  $block->getCustomData($item_id);
foreach ($customdata as $key => $data) {
     echo $data['title'];  echo $data['created_time'];
}

By this way I am able to show my custom Tab on Admin catalog edit page , which shows sample.phtml content. But, I want to show grid instead of sample.phtml

Can anyone provide me the steps to show grid on custom tab created in catalog_product_new.xml ?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.