Good day mates on this weblog we are going to learn the way we will create customized attributes in Magento 2 with dynamic rows on the admin add/edit product web page. On this weblog, we are going to cowl every level to create dynamic attributes so keep until the tip.
First, we have to create a primary module.
After creating the module our module construction will look one thing like this.
Now create the di.xml file within the and so on folder. This file is used to start out the rendering of the dynamic row attribute when the product add/edit web page opens on the admin finish.
File Path: VendorName/ModuleName/and so on/adminhtml/di.xml
<?xml model="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/and so on/config.xsd"> <virtualType identify="MagentoCatalogUiDataProviderProductFormModifierPool"> <arguments> <argument identify="modifiers" xsi:kind="array"> <merchandise identify="add-attributes" xsi:kind="array"> <merchandise identify="class" xsi:kind="string">WebkulCustomAttributeUiDataProviderProductFormModifierDynamicRowAttribute</merchandise> <merchandise identify="sortOrder" xsi:kind="quantity">20</merchandise> </merchandise> </argument> </arguments> </virtualType> </config>
Now we are going to create a UI file that’s really accountable for rendering the attribute with the dynamic rows.
File Path: VendorName/ModuleName/Ui/DataProvider/Product/Type/Modifier/DynamicRowAttribute.php
<?php namespace WebkulCustomAttributeUiDataProviderProductFormModifier; use MagentoCatalogModelLocatorLocatorInterface; use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier; use MagentoUiComponentFormField; use MagentoUiComponentFormElementInput; use MagentoUiComponentDynamicRows; use MagentoUiComponentContainer; use MagentoUiComponentFormElementDataTypeText; use MagentoEavModelResourceModelEntityAttributeSetCollectionFactory as AttributeSetCollection; use MagentoFrameworkStdlibArrayManager; class DynamicRowAttribute extends AbstractModifier { public const PRODUCT_ATTRIBUTE_CODE = 'dynamic_row_attribute'; public const FIELD_IS_DELETE = 'is_delete'; public const FIELD_SORT_ORDER_NAME = 'sort_order'; /** * Dependency Initilization * * @param LocatorInterface $locator * @param AttributeSetCollection $attributeSetCollection * @param MagentoFrameworkSerializeSerializerInterface $serializer * @param ArrayManager $arrayManager */ public operate __construct( personal LocatorInterface $locator, protected AttributeSetCollection $attributeSetCollection, protected MagentoFrameworkSerializeSerializerInterface $serializer, protected ArrayManager $arrayManager, ) { } /** * Modify Knowledge * * @param array $knowledge * @return array */ public operate modifyData(array $knowledge) { $fieldCode = self::PRODUCT_ATTRIBUTE_CODE; $mannequin = $this->locator->getProduct(); $modelId = $model->getId(); $highlightsData = $model->getDynamicRowAttribute(); if ($highlightsData) { $highlightsData = $this->serializer->unserialize($highlightsData, true); $path = $modelId . '/' . self::DATA_SOURCE_DEFAULT . '/' . $fieldCode; $knowledge = $this->arrayManager->set($path, $knowledge, $highlightsData); } return $knowledge; } /** * Modify Meta * * @param array $meta * @return array */ public operate modifyMeta(array $meta) { $highlightsPath = $this->arrayManager->findPath( self::PRODUCT_ATTRIBUTE_CODE, $meta, null, 'kids' ); if ($highlightsPath) { $meta = $this->arrayManager->merge( $highlightsPath, $meta, $this->initHighlightFieldStructure($meta, $highlightsPath) ); $meta = $this->arrayManager->set( $this->arrayManager->slicePath($highlightsPath, 0, -3) . '/' . self::PRODUCT_ATTRIBUTE_CODE, $meta, $this->arrayManager->get($highlightsPath, $meta) ); $meta = $this->arrayManager->take away( $this->arrayManager->slicePath($highlightsPath, 0, -2), $meta ); } return $meta; } /** * Add Attribute Grid Config * * @param int $sortOrder * @return array */ protected operate addAttributeGridConfig($sortOrder) { return [ 'arguments' => [ 'data' => [ 'config' => [ 'addButtonLabel' => __('Add Attribute'), 'componentType' => DynamicRows::NAME, 'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows', 'additionalClasses' => 'admin__field-wide', 'deleteProperty' => static::FIELD_IS_DELETE, 'deleteValue' => '1', 'renderDefaultRecord' => false, 'sortOrder' => $sortOrder, ], ], ], 'kids' => [ 'record' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Container::NAME, 'component' => 'Magento_Ui/js/dynamic-rows/record', 'positionProvider' => static::FIELD_SORT_ORDER_NAME, 'isTemplate' => true, 'is_collection' => true, ], ], ], 'kids' => [ 'attribute_type' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Field::NAME, 'formElement' => Input::NAME, 'dataType' => Text::NAME, 'label' => __('Attribute Type'), 'enableLabel' => true, 'dataScope' => 'attribute_type', 'sortOrder' => 40, 'validation' => [ 'required-entry' => true, ], ], ], ], ], 'attribute_lable' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Field::NAME, 'formElement' => Input::NAME, 'dataType' => Text::NAME, 'label' => __('Attribute'), 'enableLabel' => true, 'dataScope' => 'attribute_lable', 'sortOrder' => 40, 'validation' => [ 'required-entry' => true, ], ], ], ], ], 'actionDelete' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => 'actionDelete', 'dataType' => Text::NAME, 'label' => '', 'sortOrder' => 50, ], ], ], ], ] ] ] ]; } /** * Get attraction highlights dynamic rows construction * * @param array $meta * @param string $highlightsPath * @return array */ protected operate initHighlightFieldStructure($meta, $highlightsPath) { return [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => 'dynamicRows', 'label' => __('Custom Dynamic Rows'), 'renderDefaultRecord' => false, 'recordTemplate' => 'record', 'dataScope' => '', 'dndConfig' => [ 'enabled' => false, ], 'disabled' => false, 'sortOrder' => $this->arrayManager->get($highlightsPath . '/arguments/knowledge/config/sortOrder', $meta), ], ], ], 'kids' => [ 'record' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Container::NAME, 'isTemplate' => true, 'is_collection' => true, 'component' => 'Magento_Ui/js/dynamic-rows/record', 'dataScope' => '', ], ], ], 'kids' => [ 'title' => [ 'arguments' => [ 'data' => [ 'config' => [ 'formElement' => Input::NAME, 'componentType' => Field::NAME, 'dataType' => Text::NAME, 'label' => __('Title'), 'dataScope' => 'title', 'require' => '1', ], ], ], ], 'worth' => [ 'arguments' => [ 'data' => [ 'config' => [ 'formElement' => Input::NAME, 'componentType' => Field::NAME, 'dataType' => Text::NAME, 'label' => __('Value'), 'dataScope' => 'value', 'require' => '1', ], ], ], ], 'actionDelete' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => 'actionDelete', 'dataType' => Text::NAME, 'label' => '', ], ], ], ], ], ], ], ]; } }
Now we are going to create a brand new file to create the product attribute that shops the information of the dynamic rows within the JSON format.
File Path: VendorNameModuleNameSetupPatchDataProductAttribute.php
<?php namespace WebkulCustomAttributeSetupPatchData; use MagentoFrameworkSetupModuleDataSetupInterface; use MagentoFrameworkSetupPatchDataPatchInterface; use MagentoCatalogSetupCategorySetupFactory; use MagentoEavSetupEavSetupFactory; use WebkulCustomAttributeUiDataProviderProductFormModifierDynamicRowAttribute; use MagentoEavModelEntityAttributeScopedAttributeInterface; class ProductAttribute implements DataPatchInterface { /** * Dependency Initilization * * @param ModuleDataSetupInterface $moduleDataSetup * @param CategorySetupFactory $categorySetupFactory * @param EavSetupFactory $eavSetupFactory */ public operate __construct( personal ModuleDataSetupInterface $moduleDataSetup, personal CategorySetupFactory $categorySetupFactory, personal EavSetupFactory $eavSetupFactory ) { } /** * @inheritdoc */ public operate apply() { $eavSetup = $this->eavSetupFactory->create(); $eavSetup->addAttribute( MagentoCatalogModelProduct::ENTITY, DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE, [ 'label' => 'Custom Dynamic Rows', 'type' => 'text', 'default' => '', 'input' => 'text', 'required' => false, 'sort_order' => 1, 'user_defined' => true, 'global' => ScopedAttributeInterface::SCOPE_GLOBAL, 'used_in_product_listing' => true, 'visible_on_front' => true, 'visible' => true ] ); $eavSetup->addAttributeToGroup( MagentoCatalogModelProduct::ENTITY, 'Default', 'Normal', // group DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE, 1000 // type order ); } /** * @inheritdoc */ public static operate getDependencies() { return []; } /** * @inheritdoc */ public operate getAliases() { return []; } }
Until now our Dynamic Row Attribute will look one thing like this.
However wait if we save our product now our dynamic row values is not going to save and easily disappear. So to avoid wasting these dynamic row values we have to add an observer to the occasion catalog_product_save_before that can save the dynamic row worth in our created product dynamic row attribute.
So, now we are going to create our occasion and observer file to avoid wasting our dynamic rows worth.
Occasion File Path: VendorNameModuleNameetcevents.xml
<?xml model="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Occasion/and so on/occasions.xsd"> <occasion identify="catalog_product_save_before"> <observer identify="product_dynamic_row_attribute" occasion="WebkulCustomAttributeObserverSaveDynamicRowValues" /> </occasion> </config>
Observer File Path: VendorNameModuleNameObserverSaveDynamicRowValues.php
<?php namespace WebkulCustomAttributeObserver; use WebkulCustomAttributeUiDataProviderProductFormModifierDynamicRowAttribute; use MagentoFrameworkEventObserver; use MagentoFrameworkEventObserverInterface; use MagentoFrameworkAppRequestInterface; class SaveDynamicRowValues implements ObserverInterface { /** * Dependency Initilization * * @param RequestInterface $request * @param MagentoFrameworkSerializeSerializerInterface $serializer */ public operate __construct( protected RequestInterface $request, protected MagentoFrameworkSerializeSerializerInterface $serializer, ) { } /** * Execute * * @param Observer $observer * @return this */ public operate execute(Observer $observer) { /** @var $product MagentoCatalogModelProduct */ $product = $observer->getEvent()->getDataObject(); $wholeRequest = $this->request->getPost(); $submit = $wholeRequest['product']; if (empty($submit)) { $submit = !empty($wholeRequest['variables']['product']) ? $wholeRequest['variables']['product'] : []; } $highlights = isset( $submit[DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE] ) ? $submit[DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE] : ''; $product->setDynamicRowAttribute($highlights); $requiredParams = ['title', 'value']; if (is_array($highlights)) { $highlights = $this->removeEmptyArray($highlights, $requiredParams); $product->setDynamicRowAttribute($this->serializer->serialize($highlights)); } } /** * Perform to take away empty array from the multi dimensional array * * @param array $attractionData * @param array $requiredParams * @return array */ personal operate removeEmptyArray($attractionData, $requiredParams) { $requiredParams = array_combine($requiredParams, $requiredParams); $reqCount = rely($requiredParams); foreach ($attractionData as $key => $values) { $values = array_filter($values); $intersectCount = rely(array_intersect_key($values, $requiredParams)); if ($reqCount !== $intersectCount) { unset($attractionData[$key]); } } return $attractionData; } }
Now after saving once more the Dynamic Rows values will look one thing like this.
That’s all it’s essential create the product dynamic rows attribute on the admin finish. Hope this can assist.
File construction: until now
It’s possible you’ll go to different Magento 2 tutorials on the Webkul weblog. We additionally supply end-to-end providers on Magento 2 and We’re an Adobe commerce associate as effectively. Additionally, you could Rent a Magento Developer for devoted customization providers.
Thanks 🙂
Good day mates on this weblog we are going to learn the way we will create customized attributes in Magento 2 with dynamic rows on the admin add/edit product web page. On this weblog, we are going to cowl every level to create dynamic attributes so keep until the tip.
First, we have to create a primary module.
After creating the module our module construction will look one thing like this.
Now create the di.xml file within the and so on folder. This file is used to start out the rendering of the dynamic row attribute when the product add/edit web page opens on the admin finish.
File Path: VendorName/ModuleName/and so on/adminhtml/di.xml
<?xml model="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/and so on/config.xsd"> <virtualType identify="MagentoCatalogUiDataProviderProductFormModifierPool"> <arguments> <argument identify="modifiers" xsi:kind="array"> <merchandise identify="add-attributes" xsi:kind="array"> <merchandise identify="class" xsi:kind="string">WebkulCustomAttributeUiDataProviderProductFormModifierDynamicRowAttribute</merchandise> <merchandise identify="sortOrder" xsi:kind="quantity">20</merchandise> </merchandise> </argument> </arguments> </virtualType> </config>
Now we are going to create a UI file that’s really accountable for rendering the attribute with the dynamic rows.
File Path: VendorName/ModuleName/Ui/DataProvider/Product/Type/Modifier/DynamicRowAttribute.php
<?php namespace WebkulCustomAttributeUiDataProviderProductFormModifier; use MagentoCatalogModelLocatorLocatorInterface; use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier; use MagentoUiComponentFormField; use MagentoUiComponentFormElementInput; use MagentoUiComponentDynamicRows; use MagentoUiComponentContainer; use MagentoUiComponentFormElementDataTypeText; use MagentoEavModelResourceModelEntityAttributeSetCollectionFactory as AttributeSetCollection; use MagentoFrameworkStdlibArrayManager; class DynamicRowAttribute extends AbstractModifier { public const PRODUCT_ATTRIBUTE_CODE = 'dynamic_row_attribute'; public const FIELD_IS_DELETE = 'is_delete'; public const FIELD_SORT_ORDER_NAME = 'sort_order'; /** * Dependency Initilization * * @param LocatorInterface $locator * @param AttributeSetCollection $attributeSetCollection * @param MagentoFrameworkSerializeSerializerInterface $serializer * @param ArrayManager $arrayManager */ public operate __construct( personal LocatorInterface $locator, protected AttributeSetCollection $attributeSetCollection, protected MagentoFrameworkSerializeSerializerInterface $serializer, protected ArrayManager $arrayManager, ) { } /** * Modify Knowledge * * @param array $knowledge * @return array */ public operate modifyData(array $knowledge) { $fieldCode = self::PRODUCT_ATTRIBUTE_CODE; $mannequin = $this->locator->getProduct(); $modelId = $model->getId(); $highlightsData = $model->getDynamicRowAttribute(); if ($highlightsData) { $highlightsData = $this->serializer->unserialize($highlightsData, true); $path = $modelId . '/' . self::DATA_SOURCE_DEFAULT . '/' . $fieldCode; $knowledge = $this->arrayManager->set($path, $knowledge, $highlightsData); } return $knowledge; } /** * Modify Meta * * @param array $meta * @return array */ public operate modifyMeta(array $meta) { $highlightsPath = $this->arrayManager->findPath( self::PRODUCT_ATTRIBUTE_CODE, $meta, null, 'kids' ); if ($highlightsPath) { $meta = $this->arrayManager->merge( $highlightsPath, $meta, $this->initHighlightFieldStructure($meta, $highlightsPath) ); $meta = $this->arrayManager->set( $this->arrayManager->slicePath($highlightsPath, 0, -3) . '/' . self::PRODUCT_ATTRIBUTE_CODE, $meta, $this->arrayManager->get($highlightsPath, $meta) ); $meta = $this->arrayManager->take away( $this->arrayManager->slicePath($highlightsPath, 0, -2), $meta ); } return $meta; } /** * Add Attribute Grid Config * * @param int $sortOrder * @return array */ protected operate addAttributeGridConfig($sortOrder) { return [ 'arguments' => [ 'data' => [ 'config' => [ 'addButtonLabel' => __('Add Attribute'), 'componentType' => DynamicRows::NAME, 'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows', 'additionalClasses' => 'admin__field-wide', 'deleteProperty' => static::FIELD_IS_DELETE, 'deleteValue' => '1', 'renderDefaultRecord' => false, 'sortOrder' => $sortOrder, ], ], ], 'kids' => [ 'record' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Container::NAME, 'component' => 'Magento_Ui/js/dynamic-rows/record', 'positionProvider' => static::FIELD_SORT_ORDER_NAME, 'isTemplate' => true, 'is_collection' => true, ], ], ], 'kids' => [ 'attribute_type' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Field::NAME, 'formElement' => Input::NAME, 'dataType' => Text::NAME, 'label' => __('Attribute Type'), 'enableLabel' => true, 'dataScope' => 'attribute_type', 'sortOrder' => 40, 'validation' => [ 'required-entry' => true, ], ], ], ], ], 'attribute_lable' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Field::NAME, 'formElement' => Input::NAME, 'dataType' => Text::NAME, 'label' => __('Attribute'), 'enableLabel' => true, 'dataScope' => 'attribute_lable', 'sortOrder' => 40, 'validation' => [ 'required-entry' => true, ], ], ], ], ], 'actionDelete' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => 'actionDelete', 'dataType' => Text::NAME, 'label' => '', 'sortOrder' => 50, ], ], ], ], ] ] ] ]; } /** * Get attraction highlights dynamic rows construction * * @param array $meta * @param string $highlightsPath * @return array */ protected operate initHighlightFieldStructure($meta, $highlightsPath) { return [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => 'dynamicRows', 'label' => __('Custom Dynamic Rows'), 'renderDefaultRecord' => false, 'recordTemplate' => 'record', 'dataScope' => '', 'dndConfig' => [ 'enabled' => false, ], 'disabled' => false, 'sortOrder' => $this->arrayManager->get($highlightsPath . '/arguments/knowledge/config/sortOrder', $meta), ], ], ], 'kids' => [ 'record' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => Container::NAME, 'isTemplate' => true, 'is_collection' => true, 'component' => 'Magento_Ui/js/dynamic-rows/record', 'dataScope' => '', ], ], ], 'kids' => [ 'title' => [ 'arguments' => [ 'data' => [ 'config' => [ 'formElement' => Input::NAME, 'componentType' => Field::NAME, 'dataType' => Text::NAME, 'label' => __('Title'), 'dataScope' => 'title', 'require' => '1', ], ], ], ], 'worth' => [ 'arguments' => [ 'data' => [ 'config' => [ 'formElement' => Input::NAME, 'componentType' => Field::NAME, 'dataType' => Text::NAME, 'label' => __('Value'), 'dataScope' => 'value', 'require' => '1', ], ], ], ], 'actionDelete' => [ 'arguments' => [ 'data' => [ 'config' => [ 'componentType' => 'actionDelete', 'dataType' => Text::NAME, 'label' => '', ], ], ], ], ], ], ], ]; } }
Now we are going to create a brand new file to create the product attribute that shops the information of the dynamic rows within the JSON format.
File Path: VendorNameModuleNameSetupPatchDataProductAttribute.php
<?php namespace WebkulCustomAttributeSetupPatchData; use MagentoFrameworkSetupModuleDataSetupInterface; use MagentoFrameworkSetupPatchDataPatchInterface; use MagentoCatalogSetupCategorySetupFactory; use MagentoEavSetupEavSetupFactory; use WebkulCustomAttributeUiDataProviderProductFormModifierDynamicRowAttribute; use MagentoEavModelEntityAttributeScopedAttributeInterface; class ProductAttribute implements DataPatchInterface { /** * Dependency Initilization * * @param ModuleDataSetupInterface $moduleDataSetup * @param CategorySetupFactory $categorySetupFactory * @param EavSetupFactory $eavSetupFactory */ public operate __construct( personal ModuleDataSetupInterface $moduleDataSetup, personal CategorySetupFactory $categorySetupFactory, personal EavSetupFactory $eavSetupFactory ) { } /** * @inheritdoc */ public operate apply() { $eavSetup = $this->eavSetupFactory->create(); $eavSetup->addAttribute( MagentoCatalogModelProduct::ENTITY, DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE, [ 'label' => 'Custom Dynamic Rows', 'type' => 'text', 'default' => '', 'input' => 'text', 'required' => false, 'sort_order' => 1, 'user_defined' => true, 'global' => ScopedAttributeInterface::SCOPE_GLOBAL, 'used_in_product_listing' => true, 'visible_on_front' => true, 'visible' => true ] ); $eavSetup->addAttributeToGroup( MagentoCatalogModelProduct::ENTITY, 'Default', 'Normal', // group DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE, 1000 // type order ); } /** * @inheritdoc */ public static operate getDependencies() { return []; } /** * @inheritdoc */ public operate getAliases() { return []; } }
Until now our Dynamic Row Attribute will look one thing like this.
However wait if we save our product now our dynamic row values is not going to save and easily disappear. So to avoid wasting these dynamic row values we have to add an observer to the occasion catalog_product_save_before that can save the dynamic row worth in our created product dynamic row attribute.
So, now we are going to create our occasion and observer file to avoid wasting our dynamic rows worth.
Occasion File Path: VendorNameModuleNameetcevents.xml
<?xml model="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Occasion/and so on/occasions.xsd"> <occasion identify="catalog_product_save_before"> <observer identify="product_dynamic_row_attribute" occasion="WebkulCustomAttributeObserverSaveDynamicRowValues" /> </occasion> </config>
Observer File Path: VendorNameModuleNameObserverSaveDynamicRowValues.php
<?php namespace WebkulCustomAttributeObserver; use WebkulCustomAttributeUiDataProviderProductFormModifierDynamicRowAttribute; use MagentoFrameworkEventObserver; use MagentoFrameworkEventObserverInterface; use MagentoFrameworkAppRequestInterface; class SaveDynamicRowValues implements ObserverInterface { /** * Dependency Initilization * * @param RequestInterface $request * @param MagentoFrameworkSerializeSerializerInterface $serializer */ public operate __construct( protected RequestInterface $request, protected MagentoFrameworkSerializeSerializerInterface $serializer, ) { } /** * Execute * * @param Observer $observer * @return this */ public operate execute(Observer $observer) { /** @var $product MagentoCatalogModelProduct */ $product = $observer->getEvent()->getDataObject(); $wholeRequest = $this->request->getPost(); $submit = $wholeRequest['product']; if (empty($submit)) { $submit = !empty($wholeRequest['variables']['product']) ? $wholeRequest['variables']['product'] : []; } $highlights = isset( $submit[DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE] ) ? $submit[DynamicRowAttribute::PRODUCT_ATTRIBUTE_CODE] : ''; $product->setDynamicRowAttribute($highlights); $requiredParams = ['title', 'value']; if (is_array($highlights)) { $highlights = $this->removeEmptyArray($highlights, $requiredParams); $product->setDynamicRowAttribute($this->serializer->serialize($highlights)); } } /** * Perform to take away empty array from the multi dimensional array * * @param array $attractionData * @param array $requiredParams * @return array */ personal operate removeEmptyArray($attractionData, $requiredParams) { $requiredParams = array_combine($requiredParams, $requiredParams); $reqCount = rely($requiredParams); foreach ($attractionData as $key => $values) { $values = array_filter($values); $intersectCount = rely(array_intersect_key($values, $requiredParams)); if ($reqCount !== $intersectCount) { unset($attractionData[$key]); } } return $attractionData; } }
Now after saving once more the Dynamic Rows values will look one thing like this.
That’s all it’s essential create the product dynamic rows attribute on the admin finish. Hope this can assist.
File construction: until now
It’s possible you’ll go to different Magento 2 tutorials on the Webkul weblog. We additionally supply end-to-end providers on Magento 2 and We’re an Adobe commerce associate as effectively. Additionally, you could Rent a Magento Developer for devoted customization providers.
Thanks 🙂