want to do this
I have followed similar (Magento 2 add new custom option text field) topic but it's about custom options for simple products. Somebody in commets say's that he achieved this for bundle following this link. But It didn't work for me.
Here I what i have:
di.xml file in my module
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<plugin name="bachus_bundlecontextpros_custom_option" type="Bachus\BundleContextPros\Plugin\Bundle\Ui\DataProvider\Product\Form\Modifier\BundleCustomOptions" sortOrder="1"/>
</type>
</config>
and my BundleCustomOptions class
namespace Bachus\BundleContextPros\Plugin\Bundle\Ui\DataProvider\Product\Form\Modifier;
class BundleCustomOptions {
public function afterModifyMeta(
\Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundleCustomOptions $subject,
$meta
) {
$meta['custom_options']['children']['options']['children']['record']['children']['container_option']['children']['container_common']['children']['custom_text'] =
$this->getTitleFieldConfig(
200,
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Custom Text'),
'component' => 'Magento_Catalog/component/static-type-input',
'valueUpdate' => 'input',
'imports' => [
'optionId' => '${ $.provider }:${ $.parentScope }.option_id'
]
],
],
],
]
);
return $meta;
}
/**
* Get config for "Title" fields
*
* @param int $sortOrder
* @param array $options
* @return array
*/
protected function getTitleFieldConfig($sortOrder, array $options = [])
{
return array_replace_recursive(
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Custom Text'),
'componentType' => \Magento\Ui\Component\Form\Field::NAME,
'formElement' => \Magento\Ui\Component\Form\Element\Input::NAME,
'dataScope' => 'custom_text',
'dataType' => \Magento\Ui\Component\Form\Element\DataType\Text::NAME,
'sortOrder' => $sortOrder,
'validation' => [
'required-entry' => false
],
],
],
],
],
$options
);
}
}
Update: Now I am able to view the custom field in bunlde options by modyfing Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePanel.php
adding just after requierd
'bundle_template' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Form\Element\DataType\Text::NAME,
'formElement' => Form\Element\Input::NAME,
'componentType' => Form\Field::NAME,
'description' => __('bundle template'),
'dataScope' => 'bundle_template',
'label' => 'bundle template',
'sortOrder' => 40,
],
],
],
],
UPDATE I am able to save the value in data base but not see in admin
I just simply crated colum with exact name that my new custom field has in table catalog_product_bundle_option but it didn't work.
I would appreciate any help. Thanks