0

I created my custom tab in product page. Now i did't found any solution to save custom tab value so that i can use that value on frontend.

I created custom tab on product page by creating catalog_product_new.xml file in /vendor/magento/module-catalog/view/adminhtml/layout/. Below is the code:-

<?xml version="1.0"?>
            <!--
            /**
             * Copyright © 2016 Magento. All rights reserved.
             * See COPYING.txt for license details.
             */
            -->
            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
                <update handle="styles"/>
                <head>
                    <css src="jquery/fileUploader/css/jquery.fileupload-ui.css"/>
                </head>
                <update handle="editor"/>
                <update handle="catalog_product_form"/>
                 <referenceBlock name="product_form">
                       <block class="Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Welcome" name="product.welcome" as="custom-tab" >

                            <arguments>
                                <argument name="config" xsi:type="array">
                                    <item name="label" xsi:type="string" translate="true">Product Finder Parts</item>
                                    <item name="collapsible" xsi:type="boolean">true</item>
                                    <item name="opened" xsi:type="boolean">false</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>
            </page>

Then i created block: Vendor/Module/Block/Adminhtml/Product/Edit/Tab/Welcome.php

<?php

    namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Tab;
    use Magento\Backend\Block\Template\Context;
    use Magento\Framework\Registry;

    class Welcome extends \Magento\Framework\View\Element\Template
    {
        protected $_template = 'catalog/product/edit/welcome.phtml';

        protected $_coreRegistry = null;

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

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

            return "heloo dgdgdg";
        }


    }
    ?>

After that i created phtml file in Vendor/Module/view/adminhtml/templates/catalog/product/edit/welcome.phtml

<div class="welcome">
        <div class="admin__field admin__field-option">
            <input type="checkbox" class="admin__control-checkbox" id="finder" name="_ids][1]" value="1">

            <label class="admin__field-label" data-bind="attr: {for: uid}, text: description" for="UVHR95L">Parts Finder Enable</label>
        </div>
    </div>

I have created tab in admin successfully by this code .

I tried this but it didn't work for me. Can you guys help me to save this value? I am searching for solution from past 2 days.

1

By adding

data-form-part="product_form"

to the input/option field, Then you can get the values.

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.