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.

  • you will have to code this on your own – Philipp Sander Feb 19 '19 at 13:45
  • Thank you @Philipp Sander, any suggestion for this code? – Vish V Feb 21 '19 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? – Philipp Sander Feb 21 '19 at 7:46
  • Just want to disabled in the backed. Just want to make it read-only from product edit page, nothing else – Vish V Feb 21 '19 at 9:32

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">
        <referenceContainer name="js">
           <block class="Magento\Framework\View\Element\Template" name="js.seller_stock_disabler" template="Rootways_CatalogInventory::product/stock/disabler.phtml"/>

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

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

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.