magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Not possible to use multidimensional arrays in widget parameters #19909

Closed ilnytskyi closed 5 years ago

ilnytskyi commented 5 years ago

Summary (*)

Magento 2.2.*, 2.2.5, 2.2.6, 2.2.7

Not possible to use multidimensional arrays in widget parameters When add custom field set as a block parameter type to widget.xml

Examples (*)

Add custom parameter type (in my case it is an options panel) selection_007

Use parameters names and keys like this

parameters[groups_options][order][option[1]: 0
parameters[groups_options][title][option][1][store][0]: store_label_admin
parameters[groups_options][title][option][1][store][1]: store_label_1
parameters[groups_options][title][option][1][store][2]: store_label_2

See an error selection_008

in this file the code looks like this magento/vendor/magento/module-widget/Model/Widget/Instance.php:609

            if ($name == 'conditions') {
                $name = 'conditions_encoded';
                $value = $this->conditionsHelper->encode($value);
            } elseif (is_array($value)) {
                $value = implode(',', $value); 
            }

It is not really possible to reproduce on vanilla instance but we can try to substitute a request parameters for existing widget fields

Proposed solution

// can't we simply serialize an input here instead of implode it ?
// anyway in the database 'widget_instance' all widget values are included in json 
 $value = implode(',', $value); 

selection_009

magento-engcom-team commented 5 years ago

Hi @ilnytskyi. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop). For more details, please, review the Magento Contributor Assistant documentation.

@ilnytskyi do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

magento-engcom-team commented 5 years ago

Hi @maheshWebkul721. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

magento-engcom-team commented 5 years ago

Hi @eduard13. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

magento-engcom-team commented 5 years ago

@eduard13 Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97290 were created

eduard13 commented 5 years ago

Hi @ilnytskyi, these days I have also encountered the same issue while adding a dynamic rows field to a custom widget. In your case, I suggest to use conditions as field name, at least for me it helped.

ilnytskyi commented 5 years ago

@eduard13 thanks for this suggestion. I tired conditions but in my case I want to group them and give them different titles or other attributes.

magento-engcom-team commented 5 years ago

Hi @maheshWebkul721. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

magento-engcom-team commented 5 years ago

Hi @eduard13. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

magento-engcom-team commented 5 years ago

Hi @ilnytskyi. Thank you for your report. The issue has been fixed in magento/magento2#21008 by @eduard13 in 2.3-develop branch Related commit(s):

The fix will be available with the upcoming 2.3.2 release.

magento-engcom-team commented 5 years ago

Hi @ilnytskyi. Thank you for your report. The issue has been fixed in magento/magento2#22214 by @ilnytskyi in 2.2-develop branch Related commit(s):

The fix will be available with the upcoming 2.2.9 release.

jevgenijmokrousov commented 4 years ago

Hi @ilnytskyi, these days I have also encountered the same issue while adding a dynamic rows field to a custom widget. In your case, I suggest to use conditions as field name, at least for me it helped.

As an option change Magento\Widget\Model\Widget\Instance.php: 607 to

            if ($name == 'conditions') {
                $name = 'conditions_encoded';
                $value = $this->conditionsHelper->encode($value);
            } elseif(count($value) !== count($value, COUNT_RECURSIVE)) { // multidimensional array
                $value = $this->conditionsHelper->encode($value);
            } elseif (is_array($value)) {
                $value = implode(',', $value);
            }