0

What I hope to accomplish is adding a new option to an existing menu of options in category edit page, specifically adding a new option below the "Match products by rule" switch toggle.

This menu is currently defined in the Magento module visual-merchandiser using the following XML files:

module-visual-merchandiser\view\adminhtml\layout\catalog_category_edit.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="merchandiser"/>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="catalog.category.add.product.content" template="Magento_VisualMerchandiser::category/add_product.phtml">
                <block class="Magento\VisualMerchandiser\Block\Adminhtml\Category\AddProduct\Tabs" name="catalog.category.add.product.tabs" as="catalog_category_add_product_tabs" template="Magento_Backend::widget/tabshoriz.phtml">
                    <arguments>
                        <argument name="id" xsi:type="string">catalog_category_add_product</argument>
                        <argument name="dest_element_id" xsi:type="string">catalog_category_add_product_tabs_content</argument>
                    </arguments>
                    <block class="Magento\Framework\View\Element\Template" name="catalog.category.add.product.tabs.nametab" template="Magento_VisualMerchandiser::category/add_product/tabs/nametab.phtml" />
                    <block class="Magento\VisualMerchandiser\Block\Adminhtml\Category\AddProduct\Tabs\SkuTab" name="catalog.category.add.product.tabs.skutab" template="Magento_VisualMerchandiser::category/add_product/tabs/skutab.phtml" />
                </block>
            </block>
        </referenceContainer>
    </body>
</page>

and

module-visual-merchandiser\view\adminhtml\layout\merchandiser.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <block class="Magento\VisualMerchandiser\Block\Adminhtml\Category\Merchandiser" name="category.merchandiser.container" template="Magento_VisualMerchandiser::category/merchandiser.phtml">
            <block class="Magento\VisualMerchandiser\Block\Adminhtml\Category\Merchandiser\Grid" name="category.merchandiser.grid" as="grid"/>
            <block class="Magento\VisualMerchandiser\Block\Adminhtml\Category\Merchandiser\Tile" name="category.merchandiser.tile" as="tile"/>
            <block class="Magento\Backend\Block\Widget\Button" name="category.merchandiser.add_product_button" as="add_products_button">
                <arguments>
                    <argument name="id" xsi:type="string">catalog_category_add_product_tabs</argument>
                    <argument name="label" translate="true" xsi:type="string">Add Products</argument>
                    <argument name="class" xsi:type="string">secondary add-products</argument>
                </arguments>
            </block>
            <block class="Magento\Backend\Block\Widget\Button" name="category.merchandiser.sort_products_button" as="sort_products_button">
                <arguments>
                    <argument name="id" xsi:type="string">catalog_category_sort_products_tabs</argument>
                    <argument name="label" translate="true" xsi:type="string">Sort</argument>
                    <argument name="class" xsi:type="string">secondary sort-products</argument>
                </arguments>
            </block>
            <block class="Magento\Framework\View\Element\Template" name="category.merchandiser.smart_category" as="smart_category" template="Magento_VisualMerchandiser::category/smart_category.phtml">
                <block class="Magento\VisualMerchandiser\Block\Adminhtml\Widget\SmartCategorySwitch" name="category.merchandiser.smart_category.smart_category_onoff" as="smart_category_onoff" template="Magento_VisualMerchandiser::widget/smart_category_switch.phtml">
                    <arguments>
                        <argument name="id" xsi:type="string">catalog_category_smart_category_onoff</argument>
                    </arguments>
                </block>
                <!-- TRUNCATED FOR SPACE -->
            </block>
            <block class="Magento\VisualMerchandiser\Block\Adminhtml\Widget\Select\SortOrderSelect" name="category.merchandiser.sort_order" as="sort_order">
                <arguments>
                    <argument name="label" translate="true" xsi:type="string">Sort order</argument>
                    <argument name="class" xsi:type="string">sort_order</argument>
                    <argument name="name" xsi:type="string">sort_order</argument>
                </arguments>
            </block>
        </block>
    </body>
</page>

Here is my attempt at extending the layout:

app\Code\VENDOR\MODULE\view\adminhtml\layout\merchandiser.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="category.merchandiser.smart_category">
            <block class="VENDOR\MODULE\Block\Adminhtml\Widget\TestSwitch" name="category.merchandiser.smart_category.test_onoff" as="test_onoff" template="VENDOR_MODULE::widget/test_switch.phtml">
                <arguments>
                    <argument name="id" xsi:type="string">catalog_category_test_switch_onoff</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

Note: There is no error with the .phtml or .php files, if I replace <referenceBlock> with a <referenceContainer> (for "content") the switch appears (albeit at the foot of the page) and does function as anticipated.

I seems to me that the only thing I can do is override the entire layout which I specifically do not want to do.

I have also attempted to use a <move> directive with adding the element to a <referenceContainer>, this does not work.

Dependency is set up correctly to load my module after visual-merchandiser.

Your Answer

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

Browse other questions tagged or ask your own question.