2

I'm trying to override

module-sales/view/adminhtml/web/order/create/scripts.js file.

Added the custom js file in my requirejs-config.js file. But the issue is, What all changes I made to in custom script.js file is reflecting in Magento core functionalities also, For example in order page. I need to reflect the changes in my custom module pages only. How to make it possible?

Please, can anyone help?

  • Did u get any solution for this? – coderunner Nov 30 '17 at 8:06
  • @mani No. Im checking – sreelakshmi Nov 30 '17 at 9:49
1

You have to add custom.js file in your module layout xml file like this:

<head>
    <script src=path/cutom.js"/>
</head>

And put only that which you needed for that module only other code move to default custom.js.

1

I tried editing and overriding this file but was not able to find a proper way. As a workaround I created my extra functionality in another prototype object and called it inside a phtml defined in the sales_order_create_index layout file.

example:

Namespace/Module/view/adminhtml/web/js/customscript.js

define([
    "jquery",
    "Magento_Ui/js/modal/modal",
    "mage/loader",
    "mage/translate",
    "prototype",


], function (jQuery, modal,loader) {
    window.addProduct = Class.create();

    addProduct.prototype = {
      //Custom code
     initialize: function () {
            //Code to run on Object Initialisation
      },
      setPopUpContainer: function (trigger) {
            //Code to pull up a modal 

        },
        reloadAreas: function () {
          // this accesses the order object from the scripts.js file and reloads the various areas in the page
          order.loadArea(['items', 'shipping_method', 'totals', 'billing_method'], true);

        }


    };
});

Namespace/Module/view/adminhtml/templates/custom-js.phtml

<script>
    require(["jquery", "prototype", "Magento_Sales/order/create/form", "Namespace_Module/js/customscript"], function ($) {

        window.CustomAddProduct = new addProduct();

    });



</script>

Namespace/Module/view/adminhtml/layout/

<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="Namespace\Module\Block\Adminhtml\CustomBlock" template="Namespace_Module::custom-js.phtml" name="customblockname"/>

        </referenceContainer>
    </body>
</page>

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.