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?

asked Nov 30, 2017 at 7:06
2
  • Did u get any solution for this? Commented Nov 30, 2017 at 8:06
  • @mani No. Im checking Commented Nov 30, 2017 at 9:49

2 Answers 2

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.

answered Nov 30, 2017 at 8:14
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>
Rohan Hapani
17.6k9 gold badges57 silver badges99 bronze badges
answered Nov 30, 2017 at 8:15
1
  • Hello Rohan, did you add require-config.js for that customscript.js? or add that script in head tag using <link src="vendor_Module::js/customscript.js" /> Commented Dec 17, 2019 at 7:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.