0

I am trying to hide the Store View change option by overriding vendor/magento/module-catalog/view/adminhtml/layout/catalog_product_edit.xml and commenting out like this:

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="catalog_product_new"/>
    <update handle="styles"/>
    <body>
        <referenceBlock name="page.title">
            <action method="setTitleClass">
                <argument name="class" xsi:type="string">complex</argument>
            </action>
        </referenceBlock>
        <!--
        <referenceContainer name="page.main.actions">
            <block class="Magento\Backend\Block\Store\Switcher" name="store_switcher">
                <action method="setUseConfirm">
                    <argument name="params" xsi:type="string">1</argument>
                </action>
            </block>
        </referenceContainer> -->
    </body>
</page>

It works if I comment this section directly from the vendor module. But, since it is not a good practice I tried to override it via following this instructions: How can i override this vendor layout file with my custom layout file in magento 2?

but it is not working for me. Please help.

UPDATE

There is the custom module I created:

registration.php

    <?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Company_CatalogProduct',
    __DIR__
);

etc>module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Company_CatalogProduct" setup_version="1.0">
    <sequence>
            <module name="Magento_Catalog"/>
        </sequence>

        </module>
</config>

view>adminhtml>layout>catalog_product_edit.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="catalog_product_new"/>
    <update handle="styles"/>
    <body>
        <referenceBlock name="page.title">
            <action method="setTitleClass">
                <argument name="class" xsi:type="string">complex</argument>
            </action>
        </referenceBlock>
        <!--
        <referenceContainer name="page.main.actions">
            <block class="Magento\Backend\Block\Store\Switcher" name="store_switcher">
                <action method="setUseConfirm">
                    <argument name="params" xsi:type="string">1</argument>
                </action>
            </block>
        </referenceContainer> -->
    </body>
</page>
  • 2
    @Korbin This is adminhtml area file you cannot override in frontend..@ishu did you run upgrde and content deploy command – Ranganathan Dec 17 '19 at 8:17
  • Yes I have run all the command..I also tried to override by creating an adminhtml theme..but it won't work. Any other idea how I can hide that option from product edit page? – ishu Dec 17 '19 at 8:28
  • try to place "view/adminhtml/layout/catalog_product_edit.xml" file in your custom module. – Ronak Chauhan Dec 17 '19 at 8:36
  • Yes I have tried that..please see my updated question. Thank you – ishu Dec 17 '19 at 8:43
3

Instead of this, you can simply create 1 xml file with below code in your custom module.

view/adminhtml/layout/catalog_product_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">
    <body>
        <referenceContainer name="page.main.actions">
            <referenceBlock name="store_switcher" remove="true" />
        </referenceContainer>
    </body>
</page>

Using this, you can achieve your desired result.

| improve this answer | |
  • worked like a charm...thank you so much.! – ishu Dec 17 '19 at 8:55
1

Copy that file and place it in custom module: app/code/<vendor>/<module>/view/adminhtml/layout/catalog_product_edit.xml

and do not forget to add sequence in etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="CutstomModule" >
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>
| improve this answer | |
  • Please see my updated question..thank you @Ronak Chauhan – ishu Dec 17 '19 at 8:42
  • this should work. remove unnecessary code from layout file. – Ronak Chauhan Dec 17 '19 at 8:49
  • ..don't know why not able to tag properly.. Removed the unnecessary code also took suggestion from above. Working nicely. Thank you – ishu Dec 17 '19 at 8:56
  • please accept the answer if it works for you, so it can help others also. – Ronak Chauhan Dec 17 '19 at 8:59
  • Sorry I am new to all this..how to accept the answer? – ishu Dec 17 '19 at 9:03
1

You cannot Comment the code on the overided file, It won't work, You can use below code to remove the container

<referenceContainer name="page.main.actions" remove="true" />
| improve this answer | |
  • thank you.! it is working now.! – ishu Dec 17 '19 at 8:55
  • You are welcome... – aravind Dec 17 '19 at 9:02

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.