2

I created a complex product attribute entry in product admin, which uses dynamic rows.

Same idea as this core one:

enter image description here

UI works fine, but if you remove all rows, and save, the attribute does not update, and reloads back to the rows prior to removed. So, basically, you cannot clear out the rows/entries.

However, this example core one works 100%.

My entry is adjusted using UI Components modifiers, exactly like this core attribute is done.

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php#L433

(they used a derived UI component called Magento_Catalog/js/components/dynamic-rows-tier-price in place of Magento_Catalog/js/components/dynamic-rows, but they are essentially the same. Tested as well by making my component use the same, which did not solve the issue (just in case)

So, essentially, we have ability to build these complex input components, but they cannot be cleared.

1

I am placing this answer, to allow someone having same issue get help.

Investigating how magento core solves this issue (thinking I am missing something in my UI Component setup), I found this line of code:

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php#L202

$productData['tier_price'] = isset($productData['tier_price']) ? $productData['tier_price'] : [];

So, seems like this issue is solved (by core) as part of the product data initialisation

Essentially, the issue is that since the attribute contains no data, at saving, it is not in the POST data, so is not handled.

That line of code solves this.

The solution I did was to place a before interceptor to the initializeFromData method, and handle my own attribute the same.

Personally, I think this stinks. The UI component system should have a way to deal with this, and not need to place such code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.