magento: create order for new customer in admin, shipping address filled with jquery not refreshing POST with new values

StackOverflow https://stackoverflow.com/questions/22376782

  •  14-06-2023
  •  | 
  •  

Question

I created Store pick up module, everything is working on the front, there is problem on the back.

When I creating order in admin I added dropdown with all the stores. So when you select one store fields in shipping address got populated with data, I am using jQuery for that

$rdj.getJSON('<?php echo Mage::getUrl('ustorelocator/location/storeDetailsAjax'); ?>', function(jd) {
                $rdj.each(jd, function(i, value) {
                    //var storeArray = [];
                    $rdj('.rd_stores').append($rdj('<option>').text(value.title + ' (' + value.notes_delivery + ')').attr('value', i));
                });

                $rdj('.rd_stores').on('change', function() {
                    var v = this.value;
                    var fname = $rdj('input[name="order[billing_address][firstname]"]').val();
                    var lname = $rdj('input[name="order[billing_address][lastname]"]').val();
                    $rdj('input[name="order[shipping_address][firstname]"]').val(fname);
                    $rdj('input[name="order[shipping_address][lastname]"]').val(lname);
                    $rdj('input[name="order[shipping_address][telephone]"]').val(jd[v].phone);
                    $rdj('input[name="order[shipping_address][postcode]"]').val(jd[v].postcode);
                    $rdj('input[name="order[shipping_address][company]"]').val('ROBERT DYAS - ' + jd[v].title + ' ('+ jd[v].store_id + ')');
                    $rdj('input[name="order[shipping_address][street][0]"]').val(jd[v].street);
                    $rdj('input[name="order[shipping_address][street][1]"]').val('');
                    $rdj('input[name="order[shipping_address][city]"]').val(jd[v].city);
                    $rdj('input[name="rd_notes_delivery"]').val(jd[v].notes_delivery);
                    $rdj('input[name="rd_store_email"]').val(jd[v].store_email);
                    $rdj('input[name="rd_opening_hours"]').val(jd[v].notes);
                });
            });

I am using $rdj to avoid conflicts. As you can see I am creating json with module and using it here to populate dropdown and then based on a value of the store selected I filled the shipping address fields with data.

Problem is that after I do this Form Data (post action) is not updated so I don't get shipping methods!

How can I refresh this? I noticed that if you click same as billing address update is triggering this: shipping_method,billing_method,shipping_address,totals,giftmessage?isAjax=true

Was it helpful?

Solution

Solution:

ok, so I added this function to js/mage/sales.js

selectStore: function() {
    var data = this.serializeData(this.shippingAddressContainer);
    data = data.toObject();
    this.loadArea(['shipping_method', 'billing_method', 'shipping_address', 'totals', 'giftmessage'], true, data);
}

and to my jQuery where I am following change on dropdown I am calling:

order.storeSelect();

at the end, after I filled all the shipping address fields.

This is working, Form data is now set and shipping method is shown.

Is there any way to define this extra function out of the sales.js? Because this js is a part of the core js files?

I am not prototype.js expert

UPDATE Ok, I finally relised why Magento using Prototype, because the overwriting is the same as Zend framework. So to add method to a Mage js file you need to do this:

Create your js file in js/your_name_folder/your_file.js Because I need to add method to sales.js if you go there and check top of the page you will see this: var AdminOrder = new Class.create(); AdminOrder.prototype = {

so in your your_file.js you need to add your method to class (in this case) AdminOrder and you do it like this:

AdminOrder.addMethods({
    selectStore: function() {
        var data = this.serializeData(this.shippingAddressContainer);
        data = data.toObject();
        this.loadArea(['shipping_method', 'billing_method', 'shipping_address', 'totals', 'giftmessage'], true, data);
    }

});

Then you go to design/adminhtml/default/your_theme/layout/local.xml and in my case I need to add my js file to adminhtml_sales_order_create_index That is it. Hope this helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top