Can anybody help me to build this tab in admin panel by custom module.
i want to achieve something like above picture.
admin-panelmagento-2.1multi-vendor
Can anybody help me to build this tab in admin panel by custom module.
i want to achieve something like above picture.
Magento 2.1 :- You can use this code for simple custom tab add in product edit page. Create Own module and put below code in Vendor/Module/view/adminhtml/layout/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\Welcome" name="product.welcome" as="custom-tab" >
<arguments>
<argument name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Product Welcome</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>
</page>
In block Vendor/Module/Block/Adminhtml/Product/Edit/Tab/Welcome.php put below code.
<?php
namespace Vendor\Module\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');
}
}
In templates Vendor/Module/view/adminhtml/templates/catalog/product/edit/welcome.phtml put below code.
<div class="welcome">
<?php echo __('Welcome !'); ?>
</div>
Now Check back-end product module of Magento 2.1. It's working perfect.
etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<YourCompany_YourModule>
<version>0.1.0</version>
</YourCompany_YourModule>
</modules>
<global>
<helpers>
<yourmodule>
<class>YourCompany_YourModule_Helper</class>
</yourmodule>
</helpers>
<models>
<yourmodule>
<class>YourCompany_YourModule_Model</class>
<resourceModel>yourmodule_mysql4</resourceModel>
</yourmodule>
</models>
<resources>
<customerattribute1480661105_setup>
<setup>
<module>YourCompany_YourModule</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerattribute1480661105_setup>
<customerattribute1480661105_write>
<connection>
<use>core_write</use>
</connection>
</customerattribute1480661105_write>
<customerattribute1480661105_read>
<connection>
<use>core_read</use>
</connection>
</customerattribute1480661105_read>
</resources>
</global>
</config>
Helper/Data.php
<?php
class YourCompany_YourModule_Helper_Data extends Mage_Core_Helper_Abstract
{
}
sql/customerattribute1480661105_setup/mysql4-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "customer_attribute", array(
"type" => "text",
"backend" => "",
"label" => "Customer Attribute",
"input" => "multiselect",
"source" => "yourmodule/eav_entity_attribute_source_customeroptions14806611050",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "customer_attribute");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->endSetup();
Model/Eav/Entity/Attribute/Source/Customeroptions14806611050.php
<?php
class YourCompany_YourModule_Model_Eav_Entity_Attribute_Source_Customeroptions14806611050 extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
/**
* Retrieve all options array
*
* @return array
*/
public function getAllOptions()
{
//*******Here I have given sample values instead of this just retrieve your values in this format*******************
if (is_null($this->_options)) {
$this->_options = array(
array(
"label" => Mage::helper("eav")->__("1"),
"value" => 1
),
array(
"label" => Mage::helper("eav")->__("2"),
"value" => 2
),
array(
"label" => Mage::helper("eav")->__("3"),
"value" => 3
),
array(
"label" => Mage::helper("eav")->__("5"),
"value" => 4
),
);
}
return $this->_options;
}
/**
* Retrieve option array
*
* @return array
*/
public function getOptionArray()
{
$_options = array();
foreach ($this->getAllOptions() as $option) {
$_options[$option["value"]] = $option["label"];
}
return $_options;
}
/**
* Get a text for option value
*
* @param string|integer $value
* @return string
*/
public function getOptionText($value)
{
$options = $this->getAllOptions();
foreach ($options as $option) {
if ($option["value"] == $value) {
return $option["label"];
}
}
return false;
}
/**
* Retrieve Column(s) for Flat
*
* @return array
*/
public function getFlatColums()
{
$columns = array();
$columns[$this->getAttribute()->getAttributeCode()] = array(
"type" => "tinyint(1)",
"unsigned" => false,
"is_null" => true,
"default" => null,
"extra" => null
);
return $columns;
}
/**
* Retrieve Indexes(s) for Flat
*
* @return array
*/
public function getFlatIndexes()
{
$indexes = array();
$index = "IDX_" . strtoupper($this->getAttribute()->getAttributeCode());
$indexes[$index] = array(
"type" => "index",
"fields" => array($this->getAttribute()->getAttributeCode())
);
return $indexes;
}
/**
* Retrieve Select For Flat Attribute update
*
* @param int $store
* @return Varien_Db_Select|null
*/
public function getFlatUpdateSelect($store)
{
return Mage::getResourceModel("eav/entity_attribute")
->getFlatUpdateSelect($this->getAttribute(), $store);
}
}
Create function to get all options of your another module and retrieve it in function getAllOptions()
of given model.
Best Answer
You will need to create an custom module with etc/adminhtml/menu.xml.
For example
I suggest you look here for more info http://www.mage-world.com/blog/adding-new-menu-item-in-magento-2-custom-module.html