I add custom field to admin order form and I want it to be updated with ajax when admin add products to order, like other areas - shipping, billing and totals. I inspected file \vendor\magento\module-sales\view\adminhtml\web\order\create\scripts.js. There is a function

productGridAddSelected : function(){
        if(this.productGridShowButton) Element.show(this.productGridShowButton);
        var area = ['search', 'items', 'shipping_method', 'totals', 'giftmessage','billing_method'];

When I add my custom area name to it, like this, it works!

var area = ['custom_area', 'search', 'items', 'shipping_method','totals', 'giftmessage','billing_method'];....

But this is core file, so I need to do this somehow in my module. Any ideas how can I do this?


I ended up adding this js script to my html block template

if (typeof(order) != 'undefined') {
   order.prepareArea = function(area) {
        if (this.giftMessageDataChanged) {
            return area.without('giftmessage');
        if(order.getAreaId('store_credit')) area.push("store_credit");
        return area;

So basically I rewrite prepareArea function from AdminOrder class and add here my area. That's it

|improve this answer|||||

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.