Page 1 of 1

Order Edit: Extract name and country from delivery address

Posted: Sat Jan 28, 2023 7:07 am
by Moxamint
Hi,

In admin=>orders=>edit of any order, the page title is something like "Order #56", for example. To make the order number match a specific naming convention, I need to extract the customer/recipient's name and the country name from the delivery address to add to the page title. How do I do that?

I know the code displaying all data of an order is in admin/actions/orders/views/edit.php, and I am aware I probably need to change the core code. I tried extracting the data mentioned above but failed.

Thanks in advance for any help.

Eddy

Re: Order Edit: Extract name and country from delivery address

Posted: Sat Jan 28, 2023 8:18 am
by Kofod95
Instead of editing core, I think you could hi-jack the action and redirect it to your custom action with a hook.
Alternatively, you might be able to just hook in some JavaScript to append the data to the title.

If you look in invoice.php, I think you can see how to get the data you need.

Sorry for being brief and vague, I'll try to expound on stuff, if you need it!

//Daniel

Re: Order Edit: Extract name and country from delivery address

Posted: Sat Jan 28, 2023 9:51 am
by Moxamint
Kofod95 wrote: Sat Jan 28, 2023 8:18 am Instead of editing core, I think you could hi-jack the action and redirect it to your custom action with a hook.
Alternatively, you might be able to just hook in some JavaScript to append the data to the title.

If you look in invoice.php, I think you can see how to get the data you need.

Sorry for being brief and vague, I'll try to expound on stuff, if you need it!

//Daniel
Unlike customer data, name and country in delivery & billing addresses are merged into $address for invoice.php, so I probably need to do my own database query to get those data separately - at least, that's the only way I can think of. I do not know enough to code a hook or js to change the behavior of the original code. Probably time for me to learn coding in new ways.

Re: Order Edit: Extract name and country from delivery address

Posted: Sat Jan 28, 2023 10:10 pm
by Kofod95
I think you could make a hook in includes/hooks/admin/orders listening to inject_redirects, which would have to check for action=edit and then redirect to action=your_custom_edit.

If going the JS-way, there is a function that gets elements from classes (https://www.w3schools.com/jsref/met_doc ... ssname.asp) after which you should be able to append your custom data. So still includes/hooks/admin/orders, but probably just listening to injectSiteend (or whatever it's called) with some php that adds the data to variables that you then add to the JS (there are examples of this last part in some of the supporters code - in fact all that adds a new tab for product-edits, if I remember correctly). The data should be obtainable with either (or maybe both) $order->info or $customer_data->get, but I don't remember exactly how.

//Daniel

Re: Order Edit: Extract name and country from delivery address

Posted: Sat Jan 28, 2023 11:12 pm
by Moxamint
Kofod95 wrote: Sat Jan 28, 2023 10:10 pm I think you could make a hook in includes/hooks/admin/orders listening to inject_redirects, which would have to check for action=edit and then redirect to action=your_custom_edit.

If going the JS-way, there is a function that gets elements from classes (https://www.w3schools.com/jsref/met_doc ... ssname.asp) after which you should be able to append your custom data. So still includes/hooks/admin/orders, but probably just listening to injectSiteend (or whatever it's called) with some php that adds the data to variables that you then add to the JS (there are examples of this last part in some of the supporters code - in fact all that adds a new tab for product-edits, if I remember correctly). The data should be obtainable with either (or maybe both) $order->info or $customer_data->get, but I don't remember exactly how.

//Daniel
Thanks, Daniel - much appreciated! I'll do my best and give it a try. Cheers, Eddy

Re: Order Edit: Extract name and country from delivery address

Posted: Sun Jan 29, 2023 7:18 am
by Kofod95
I wish you good luck!
If you get stuck, I think I could be a little more helpful, and maybe others know better than me - as a PRO-Supporter you have of course also the option to post in the VIP-forum to get expert advice from core coders, should we fail to solve things here. So at least there is a fallback;)
-anyway, I look forward to hear of your progress!

//Daniel

Re: Order Edit: Extract name and country from delivery address

Posted: Wed Feb 01, 2023 4:58 am
by Moxamint
Kofod95 wrote: Sun Jan 29, 2023 7:18 am I wish you good luck!
If you get stuck, I think I could be a little more helpful, and maybe others know better than me - as a PRO-Supporter you have of course also the option to post in the VIP-forum to get expert advice from core coders, should we fail to solve things here. So at least there is a fallback;)
-anyway, I look forward to hear of your progress!

//Daniel
Thanks to @zipurman who coded for me a hook with 24 lines of js. It is kind of tricky, though, as the "ship to" address is just a block of text separated by line breaks. Anyway, it's perfectly working!

Cheers, Eddy