0

I want to overide

Magento_Sales/adminhtml/web/order/create/scripts.js

I wrote require-config.js for this

var config = {
    config: {
        mixins: {
            'Magento_Sales/adminhtml/web/order/create/scripts.js': {
                'Magento_Sales/web/order/create/scripts-mixins.js': true
            }
        }
    }
};

My implementation is in file

Magento_Sales/web/order/create/scripts-mixins.js
define([
    "jquery",
    'Magento_Ui/js/modal/confirm',
    'Magento_Ui/js/modal/alert',
    "mage/translate",
    "prototype",
    "Magento_Catalog/catalog/product/composite/configure",
    'Magento_Ui/js/lib/view/utils/async'
], function(jQuery, confirm, alert){

   return AdminOrder.prototype = {
       setCustomerId : function(id){
            return false;
            this.customerId = id;
            this.loadArea('header', true);
            $(this.getAreaId('header')).callback = 'setCustomerAfter';
            $('back_order_top_button').hide();
            $('reset_order_top_button').show();
        }
   }
});

But its not working. its always executing parent class function.

0

You may not use js mixin for the particular js file you try to override (i.e /vendor/magento/module-sales/view/adminhtml/web/order/create/scripts.js). Also, your require-config.js declaration is wrong but this not matter since mixin will not work for the js file /vendor/magento/module-sales/view/adminhtml/web/order/create/scripts.js

You may try below steps to override this AdminOrder class of the scripts.js file

I assume you are using a custom Module "Company_MyModule"

Step 1)

Create a xml file sales_order_create_index.xml under /app/code/Company/MyModule/view/adminhtml/layout

File : /app/code/Company/MyModule/view/adminhtml/layout/sales_order_create_index.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\Backend\Block\Template" template="Company_MyModule::order/create/js.phtml" name="create2"/>
     </referenceContainer>
</page> 

step 2)

Create a phtml file js.phtml under /app/code/Company/MyModule/view/adminhtml/templates/order/create

File : /app/code/Company/MyModule/view/adminhtml/templates/order/create/js.phtml

<script>
require([
    "prototype",
    "Company_MyModule/js/order/create/scripts"
], function(){



});
</script>

step 3)

Create js file scripts.js under /app/code/Company/MyModule/view/adminhtml/web/js/order/create to override AdminOrder class.

File: /app/code/Company/MyModule/view/adminhtml/web/js/order/create/scripts.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/* global AdminOrder */
define([
    'jquery',
    'Magento_Sales/order/create/scripts'
], function (jQuery) {
    'use strict';


    AdminOrder.prototype.setCustomerId = function(id){
           //console.log("override setCustomerId called");
        return false;
            this.customerId = id;
            this.loadArea('header', true);
            $(this.getAreaId('header')).callback = 'setCustomerAfter';
            $('back_order_top_button').hide();
            $('reset_order_top_button').show();

        }
});

step 4)

Clear your Magento Cache and alson remove adminhtml static files also.

php bin/magento cache:clean
sudo rm -rf pub/static/adminhtml/*

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.