Magento 2 BundleCustom Option New Field Not Show Value
What we have:
di.xml
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
UpgradeSchema.php
<?php
namespace SYConfiguratorSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface {
public function upgrade(
SchemaSetupInterface $setup,
ModuleContextInterface $context
){
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '0.0.3', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'option_sku',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'comment' => 'Sku'
]
);
}
$installer->endSetup();
}
}
Plugin:
class BundlePanel {
public function afterModifyMeta(
MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject,
$meta
){
$meta['bundle-items']['children']['bundle_options']['children']['record']['children']['product_bundle_container']['children']['option_info']['children']['option_sku'] = $this->getSkuFieldConfig(
11,
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'component' => 'Magento_Catalog/component/static-type-input',
'valueUpdate' => 'input',
'imports' => [
'optionId' => '${ $.provider }:${ $.parentScope }.option_id'
]
]
]
]
]
);
return $meta;
}
protected function getSkuFieldConfig($sortOrder, array $options = ){
return array_replace_recursive(
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'componentType' => MagentoUiComponentFormField::NAME,
'formElement' => MagentoUiComponentFormElementInput::NAME,
'dataScope' => 'option_sku',
// 'dataScope' => 'title',
'dataType' => MagentoUiComponentFormElementDataTypeText::NAME,
'sortOrder' => $sortOrder,
'validation' => [
'required-entry' => true,
// 'no-whitespace' => true,
'validate-alphanum-with-spaces' => true
]
]
]
]
],
$options
);
}
}
All is ok, showing and saving, but saved values not appends, what is need to do?
magento2
add a comment |
What we have:
di.xml
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
UpgradeSchema.php
<?php
namespace SYConfiguratorSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface {
public function upgrade(
SchemaSetupInterface $setup,
ModuleContextInterface $context
){
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '0.0.3', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'option_sku',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'comment' => 'Sku'
]
);
}
$installer->endSetup();
}
}
Plugin:
class BundlePanel {
public function afterModifyMeta(
MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject,
$meta
){
$meta['bundle-items']['children']['bundle_options']['children']['record']['children']['product_bundle_container']['children']['option_info']['children']['option_sku'] = $this->getSkuFieldConfig(
11,
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'component' => 'Magento_Catalog/component/static-type-input',
'valueUpdate' => 'input',
'imports' => [
'optionId' => '${ $.provider }:${ $.parentScope }.option_id'
]
]
]
]
]
);
return $meta;
}
protected function getSkuFieldConfig($sortOrder, array $options = ){
return array_replace_recursive(
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'componentType' => MagentoUiComponentFormField::NAME,
'formElement' => MagentoUiComponentFormElementInput::NAME,
'dataScope' => 'option_sku',
// 'dataScope' => 'title',
'dataType' => MagentoUiComponentFormElementDataTypeText::NAME,
'sortOrder' => $sortOrder,
'validation' => [
'required-entry' => true,
// 'no-whitespace' => true,
'validate-alphanum-with-spaces' => true
]
]
]
]
],
$options
);
}
}
All is ok, showing and saving, but saved values not appends, what is need to do?
magento2
found solution magento.stackexchange.com/a/183583/48697
– Slava Yurthev
Oct 17 '17 at 7:31
add a comment |
What we have:
di.xml
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
UpgradeSchema.php
<?php
namespace SYConfiguratorSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface {
public function upgrade(
SchemaSetupInterface $setup,
ModuleContextInterface $context
){
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '0.0.3', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'option_sku',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'comment' => 'Sku'
]
);
}
$installer->endSetup();
}
}
Plugin:
class BundlePanel {
public function afterModifyMeta(
MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject,
$meta
){
$meta['bundle-items']['children']['bundle_options']['children']['record']['children']['product_bundle_container']['children']['option_info']['children']['option_sku'] = $this->getSkuFieldConfig(
11,
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'component' => 'Magento_Catalog/component/static-type-input',
'valueUpdate' => 'input',
'imports' => [
'optionId' => '${ $.provider }:${ $.parentScope }.option_id'
]
]
]
]
]
);
return $meta;
}
protected function getSkuFieldConfig($sortOrder, array $options = ){
return array_replace_recursive(
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'componentType' => MagentoUiComponentFormField::NAME,
'formElement' => MagentoUiComponentFormElementInput::NAME,
'dataScope' => 'option_sku',
// 'dataScope' => 'title',
'dataType' => MagentoUiComponentFormElementDataTypeText::NAME,
'sortOrder' => $sortOrder,
'validation' => [
'required-entry' => true,
// 'no-whitespace' => true,
'validate-alphanum-with-spaces' => true
]
]
]
]
],
$options
);
}
}
All is ok, showing and saving, but saved values not appends, what is need to do?
magento2
What we have:
di.xml
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
UpgradeSchema.php
<?php
namespace SYConfiguratorSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface {
public function upgrade(
SchemaSetupInterface $setup,
ModuleContextInterface $context
){
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '0.0.3', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'option_sku',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'comment' => 'Sku'
]
);
}
$installer->endSetup();
}
}
Plugin:
class BundlePanel {
public function afterModifyMeta(
MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject,
$meta
){
$meta['bundle-items']['children']['bundle_options']['children']['record']['children']['product_bundle_container']['children']['option_info']['children']['option_sku'] = $this->getSkuFieldConfig(
11,
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'component' => 'Magento_Catalog/component/static-type-input',
'valueUpdate' => 'input',
'imports' => [
'optionId' => '${ $.provider }:${ $.parentScope }.option_id'
]
]
]
]
]
);
return $meta;
}
protected function getSkuFieldConfig($sortOrder, array $options = ){
return array_replace_recursive(
[
'arguments' => [
'data' => [
'config' => [
'label' => __('Sku'),
'componentType' => MagentoUiComponentFormField::NAME,
'formElement' => MagentoUiComponentFormElementInput::NAME,
'dataScope' => 'option_sku',
// 'dataScope' => 'title',
'dataType' => MagentoUiComponentFormElementDataTypeText::NAME,
'sortOrder' => $sortOrder,
'validation' => [
'required-entry' => true,
// 'no-whitespace' => true,
'validate-alphanum-with-spaces' => true
]
]
]
]
],
$options
);
}
}
All is ok, showing and saving, but saved values not appends, what is need to do?
magento2
magento2
asked Oct 17 '17 at 7:21
Slava YurthevSlava Yurthev
628
628
found solution magento.stackexchange.com/a/183583/48697
– Slava Yurthev
Oct 17 '17 at 7:31
add a comment |
found solution magento.stackexchange.com/a/183583/48697
– Slava Yurthev
Oct 17 '17 at 7:31
found solution magento.stackexchange.com/a/183583/48697
– Slava Yurthev
Oct 17 '17 at 7:31
found solution magento.stackexchange.com/a/183583/48697
– Slava Yurthev
Oct 17 '17 at 7:31
add a comment |
2 Answers
2
active
oldest
votes
You need to rewrite class:
MagentoBundleUiDataProviderProductFormModifierComposite
Look at method name modifyData and find below code:
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS]
Please add your custom field key 'option_sku' to above array
Please follow below step
1) crete di.xml file at SY/Configurator/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="SYConfiguratorUiDataProviderProductFormModifierComposite" />
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
</config>
2) create Composite.php file at
SY/Configurator/Ui/DataProvider/Product/Form/Modifier/Composite.php
<?php
namespace SYConfiguratorUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite {
public function modifyData(array $data) {
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
$extra_options = $this->getEtra_attributes($product);
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool) $integerQty ? (int) $productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool) $integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'option_sku' => $extra_options[$option->getOptionId()]['option_sku'],
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
public function getEtra_attributes($product) {
$optionArray = array();
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $_objectManager->get('MagentoCatalogModelProduct')->load($product->getId());
$optionsCollection = $product->getTypeInstance(true)
->getOptionsCollection($product);
foreach ($optionsCollection as $options) {
$optionArray[$options->getOptionId()]['option_sku'] = $options->getMaximumQuantity();
}
return $optionArray;
}
}
Code can be little bit improved. Please refer below answer.
– Oshan
Aug 16 '18 at 12:46
add a comment |
1) Create plugin, preferences in app/code/ABC/Product/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_addtional_options" type="ABCProductPluginBundleUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="ABCProductUiDataProviderProductFormModifierComposite"/>
<preference for="MagentoBundleModelProductOptionList" type="ABCProductModelBundleProductOptionList"/>
</config>
2) Plugin will be as follows ABC/Product/Plugin/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php
<?php
namespace ABCProductPluginBundleUiDataProviderProductFormModifier;
use MagentoUiComponentForm;;
class BundlePanel
{
/**
* @param MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject
* @param $meta
* @return mixed
*/
public function afterModifyMeta(MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject, $meta)
{
$fieldSet = [
'min_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Min Qty',
'dataScope' => 'min_qty',
'sortOrder' => 40
],
'max_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Max Qty',
'dataScope' => 'max_qty',
'sortOrder' => 45
],
'is_lease_machine' => [
'dataType' => FormElementDataTypeBoolean::NAME,
'formElement' => FormElementSelect::NAME,
'label' => 'Is Lease Machine',
'dataScope' => 'is_lease_machine',
'sortOrder' => 50,
'options' => [
[
'label' => __('No'),
'value' => 0
],
[
'label' => __('Yes'),
'value' => 1
],
],
],
];
foreach ($fieldSet as $filed => $fieldOptions)
{
$meta['bundle-items']['children']['bundle_options']['children']
['record']['children']['product_bundle_container']['children']['option_info']['children'][$filed] = $this->getSelectionCustomText($fieldOptions);
}
return $meta;
}
/**
* @param $fieldOptions
* @return array
*/
protected function getSelectionCustomText($fieldOptions)
{
return [
'arguments' => [
'data' => [
'config' => [
'componentType' => FormField::NAME,
'dataType' => $fieldOptions['dataType'],
'formElement' => $fieldOptions['formElement'],
'label' => __($fieldOptions['label']),
'dataScope' => $fieldOptions['dataScope'],
'sortOrder' => $fieldOptions['sortOrder'],
'options' => array_key_exists('options', $fieldOptions) ? $fieldOptions['options']: "",
]
]
]
];
}
}
3) Preference 1 as follows (to save data):
<?php
namespace ABCProductUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite
{
public function modifyData(array $data)
{
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool)$integerQty ? (int)$productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool)$integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'min_qty' => $option->getMinQty(), //new field
'max_qty' => $option->getMaxQty(), //new field
'is_lease_machine' => $option->getIsLeaseMachine(), //new field
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
}
4) Preference 2 as follows (to retrieve data):
<?php
namespace ABCProductModelBundleProduct;
class OptionList extends MagentoBundleModelProductOptionList
{
/**
* @param MagentoCatalogApiDataProductInterface $product
* @return MagentoBundleApiDataOptionInterface
*/
public function getItems(MagentoCatalogApiDataProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$this->extensionAttributesJoinProcessor->process($optionCollection);
$optionList = ;
/** @var MagentoBundleModelOption $option */
foreach ($optionCollection as $option) {
$productLinks = $this->linkList->getItems($product, $option->getOptionId());
/** @var MagentoBundleApiDataOptionInterface $optionDataObject */
$optionDataObject = $this->optionFactory->create();
$this->dataObjectHelper->populateWithArray(
$optionDataObject,
$option->getData(),
MagentoBundleApiDataOptionInterface::class
);
$optionDataObject->setOptionId($option->getOptionId())
->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())
->setDefaultTitle($option->getDefaultTitle())
->setSku($product->getSku())
->setMinQty($option->getMinQty()) // retrieve "min_qty" from db
->setMaxQty($option->getMaxQty()) // retrieve "max_qty" from db
->setIsLeaseMachine($option->getIsLeaseMachine()) // retrieve "is_lease_machine" from db
->setProductLinks($productLinks);
$optionList = $optionDataObject;
}
return $optionList;
}
}
5) To create columns named "min_qty, max_qty, is_machine_lease" can use UpgradeSchema as follows.
<?php
namespace ABCProductSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.4', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'min_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Minimum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'max_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Maximum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'is_lease_machine',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
'length' => 1,
'unsigned' => true,
'nullable' => true,
'default' => 0,
'comment' => 'Is Lease Machine'
]
);
}
$installer->endSetup();
}
}
Output will be shown as follows.

For me save in db and display in backend this custom value were not working. after lot of research i found that in setup script you have mentioned wrong table instead of this 'catalog_product_bundle_selection' need to use this table 'catalog_product_bundle_option' and all worked fine. Thanks for help.
– Dhaval Solanki
yesterday
@DhavalSolanki: Thank you for pointing this out. Answer updated.
– Oshan
8 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f197549%2fmagento-2-bundle-custom-option-new-field-not-show-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to rewrite class:
MagentoBundleUiDataProviderProductFormModifierComposite
Look at method name modifyData and find below code:
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS]
Please add your custom field key 'option_sku' to above array
Please follow below step
1) crete di.xml file at SY/Configurator/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="SYConfiguratorUiDataProviderProductFormModifierComposite" />
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
</config>
2) create Composite.php file at
SY/Configurator/Ui/DataProvider/Product/Form/Modifier/Composite.php
<?php
namespace SYConfiguratorUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite {
public function modifyData(array $data) {
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
$extra_options = $this->getEtra_attributes($product);
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool) $integerQty ? (int) $productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool) $integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'option_sku' => $extra_options[$option->getOptionId()]['option_sku'],
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
public function getEtra_attributes($product) {
$optionArray = array();
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $_objectManager->get('MagentoCatalogModelProduct')->load($product->getId());
$optionsCollection = $product->getTypeInstance(true)
->getOptionsCollection($product);
foreach ($optionsCollection as $options) {
$optionArray[$options->getOptionId()]['option_sku'] = $options->getMaximumQuantity();
}
return $optionArray;
}
}
Code can be little bit improved. Please refer below answer.
– Oshan
Aug 16 '18 at 12:46
add a comment |
You need to rewrite class:
MagentoBundleUiDataProviderProductFormModifierComposite
Look at method name modifyData and find below code:
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS]
Please add your custom field key 'option_sku' to above array
Please follow below step
1) crete di.xml file at SY/Configurator/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="SYConfiguratorUiDataProviderProductFormModifierComposite" />
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
</config>
2) create Composite.php file at
SY/Configurator/Ui/DataProvider/Product/Form/Modifier/Composite.php
<?php
namespace SYConfiguratorUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite {
public function modifyData(array $data) {
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
$extra_options = $this->getEtra_attributes($product);
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool) $integerQty ? (int) $productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool) $integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'option_sku' => $extra_options[$option->getOptionId()]['option_sku'],
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
public function getEtra_attributes($product) {
$optionArray = array();
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $_objectManager->get('MagentoCatalogModelProduct')->load($product->getId());
$optionsCollection = $product->getTypeInstance(true)
->getOptionsCollection($product);
foreach ($optionsCollection as $options) {
$optionArray[$options->getOptionId()]['option_sku'] = $options->getMaximumQuantity();
}
return $optionArray;
}
}
Code can be little bit improved. Please refer below answer.
– Oshan
Aug 16 '18 at 12:46
add a comment |
You need to rewrite class:
MagentoBundleUiDataProviderProductFormModifierComposite
Look at method name modifyData and find below code:
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS]
Please add your custom field key 'option_sku' to above array
Please follow below step
1) crete di.xml file at SY/Configurator/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="SYConfiguratorUiDataProviderProductFormModifierComposite" />
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
</config>
2) create Composite.php file at
SY/Configurator/Ui/DataProvider/Product/Form/Modifier/Composite.php
<?php
namespace SYConfiguratorUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite {
public function modifyData(array $data) {
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
$extra_options = $this->getEtra_attributes($product);
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool) $integerQty ? (int) $productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool) $integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'option_sku' => $extra_options[$option->getOptionId()]['option_sku'],
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
public function getEtra_attributes($product) {
$optionArray = array();
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $_objectManager->get('MagentoCatalogModelProduct')->load($product->getId());
$optionsCollection = $product->getTypeInstance(true)
->getOptionsCollection($product);
foreach ($optionsCollection as $options) {
$optionArray[$options->getOptionId()]['option_sku'] = $options->getMaximumQuantity();
}
return $optionArray;
}
}
You need to rewrite class:
MagentoBundleUiDataProviderProductFormModifierComposite
Look at method name modifyData and find below code:
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS]
Please add your custom field key 'option_sku' to above array
Please follow below step
1) crete di.xml file at SY/Configurator/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="SYConfiguratorUiDataProviderProductFormModifierComposite" />
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_option_sku" type="SYConfiguratorPluginCatalogUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
</config>
2) create Composite.php file at
SY/Configurator/Ui/DataProvider/Product/Form/Modifier/Composite.php
<?php
namespace SYConfiguratorUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite {
public function modifyData(array $data) {
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
$extra_options = $this->getEtra_attributes($product);
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool) $integerQty ? (int) $productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool) $integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'option_sku' => $extra_options[$option->getOptionId()]['option_sku'],
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
public function getEtra_attributes($product) {
$optionArray = array();
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $_objectManager->get('MagentoCatalogModelProduct')->load($product->getId());
$optionsCollection = $product->getTypeInstance(true)
->getOptionsCollection($product);
foreach ($optionsCollection as $options) {
$optionArray[$options->getOptionId()]['option_sku'] = $options->getMaximumQuantity();
}
return $optionArray;
}
}
answered Dec 7 '17 at 11:02
Rajesh HothiRajesh Hothi
17616
17616
Code can be little bit improved. Please refer below answer.
– Oshan
Aug 16 '18 at 12:46
add a comment |
Code can be little bit improved. Please refer below answer.
– Oshan
Aug 16 '18 at 12:46
Code can be little bit improved. Please refer below answer.
– Oshan
Aug 16 '18 at 12:46
Code can be little bit improved. Please refer below answer.
– Oshan
Aug 16 '18 at 12:46
add a comment |
1) Create plugin, preferences in app/code/ABC/Product/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_addtional_options" type="ABCProductPluginBundleUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="ABCProductUiDataProviderProductFormModifierComposite"/>
<preference for="MagentoBundleModelProductOptionList" type="ABCProductModelBundleProductOptionList"/>
</config>
2) Plugin will be as follows ABC/Product/Plugin/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php
<?php
namespace ABCProductPluginBundleUiDataProviderProductFormModifier;
use MagentoUiComponentForm;;
class BundlePanel
{
/**
* @param MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject
* @param $meta
* @return mixed
*/
public function afterModifyMeta(MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject, $meta)
{
$fieldSet = [
'min_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Min Qty',
'dataScope' => 'min_qty',
'sortOrder' => 40
],
'max_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Max Qty',
'dataScope' => 'max_qty',
'sortOrder' => 45
],
'is_lease_machine' => [
'dataType' => FormElementDataTypeBoolean::NAME,
'formElement' => FormElementSelect::NAME,
'label' => 'Is Lease Machine',
'dataScope' => 'is_lease_machine',
'sortOrder' => 50,
'options' => [
[
'label' => __('No'),
'value' => 0
],
[
'label' => __('Yes'),
'value' => 1
],
],
],
];
foreach ($fieldSet as $filed => $fieldOptions)
{
$meta['bundle-items']['children']['bundle_options']['children']
['record']['children']['product_bundle_container']['children']['option_info']['children'][$filed] = $this->getSelectionCustomText($fieldOptions);
}
return $meta;
}
/**
* @param $fieldOptions
* @return array
*/
protected function getSelectionCustomText($fieldOptions)
{
return [
'arguments' => [
'data' => [
'config' => [
'componentType' => FormField::NAME,
'dataType' => $fieldOptions['dataType'],
'formElement' => $fieldOptions['formElement'],
'label' => __($fieldOptions['label']),
'dataScope' => $fieldOptions['dataScope'],
'sortOrder' => $fieldOptions['sortOrder'],
'options' => array_key_exists('options', $fieldOptions) ? $fieldOptions['options']: "",
]
]
]
];
}
}
3) Preference 1 as follows (to save data):
<?php
namespace ABCProductUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite
{
public function modifyData(array $data)
{
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool)$integerQty ? (int)$productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool)$integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'min_qty' => $option->getMinQty(), //new field
'max_qty' => $option->getMaxQty(), //new field
'is_lease_machine' => $option->getIsLeaseMachine(), //new field
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
}
4) Preference 2 as follows (to retrieve data):
<?php
namespace ABCProductModelBundleProduct;
class OptionList extends MagentoBundleModelProductOptionList
{
/**
* @param MagentoCatalogApiDataProductInterface $product
* @return MagentoBundleApiDataOptionInterface
*/
public function getItems(MagentoCatalogApiDataProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$this->extensionAttributesJoinProcessor->process($optionCollection);
$optionList = ;
/** @var MagentoBundleModelOption $option */
foreach ($optionCollection as $option) {
$productLinks = $this->linkList->getItems($product, $option->getOptionId());
/** @var MagentoBundleApiDataOptionInterface $optionDataObject */
$optionDataObject = $this->optionFactory->create();
$this->dataObjectHelper->populateWithArray(
$optionDataObject,
$option->getData(),
MagentoBundleApiDataOptionInterface::class
);
$optionDataObject->setOptionId($option->getOptionId())
->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())
->setDefaultTitle($option->getDefaultTitle())
->setSku($product->getSku())
->setMinQty($option->getMinQty()) // retrieve "min_qty" from db
->setMaxQty($option->getMaxQty()) // retrieve "max_qty" from db
->setIsLeaseMachine($option->getIsLeaseMachine()) // retrieve "is_lease_machine" from db
->setProductLinks($productLinks);
$optionList = $optionDataObject;
}
return $optionList;
}
}
5) To create columns named "min_qty, max_qty, is_machine_lease" can use UpgradeSchema as follows.
<?php
namespace ABCProductSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.4', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'min_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Minimum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'max_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Maximum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'is_lease_machine',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
'length' => 1,
'unsigned' => true,
'nullable' => true,
'default' => 0,
'comment' => 'Is Lease Machine'
]
);
}
$installer->endSetup();
}
}
Output will be shown as follows.

For me save in db and display in backend this custom value were not working. after lot of research i found that in setup script you have mentioned wrong table instead of this 'catalog_product_bundle_selection' need to use this table 'catalog_product_bundle_option' and all worked fine. Thanks for help.
– Dhaval Solanki
yesterday
@DhavalSolanki: Thank you for pointing this out. Answer updated.
– Oshan
8 mins ago
add a comment |
1) Create plugin, preferences in app/code/ABC/Product/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_addtional_options" type="ABCProductPluginBundleUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="ABCProductUiDataProviderProductFormModifierComposite"/>
<preference for="MagentoBundleModelProductOptionList" type="ABCProductModelBundleProductOptionList"/>
</config>
2) Plugin will be as follows ABC/Product/Plugin/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php
<?php
namespace ABCProductPluginBundleUiDataProviderProductFormModifier;
use MagentoUiComponentForm;;
class BundlePanel
{
/**
* @param MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject
* @param $meta
* @return mixed
*/
public function afterModifyMeta(MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject, $meta)
{
$fieldSet = [
'min_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Min Qty',
'dataScope' => 'min_qty',
'sortOrder' => 40
],
'max_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Max Qty',
'dataScope' => 'max_qty',
'sortOrder' => 45
],
'is_lease_machine' => [
'dataType' => FormElementDataTypeBoolean::NAME,
'formElement' => FormElementSelect::NAME,
'label' => 'Is Lease Machine',
'dataScope' => 'is_lease_machine',
'sortOrder' => 50,
'options' => [
[
'label' => __('No'),
'value' => 0
],
[
'label' => __('Yes'),
'value' => 1
],
],
],
];
foreach ($fieldSet as $filed => $fieldOptions)
{
$meta['bundle-items']['children']['bundle_options']['children']
['record']['children']['product_bundle_container']['children']['option_info']['children'][$filed] = $this->getSelectionCustomText($fieldOptions);
}
return $meta;
}
/**
* @param $fieldOptions
* @return array
*/
protected function getSelectionCustomText($fieldOptions)
{
return [
'arguments' => [
'data' => [
'config' => [
'componentType' => FormField::NAME,
'dataType' => $fieldOptions['dataType'],
'formElement' => $fieldOptions['formElement'],
'label' => __($fieldOptions['label']),
'dataScope' => $fieldOptions['dataScope'],
'sortOrder' => $fieldOptions['sortOrder'],
'options' => array_key_exists('options', $fieldOptions) ? $fieldOptions['options']: "",
]
]
]
];
}
}
3) Preference 1 as follows (to save data):
<?php
namespace ABCProductUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite
{
public function modifyData(array $data)
{
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool)$integerQty ? (int)$productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool)$integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'min_qty' => $option->getMinQty(), //new field
'max_qty' => $option->getMaxQty(), //new field
'is_lease_machine' => $option->getIsLeaseMachine(), //new field
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
}
4) Preference 2 as follows (to retrieve data):
<?php
namespace ABCProductModelBundleProduct;
class OptionList extends MagentoBundleModelProductOptionList
{
/**
* @param MagentoCatalogApiDataProductInterface $product
* @return MagentoBundleApiDataOptionInterface
*/
public function getItems(MagentoCatalogApiDataProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$this->extensionAttributesJoinProcessor->process($optionCollection);
$optionList = ;
/** @var MagentoBundleModelOption $option */
foreach ($optionCollection as $option) {
$productLinks = $this->linkList->getItems($product, $option->getOptionId());
/** @var MagentoBundleApiDataOptionInterface $optionDataObject */
$optionDataObject = $this->optionFactory->create();
$this->dataObjectHelper->populateWithArray(
$optionDataObject,
$option->getData(),
MagentoBundleApiDataOptionInterface::class
);
$optionDataObject->setOptionId($option->getOptionId())
->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())
->setDefaultTitle($option->getDefaultTitle())
->setSku($product->getSku())
->setMinQty($option->getMinQty()) // retrieve "min_qty" from db
->setMaxQty($option->getMaxQty()) // retrieve "max_qty" from db
->setIsLeaseMachine($option->getIsLeaseMachine()) // retrieve "is_lease_machine" from db
->setProductLinks($productLinks);
$optionList = $optionDataObject;
}
return $optionList;
}
}
5) To create columns named "min_qty, max_qty, is_machine_lease" can use UpgradeSchema as follows.
<?php
namespace ABCProductSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.4', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'min_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Minimum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'max_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Maximum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'is_lease_machine',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
'length' => 1,
'unsigned' => true,
'nullable' => true,
'default' => 0,
'comment' => 'Is Lease Machine'
]
);
}
$installer->endSetup();
}
}
Output will be shown as follows.

For me save in db and display in backend this custom value were not working. after lot of research i found that in setup script you have mentioned wrong table instead of this 'catalog_product_bundle_selection' need to use this table 'catalog_product_bundle_option' and all worked fine. Thanks for help.
– Dhaval Solanki
yesterday
@DhavalSolanki: Thank you for pointing this out. Answer updated.
– Oshan
8 mins ago
add a comment |
1) Create plugin, preferences in app/code/ABC/Product/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_addtional_options" type="ABCProductPluginBundleUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="ABCProductUiDataProviderProductFormModifierComposite"/>
<preference for="MagentoBundleModelProductOptionList" type="ABCProductModelBundleProductOptionList"/>
</config>
2) Plugin will be as follows ABC/Product/Plugin/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php
<?php
namespace ABCProductPluginBundleUiDataProviderProductFormModifier;
use MagentoUiComponentForm;;
class BundlePanel
{
/**
* @param MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject
* @param $meta
* @return mixed
*/
public function afterModifyMeta(MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject, $meta)
{
$fieldSet = [
'min_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Min Qty',
'dataScope' => 'min_qty',
'sortOrder' => 40
],
'max_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Max Qty',
'dataScope' => 'max_qty',
'sortOrder' => 45
],
'is_lease_machine' => [
'dataType' => FormElementDataTypeBoolean::NAME,
'formElement' => FormElementSelect::NAME,
'label' => 'Is Lease Machine',
'dataScope' => 'is_lease_machine',
'sortOrder' => 50,
'options' => [
[
'label' => __('No'),
'value' => 0
],
[
'label' => __('Yes'),
'value' => 1
],
],
],
];
foreach ($fieldSet as $filed => $fieldOptions)
{
$meta['bundle-items']['children']['bundle_options']['children']
['record']['children']['product_bundle_container']['children']['option_info']['children'][$filed] = $this->getSelectionCustomText($fieldOptions);
}
return $meta;
}
/**
* @param $fieldOptions
* @return array
*/
protected function getSelectionCustomText($fieldOptions)
{
return [
'arguments' => [
'data' => [
'config' => [
'componentType' => FormField::NAME,
'dataType' => $fieldOptions['dataType'],
'formElement' => $fieldOptions['formElement'],
'label' => __($fieldOptions['label']),
'dataScope' => $fieldOptions['dataScope'],
'sortOrder' => $fieldOptions['sortOrder'],
'options' => array_key_exists('options', $fieldOptions) ? $fieldOptions['options']: "",
]
]
]
];
}
}
3) Preference 1 as follows (to save data):
<?php
namespace ABCProductUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite
{
public function modifyData(array $data)
{
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool)$integerQty ? (int)$productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool)$integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'min_qty' => $option->getMinQty(), //new field
'max_qty' => $option->getMaxQty(), //new field
'is_lease_machine' => $option->getIsLeaseMachine(), //new field
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
}
4) Preference 2 as follows (to retrieve data):
<?php
namespace ABCProductModelBundleProduct;
class OptionList extends MagentoBundleModelProductOptionList
{
/**
* @param MagentoCatalogApiDataProductInterface $product
* @return MagentoBundleApiDataOptionInterface
*/
public function getItems(MagentoCatalogApiDataProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$this->extensionAttributesJoinProcessor->process($optionCollection);
$optionList = ;
/** @var MagentoBundleModelOption $option */
foreach ($optionCollection as $option) {
$productLinks = $this->linkList->getItems($product, $option->getOptionId());
/** @var MagentoBundleApiDataOptionInterface $optionDataObject */
$optionDataObject = $this->optionFactory->create();
$this->dataObjectHelper->populateWithArray(
$optionDataObject,
$option->getData(),
MagentoBundleApiDataOptionInterface::class
);
$optionDataObject->setOptionId($option->getOptionId())
->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())
->setDefaultTitle($option->getDefaultTitle())
->setSku($product->getSku())
->setMinQty($option->getMinQty()) // retrieve "min_qty" from db
->setMaxQty($option->getMaxQty()) // retrieve "max_qty" from db
->setIsLeaseMachine($option->getIsLeaseMachine()) // retrieve "is_lease_machine" from db
->setProductLinks($productLinks);
$optionList = $optionDataObject;
}
return $optionList;
}
}
5) To create columns named "min_qty, max_qty, is_machine_lease" can use UpgradeSchema as follows.
<?php
namespace ABCProductSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.4', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'min_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Minimum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'max_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Maximum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'is_lease_machine',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
'length' => 1,
'unsigned' => true,
'nullable' => true,
'default' => 0,
'comment' => 'Is Lease Machine'
]
);
}
$installer->endSetup();
}
}
Output will be shown as follows.

1) Create plugin, preferences in app/code/ABC/Product/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoBundleUiDataProviderProductFormModifierBundlePanel">
<plugin name="bundle_addtional_options" type="ABCProductPluginBundleUiDataProviderProductFormModifierBundlePanel" sortOrder="1000"/>
</type>
<preference for="MagentoBundleUiDataProviderProductFormModifierComposite" type="ABCProductUiDataProviderProductFormModifierComposite"/>
<preference for="MagentoBundleModelProductOptionList" type="ABCProductModelBundleProductOptionList"/>
</config>
2) Plugin will be as follows ABC/Product/Plugin/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php
<?php
namespace ABCProductPluginBundleUiDataProviderProductFormModifier;
use MagentoUiComponentForm;;
class BundlePanel
{
/**
* @param MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject
* @param $meta
* @return mixed
*/
public function afterModifyMeta(MagentoBundleUiDataProviderProductFormModifierBundlePanel $subject, $meta)
{
$fieldSet = [
'min_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Min Qty',
'dataScope' => 'min_qty',
'sortOrder' => 40
],
'max_qty' => [
'dataType' => FormElementDataTypeNumber::NAME,
'formElement' => FormElementInput::NAME,
'label' => 'Max Qty',
'dataScope' => 'max_qty',
'sortOrder' => 45
],
'is_lease_machine' => [
'dataType' => FormElementDataTypeBoolean::NAME,
'formElement' => FormElementSelect::NAME,
'label' => 'Is Lease Machine',
'dataScope' => 'is_lease_machine',
'sortOrder' => 50,
'options' => [
[
'label' => __('No'),
'value' => 0
],
[
'label' => __('Yes'),
'value' => 1
],
],
],
];
foreach ($fieldSet as $filed => $fieldOptions)
{
$meta['bundle-items']['children']['bundle_options']['children']
['record']['children']['product_bundle_container']['children']['option_info']['children'][$filed] = $this->getSelectionCustomText($fieldOptions);
}
return $meta;
}
/**
* @param $fieldOptions
* @return array
*/
protected function getSelectionCustomText($fieldOptions)
{
return [
'arguments' => [
'data' => [
'config' => [
'componentType' => FormField::NAME,
'dataType' => $fieldOptions['dataType'],
'formElement' => $fieldOptions['formElement'],
'label' => __($fieldOptions['label']),
'dataScope' => $fieldOptions['dataScope'],
'sortOrder' => $fieldOptions['sortOrder'],
'options' => array_key_exists('options', $fieldOptions) ? $fieldOptions['options']: "",
]
]
]
];
}
}
3) Preference 1 as follows (to save data):
<?php
namespace ABCProductUiDataProviderProductFormModifier;
use MagentoBundleModelProductType;
use MagentoBundleUiDataProviderProductFormModifierBundlePanel;
class Composite extends MagentoBundleUiDataProviderProductFormModifierComposite
{
public function modifyData(array $data)
{
/** @var MagentoCatalogApiDataProductInterface $product */
$product = $this->locator->getProduct();
$modelId = $product->getId();
$isBundleProduct = $product->getTypeId() === Type::TYPE_CODE;
if ($isBundleProduct && $modelId) {
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = ;
/** @var MagentoBundleApiDataOptionInterface $option */
foreach ($this->optionsRepository->getList($product->getSku()) as $option) {
$selections = ;
foreach ($option->getProductLinks() as $productLink) {
$linkedProduct = $this->productRepository->get($productLink->getSku());
$integerQty = 1;
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
$integerQty = 0;
}
}
$selections = [
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
'selection_price_type' => $productLink->getPriceType(),
'selection_qty' => (bool)$integerQty ? (int)$productLink->getQty() : $productLink->getQty(),
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
'selection_qty_is_integer' => (bool)$integerQty,
'position' => $productLink->getPosition(),
'delete' => '',
];
}
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS] = [
'position' => $option->getPosition(),
'option_id' => $option->getOptionId(),
'title' => $option->getTitle(),
'min_qty' => $option->getMinQty(), //new field
'max_qty' => $option->getMaxQty(), //new field
'is_lease_machine' => $option->getIsLeaseMachine(), //new field
'default_title' => $option->getDefaultTitle(),
'type' => $option->getType(),
'required' => ($option->getRequired()) ? '1' : '0',
'bundle_selections' => $selections,
];
}
}
return $data;
}
}
4) Preference 2 as follows (to retrieve data):
<?php
namespace ABCProductModelBundleProduct;
class OptionList extends MagentoBundleModelProductOptionList
{
/**
* @param MagentoCatalogApiDataProductInterface $product
* @return MagentoBundleApiDataOptionInterface
*/
public function getItems(MagentoCatalogApiDataProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$this->extensionAttributesJoinProcessor->process($optionCollection);
$optionList = ;
/** @var MagentoBundleModelOption $option */
foreach ($optionCollection as $option) {
$productLinks = $this->linkList->getItems($product, $option->getOptionId());
/** @var MagentoBundleApiDataOptionInterface $optionDataObject */
$optionDataObject = $this->optionFactory->create();
$this->dataObjectHelper->populateWithArray(
$optionDataObject,
$option->getData(),
MagentoBundleApiDataOptionInterface::class
);
$optionDataObject->setOptionId($option->getOptionId())
->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())
->setDefaultTitle($option->getDefaultTitle())
->setSku($product->getSku())
->setMinQty($option->getMinQty()) // retrieve "min_qty" from db
->setMaxQty($option->getMaxQty()) // retrieve "max_qty" from db
->setIsLeaseMachine($option->getIsLeaseMachine()) // retrieve "is_lease_machine" from db
->setProductLinks($productLinks);
$optionList = $optionDataObject;
}
return $optionList;
}
}
5) To create columns named "min_qty, max_qty, is_machine_lease" can use UpgradeSchema as follows.
<?php
namespace ABCProductSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.4', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'min_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Minimum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'max_qty',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'default' => null,
'comment' => 'Maximum Qty'
]
);
$installer->getConnection()->addColumn(
$installer->getTable('catalog_product_bundle_option'),
'is_lease_machine',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
'length' => 1,
'unsigned' => true,
'nullable' => true,
'default' => 0,
'comment' => 'Is Lease Machine'
]
);
}
$installer->endSetup();
}
}
Output will be shown as follows.

edited 6 mins ago
answered Aug 16 '18 at 13:00
OshanOshan
1,4241920
1,4241920
For me save in db and display in backend this custom value were not working. after lot of research i found that in setup script you have mentioned wrong table instead of this 'catalog_product_bundle_selection' need to use this table 'catalog_product_bundle_option' and all worked fine. Thanks for help.
– Dhaval Solanki
yesterday
@DhavalSolanki: Thank you for pointing this out. Answer updated.
– Oshan
8 mins ago
add a comment |
For me save in db and display in backend this custom value were not working. after lot of research i found that in setup script you have mentioned wrong table instead of this 'catalog_product_bundle_selection' need to use this table 'catalog_product_bundle_option' and all worked fine. Thanks for help.
– Dhaval Solanki
yesterday
@DhavalSolanki: Thank you for pointing this out. Answer updated.
– Oshan
8 mins ago
For me save in db and display in backend this custom value were not working. after lot of research i found that in setup script you have mentioned wrong table instead of this 'catalog_product_bundle_selection' need to use this table 'catalog_product_bundle_option' and all worked fine. Thanks for help.
– Dhaval Solanki
yesterday
For me save in db and display in backend this custom value were not working. after lot of research i found that in setup script you have mentioned wrong table instead of this 'catalog_product_bundle_selection' need to use this table 'catalog_product_bundle_option' and all worked fine. Thanks for help.
– Dhaval Solanki
yesterday
@DhavalSolanki: Thank you for pointing this out. Answer updated.
– Oshan
8 mins ago
@DhavalSolanki: Thank you for pointing this out. Answer updated.
– Oshan
8 mins ago
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f197549%2fmagento-2-bundle-custom-option-new-field-not-show-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
found solution magento.stackexchange.com/a/183583/48697
– Slava Yurthev
Oct 17 '17 at 7:31