0

I am trying to add a new tab in the product page in admin but it's no appears in the product page.

The code is:

Vendor\Demo\view\adminhtml\layout\catalog_product_edit.xml

<?xml version="1.0"?>
<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\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo" name="demo.tab">
            <arguments>
                <argument name="config" xsi:type="array">
                    <item name="label" xsi:type="string" translate="true">Demo Tab</item>
                    <item name="collapsible" xsi:type="boolean">true</item>
                    <item name="opened" xsi:type="boolean">true</item>
                    <item name="sortOrder" xsi:type="string">2</item>
                    <item name="canShow" xsi:type="boolean">true</item>
                    <item name="componentType" xsi:type="string">fieldset</item>
                </argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

Vendor\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo

<?php
  namespace Vendor\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab;

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

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

     protected $_template = 'product/edit/demo.phtml';

    protected $_coreRegistry = null;

    public function __construct(
                              Context $context,
                              Registry $registry,
                              array $data = []
                              )
    {
       //echo "heloooo"; exit;
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }


   public function getProduct(){
      return $this->_coreRegistry->registry('current_product');
   }

} 

Vendor\Demo\view\adminhtml\templates\product\edit\demo.phtml

<h2>Demmooo</h2>

the tab not appearing in admin page.

  • From the initial review, it seems that you have typo mistake in namespace defined in the block file. It should be like Vendor\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab, since you have used Vendor everywhere else in your question. – Mohit Kumar Arora Nov 6 '18 at 6:29
  • @MohitKumarArora, It's my typing issue in editor and i update in above. the above code is not working – Ramesh Nov 14 '18 at 14:24

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.