1

How can we disable quantity text fields of product edit form at admin side or how can we make it ready only?

We found that it's already disabled with bundle product but we want to do this with all type of products.

Any help or suggestion will be appreciated. Thank you in advance.

4
  • you will have to code this on your own Feb 19, 2019 at 13:45
  • Thank you @Philipp Sander, any suggestion for this code? Feb 21, 2019 at 5:10
  • do you just want the qty field to be disabled in the backend or do you also wan't to restrict API or anything else? Feb 21, 2019 at 7:46
  • Just want to disabled in the backed. Just want to make it read-only from product edit page, nothing else Feb 21, 2019 at 9:32

1 Answer 1

1

Step 1: Create catalog_product_new.xml file under your_module/view/adminhtml/layout

Below is content of catalog_product_new.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" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="js">
           <block class="Magento\Framework\View\Element\Template" name="js.seller_stock_disabler" template="Rootways_CatalogInventory::product/stock/disabler.phtml"/>
        </referenceContainer>
    </body>
</page>

Step 2: Create disabler.phtml file under your_module/view/adminthml/templates/product/stock
Below is content of disabler.phtml

<script>
require(['jquery'], function($) {
    window.afterOptionsInit = function() {
        if (!jQuery('[data-index = quantity_and_stock_status_qty] input')[0]) {
            setTimeout(function(){window.afterOptionsInit();}, 500);
            return;
        }
        $( "[data-index = quantity_and_stock_status_qty] input" ).attr("disabled", "true");
        $( "[data-index = quantity_and_stock_status_qty] .admin__field-group-additional" ).hide();
    }
    window.afterOptionsInit();
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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