How To Add Custom Data Into Product Edit Form DynamicRows Ui Component
I need to know how to populate a dynamicRows ui component I have added to the product edit form in Magento 2.
I've got the data coming from a custom table and the data is getting through. I have the dynamic rows component in the correct place in the advanced pricing modal but the dynamicRows records are not being rendered. Here's my code:
DataProvider.php
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
$this->loadedData = array();
/** @var CustomerGroupsPrice $customerGroupsPrice */
foreach ($items as $customerGroupsPrice) {
$this->loadedData[$customerGroupsPrice->getProductId()]['customer_groups_special_prices_form'] = $customerGroupsPrice->getData();
}
//var_dump($this->loadedData);exit;
return $this->loadedData;
}
public function getMeta()
{
return $this->meta;
}
customer_groups_prices_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="namespace" xsi:type="string">customer_groups_special_prices_form</item>
</item>
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">data</item>
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
</item>
</argument>
<dataSource name="customer_groups_special_prices_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">IcanseeCustomerGroupsPricesModelDataProvider</argument>
<argument name="name" xsi:type="string">customer_groups_special_prices_form_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">product_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</argument>
</dataSource>
modifyMeta function in my modifier class:
public function modifyMeta(array $meta)
{
$meta = array_merge_recursive(
$meta, [
'advanced_pricing_modal' => [
'children' => [
'customer_groups_prices_form' => [
'arguments' => [
'data' => [
'config' => [
'label' => __('Customer Group Special Prices'),
'componentType' => Fieldset::NAME,
'dataScope' => 'customer_group_special_prices_form',
'collapsible' => false,
'sortOrder' => 50,
],
],
],
'children' => [
self::CUSTOMER_GROUP_SPECIAL_PRICES_FIELD => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'dynamicRows',
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows',
'label' => __('Group Special Prices'),
'renderDefaultRecord' => false,
'ns' => 'customer_group_special_prices_form',
'externalProvider' => 'customer_groups_special_prices_form.customer_groups_special_prices_form_data_source',
'imports' => [
'productId' => '${ $.provider }:data.entity_id',
],
'exports' => [
'productId' => '${ $.externalProvider }:params.product_id'
],
'dataScope' => '',
'dndConfig' => [
'enabled' => false,
],
'deleteProperty' => false,
'disabled' => false,
'required' => false,
'additionalClasses' => 'admin__field-wide',
'sortOrder' => 50,
],
],
],
'children' => [
'record' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => Container::NAME,
'isTemplate' => true,
'is_collection' => true,
'component' => 'Magento_Ui/js/dynamic-rows/record',
'dataScope' => 'data.customer_group_special_prices_form',
],
],
],
'children' => [
'entity_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'entity_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 10,
],
],
],
],
'product_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'product_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 20,
],
],
],
],
'website_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataScope' => 'website_id',
'label' => __('Website'),
'options' => $this->getWebsites(),
'visible' => $this->isMultiWebsites(),
'disabled' => ($this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite()),
'sortOrder' => 30,
],
],
],
],
'customer_group_id' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataType' => Text::NAME,
'dataScope' => 'customer_group_id',
'label' => __('Customer Group'),
'options' => $this->getCustomerGroups(),
'sortOrder' => 40,
],
],
],
],
'price' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataType' => Number::NAME,
'label' => __('Price'),
'dataScope' => 'price',
'sortOrder' => 50,
'validation' => [
'required-entry' => true,
'validate-greater-than-zero' => true,
'validate-digits' => false,
'validate-number' => true,
],
],
],
],
],
'actionDelete' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'actionDelete',
'dataType' => Text::NAME,
'label' => '',
'sortOrder' => 60,
],
],
],
],
],
],
]
]
]
]
]
]
]
);
return $meta;
}
di.xml excerpt:
<virtualType name="CustomerGroupsPricesFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="CustomerGroupsPricesDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">CustomerGroupsPricesFilterPool</argument>
</arguments>
</virtualType>
<type name="IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection">
<arguments>
<argument name="mainTable" xsi:type="string">ics_customer_groups_price</argument>
<argument name="eventPrefix" xsi:type="string">customer_groups_special_prices_form_grid_collection</argument>
<argument name="eventObject" xsi:type="string">customer_groups_special_prices_grid_collection</argument>
<argument name="resourceModel" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupsPrice</argument>
</arguments>
</type>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="customer_groups_special_prices_form_data_source" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupGridCollection</item>
</argument>
</arguments>
</type>
The data from the custom database table comes through when I var_dump it from the data provider class, the issue is that the records of the dynamicRows are not being rendered, so there is something missing to link the datasource/data to the ui component. What am I missing?
uicomponent adminform data-provider dynamic-rows modifier
add a comment |
I need to know how to populate a dynamicRows ui component I have added to the product edit form in Magento 2.
I've got the data coming from a custom table and the data is getting through. I have the dynamic rows component in the correct place in the advanced pricing modal but the dynamicRows records are not being rendered. Here's my code:
DataProvider.php
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
$this->loadedData = array();
/** @var CustomerGroupsPrice $customerGroupsPrice */
foreach ($items as $customerGroupsPrice) {
$this->loadedData[$customerGroupsPrice->getProductId()]['customer_groups_special_prices_form'] = $customerGroupsPrice->getData();
}
//var_dump($this->loadedData);exit;
return $this->loadedData;
}
public function getMeta()
{
return $this->meta;
}
customer_groups_prices_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="namespace" xsi:type="string">customer_groups_special_prices_form</item>
</item>
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">data</item>
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
</item>
</argument>
<dataSource name="customer_groups_special_prices_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">IcanseeCustomerGroupsPricesModelDataProvider</argument>
<argument name="name" xsi:type="string">customer_groups_special_prices_form_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">product_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</argument>
</dataSource>
modifyMeta function in my modifier class:
public function modifyMeta(array $meta)
{
$meta = array_merge_recursive(
$meta, [
'advanced_pricing_modal' => [
'children' => [
'customer_groups_prices_form' => [
'arguments' => [
'data' => [
'config' => [
'label' => __('Customer Group Special Prices'),
'componentType' => Fieldset::NAME,
'dataScope' => 'customer_group_special_prices_form',
'collapsible' => false,
'sortOrder' => 50,
],
],
],
'children' => [
self::CUSTOMER_GROUP_SPECIAL_PRICES_FIELD => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'dynamicRows',
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows',
'label' => __('Group Special Prices'),
'renderDefaultRecord' => false,
'ns' => 'customer_group_special_prices_form',
'externalProvider' => 'customer_groups_special_prices_form.customer_groups_special_prices_form_data_source',
'imports' => [
'productId' => '${ $.provider }:data.entity_id',
],
'exports' => [
'productId' => '${ $.externalProvider }:params.product_id'
],
'dataScope' => '',
'dndConfig' => [
'enabled' => false,
],
'deleteProperty' => false,
'disabled' => false,
'required' => false,
'additionalClasses' => 'admin__field-wide',
'sortOrder' => 50,
],
],
],
'children' => [
'record' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => Container::NAME,
'isTemplate' => true,
'is_collection' => true,
'component' => 'Magento_Ui/js/dynamic-rows/record',
'dataScope' => 'data.customer_group_special_prices_form',
],
],
],
'children' => [
'entity_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'entity_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 10,
],
],
],
],
'product_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'product_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 20,
],
],
],
],
'website_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataScope' => 'website_id',
'label' => __('Website'),
'options' => $this->getWebsites(),
'visible' => $this->isMultiWebsites(),
'disabled' => ($this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite()),
'sortOrder' => 30,
],
],
],
],
'customer_group_id' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataType' => Text::NAME,
'dataScope' => 'customer_group_id',
'label' => __('Customer Group'),
'options' => $this->getCustomerGroups(),
'sortOrder' => 40,
],
],
],
],
'price' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataType' => Number::NAME,
'label' => __('Price'),
'dataScope' => 'price',
'sortOrder' => 50,
'validation' => [
'required-entry' => true,
'validate-greater-than-zero' => true,
'validate-digits' => false,
'validate-number' => true,
],
],
],
],
],
'actionDelete' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'actionDelete',
'dataType' => Text::NAME,
'label' => '',
'sortOrder' => 60,
],
],
],
],
],
],
]
]
]
]
]
]
]
);
return $meta;
}
di.xml excerpt:
<virtualType name="CustomerGroupsPricesFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="CustomerGroupsPricesDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">CustomerGroupsPricesFilterPool</argument>
</arguments>
</virtualType>
<type name="IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection">
<arguments>
<argument name="mainTable" xsi:type="string">ics_customer_groups_price</argument>
<argument name="eventPrefix" xsi:type="string">customer_groups_special_prices_form_grid_collection</argument>
<argument name="eventObject" xsi:type="string">customer_groups_special_prices_grid_collection</argument>
<argument name="resourceModel" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupsPrice</argument>
</arguments>
</type>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="customer_groups_special_prices_form_data_source" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupGridCollection</item>
</argument>
</arguments>
</type>
The data from the custom database table comes through when I var_dump it from the data provider class, the issue is that the records of the dynamicRows are not being rendered, so there is something missing to link the datasource/data to the ui component. What am I missing?
uicomponent adminform data-provider dynamic-rows modifier
add a comment |
I need to know how to populate a dynamicRows ui component I have added to the product edit form in Magento 2.
I've got the data coming from a custom table and the data is getting through. I have the dynamic rows component in the correct place in the advanced pricing modal but the dynamicRows records are not being rendered. Here's my code:
DataProvider.php
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
$this->loadedData = array();
/** @var CustomerGroupsPrice $customerGroupsPrice */
foreach ($items as $customerGroupsPrice) {
$this->loadedData[$customerGroupsPrice->getProductId()]['customer_groups_special_prices_form'] = $customerGroupsPrice->getData();
}
//var_dump($this->loadedData);exit;
return $this->loadedData;
}
public function getMeta()
{
return $this->meta;
}
customer_groups_prices_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="namespace" xsi:type="string">customer_groups_special_prices_form</item>
</item>
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">data</item>
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
</item>
</argument>
<dataSource name="customer_groups_special_prices_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">IcanseeCustomerGroupsPricesModelDataProvider</argument>
<argument name="name" xsi:type="string">customer_groups_special_prices_form_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">product_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</argument>
</dataSource>
modifyMeta function in my modifier class:
public function modifyMeta(array $meta)
{
$meta = array_merge_recursive(
$meta, [
'advanced_pricing_modal' => [
'children' => [
'customer_groups_prices_form' => [
'arguments' => [
'data' => [
'config' => [
'label' => __('Customer Group Special Prices'),
'componentType' => Fieldset::NAME,
'dataScope' => 'customer_group_special_prices_form',
'collapsible' => false,
'sortOrder' => 50,
],
],
],
'children' => [
self::CUSTOMER_GROUP_SPECIAL_PRICES_FIELD => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'dynamicRows',
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows',
'label' => __('Group Special Prices'),
'renderDefaultRecord' => false,
'ns' => 'customer_group_special_prices_form',
'externalProvider' => 'customer_groups_special_prices_form.customer_groups_special_prices_form_data_source',
'imports' => [
'productId' => '${ $.provider }:data.entity_id',
],
'exports' => [
'productId' => '${ $.externalProvider }:params.product_id'
],
'dataScope' => '',
'dndConfig' => [
'enabled' => false,
],
'deleteProperty' => false,
'disabled' => false,
'required' => false,
'additionalClasses' => 'admin__field-wide',
'sortOrder' => 50,
],
],
],
'children' => [
'record' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => Container::NAME,
'isTemplate' => true,
'is_collection' => true,
'component' => 'Magento_Ui/js/dynamic-rows/record',
'dataScope' => 'data.customer_group_special_prices_form',
],
],
],
'children' => [
'entity_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'entity_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 10,
],
],
],
],
'product_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'product_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 20,
],
],
],
],
'website_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataScope' => 'website_id',
'label' => __('Website'),
'options' => $this->getWebsites(),
'visible' => $this->isMultiWebsites(),
'disabled' => ($this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite()),
'sortOrder' => 30,
],
],
],
],
'customer_group_id' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataType' => Text::NAME,
'dataScope' => 'customer_group_id',
'label' => __('Customer Group'),
'options' => $this->getCustomerGroups(),
'sortOrder' => 40,
],
],
],
],
'price' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataType' => Number::NAME,
'label' => __('Price'),
'dataScope' => 'price',
'sortOrder' => 50,
'validation' => [
'required-entry' => true,
'validate-greater-than-zero' => true,
'validate-digits' => false,
'validate-number' => true,
],
],
],
],
],
'actionDelete' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'actionDelete',
'dataType' => Text::NAME,
'label' => '',
'sortOrder' => 60,
],
],
],
],
],
],
]
]
]
]
]
]
]
);
return $meta;
}
di.xml excerpt:
<virtualType name="CustomerGroupsPricesFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="CustomerGroupsPricesDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">CustomerGroupsPricesFilterPool</argument>
</arguments>
</virtualType>
<type name="IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection">
<arguments>
<argument name="mainTable" xsi:type="string">ics_customer_groups_price</argument>
<argument name="eventPrefix" xsi:type="string">customer_groups_special_prices_form_grid_collection</argument>
<argument name="eventObject" xsi:type="string">customer_groups_special_prices_grid_collection</argument>
<argument name="resourceModel" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupsPrice</argument>
</arguments>
</type>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="customer_groups_special_prices_form_data_source" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupGridCollection</item>
</argument>
</arguments>
</type>
The data from the custom database table comes through when I var_dump it from the data provider class, the issue is that the records of the dynamicRows are not being rendered, so there is something missing to link the datasource/data to the ui component. What am I missing?
uicomponent adminform data-provider dynamic-rows modifier
I need to know how to populate a dynamicRows ui component I have added to the product edit form in Magento 2.
I've got the data coming from a custom table and the data is getting through. I have the dynamic rows component in the correct place in the advanced pricing modal but the dynamicRows records are not being rendered. Here's my code:
DataProvider.php
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
$this->loadedData = array();
/** @var CustomerGroupsPrice $customerGroupsPrice */
foreach ($items as $customerGroupsPrice) {
$this->loadedData[$customerGroupsPrice->getProductId()]['customer_groups_special_prices_form'] = $customerGroupsPrice->getData();
}
//var_dump($this->loadedData);exit;
return $this->loadedData;
}
public function getMeta()
{
return $this->meta;
}
customer_groups_prices_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="namespace" xsi:type="string">customer_groups_special_prices_form</item>
</item>
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">data</item>
<item name="provider" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
<item name="deps" xsi:type="string">customer_groups_special_prices_form.customer_groups_special_prices_form_data_source</item>
</item>
</argument>
<dataSource name="customer_groups_special_prices_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">IcanseeCustomerGroupsPricesModelDataProvider</argument>
<argument name="name" xsi:type="string">customer_groups_special_prices_form_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">product_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</argument>
</dataSource>
modifyMeta function in my modifier class:
public function modifyMeta(array $meta)
{
$meta = array_merge_recursive(
$meta, [
'advanced_pricing_modal' => [
'children' => [
'customer_groups_prices_form' => [
'arguments' => [
'data' => [
'config' => [
'label' => __('Customer Group Special Prices'),
'componentType' => Fieldset::NAME,
'dataScope' => 'customer_group_special_prices_form',
'collapsible' => false,
'sortOrder' => 50,
],
],
],
'children' => [
self::CUSTOMER_GROUP_SPECIAL_PRICES_FIELD => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'dynamicRows',
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows',
'label' => __('Group Special Prices'),
'renderDefaultRecord' => false,
'ns' => 'customer_group_special_prices_form',
'externalProvider' => 'customer_groups_special_prices_form.customer_groups_special_prices_form_data_source',
'imports' => [
'productId' => '${ $.provider }:data.entity_id',
],
'exports' => [
'productId' => '${ $.externalProvider }:params.product_id'
],
'dataScope' => '',
'dndConfig' => [
'enabled' => false,
],
'deleteProperty' => false,
'disabled' => false,
'required' => false,
'additionalClasses' => 'admin__field-wide',
'sortOrder' => 50,
],
],
],
'children' => [
'record' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => Container::NAME,
'isTemplate' => true,
'is_collection' => true,
'component' => 'Magento_Ui/js/dynamic-rows/record',
'dataScope' => 'data.customer_group_special_prices_form',
],
],
],
'children' => [
'entity_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'entity_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 10,
],
],
],
],
'product_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataScope' => 'product_id',
'visible' => false,
'disabled' => true,
'sortOrder' => 20,
],
],
],
],
'website_id' => [
'arguments' => [
'data' => [
'config' => [
'dataType' => Text::NAME,
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataScope' => 'website_id',
'label' => __('Website'),
'options' => $this->getWebsites(),
'visible' => $this->isMultiWebsites(),
'disabled' => ($this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite()),
'sortOrder' => 30,
],
],
],
],
'customer_group_id' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Select::NAME,
'componentType' => Field::NAME,
'dataType' => Text::NAME,
'dataScope' => 'customer_group_id',
'label' => __('Customer Group'),
'options' => $this->getCustomerGroups(),
'sortOrder' => 40,
],
],
],
],
'price' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => Input::NAME,
'componentType' => Field::NAME,
'dataType' => Number::NAME,
'label' => __('Price'),
'dataScope' => 'price',
'sortOrder' => 50,
'validation' => [
'required-entry' => true,
'validate-greater-than-zero' => true,
'validate-digits' => false,
'validate-number' => true,
],
],
],
],
],
'actionDelete' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'actionDelete',
'dataType' => Text::NAME,
'label' => '',
'sortOrder' => 60,
],
],
],
],
],
],
]
]
]
]
]
]
]
);
return $meta;
}
di.xml excerpt:
<virtualType name="CustomerGroupsPricesFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="CustomerGroupsPricesDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">CustomerGroupsPricesFilterPool</argument>
</arguments>
</virtualType>
<type name="IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupCollection">
<arguments>
<argument name="mainTable" xsi:type="string">ics_customer_groups_price</argument>
<argument name="eventPrefix" xsi:type="string">customer_groups_special_prices_form_grid_collection</argument>
<argument name="eventObject" xsi:type="string">customer_groups_special_prices_grid_collection</argument>
<argument name="resourceModel" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupsPrice</argument>
</arguments>
</type>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="customer_groups_special_prices_form_data_source" xsi:type="string">IcanseeCustomerGroupsPricesModelResourceModelCustomerGroupGridCollection</item>
</argument>
</arguments>
</type>
The data from the custom database table comes through when I var_dump it from the data provider class, the issue is that the records of the dynamicRows are not being rendered, so there is something missing to link the datasource/data to the ui component. What am I missing?
uicomponent adminform data-provider dynamic-rows modifier
uicomponent adminform data-provider dynamic-rows modifier
asked 26 mins ago
DavidDavid
135
135
add a comment |
add a comment |
0
active
oldest
votes
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%2f263053%2fhow-to-add-custom-data-into-product-edit-form-dynamicrows-ui-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f263053%2fhow-to-add-custom-data-into-product-edit-form-dynamicrows-ui-component%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