backend_prod_category_dialog

Adds custom content to the product category editing dialog in the new interface (2.0). E.g., extra settings fields, which can be processed by a plugin.

Shop-Script

Input (passed by reference)

$params['category'] array Category information data.

$params['category']['id'] int Category ID.

$params['category']['name'] string Category name.
… your plugin code …

Output

{$backend_prod_category_dialog}
top: Custom content at the dialog top of above the “Displaying in the storefront” section.
storefront: Custom content at bottom of the “Displaying in the storefront” section.
publication: Custom content at bottom of the “Publication” section.
seo: Custom content at bottom of the “For search systems” section.
og: Custom content at bottom of the “For social media” section.
bottom: Custom content at the dialog bottom.

To show a user extra settings fields, add HTML elements with the name attribute to the returned content strings. In the attribute value, use your plugin ID to distinguish its fields’ values from the built-in ones and those added by other plugins.

Example
<input type="text" name="myplugin[field1]" value="">
<textarea name="myplugin[field2]"></textarea>


A POST request values array with your plugin’s key must then be processed in the category_save hook handler.

Example
$myplugin_fields = waRequest::post('myplugin', [], waRequest::TYPE_ARRAY);
$field1_value = $myplugin_fields['field1'] ?? null;
$field2_value = $myplugin_fields['field2'] ?? null;


Instead of using additional HTML fields, you can also send custom hidden values to the server using only JavaScript as shown in the example below.
Shop-Script

Plugin code example

PHP

function backendProdCategoryDialog(&$params)
{
    return [
        'top' => '...custom HTML code...',
        'storefront' => '...custom HTML code...',
        'publication' => '...custom HTML code...',
        'seo' => '...custom HTML code...',
        'og' => '...custom HTML code...',
        'bottom' => '...custom HTML code...',
    ];
}

HTML/Smarty

<span class="hidden" id="myplugin"></span>
<script>
    (function () {
        const $dialog = $('#myplugin').closest('.wa-dialog');
        const dialog_object = $dialog.data('dialog');

        // Be sure to wait until the dialog's DOM is ready using the 'vue_ready' option.
        // The WYSIWYG text editor's functionality is guaranteed to be available at this point, too.
        dialog_object.options.vue_ready.then(function () {
            const $category_form = $dialog.find('.s-category-form');

            // How to send a hidden value to the server using JavaScript
            $category_form.on('wa_save', function (event) {
                event.form_data['myplugin_field1'] = 'some value string';
            });

            // How to interrupt the form submission if the validation has detected invalid values
            $category_form.on('wa_before_save', function (event) {
                if (mypluginInvalidValuesAreSpecified()) {
                    alert('Warning!');
                    event.preventDefault();
                }
            });
        });
    })();
</script>