Page 1 of 2
Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 8:58 am
by Kofod95
I could not find help (at least that I understood), in the User-guide, or on the forum, so I kindly ask if anyone could help me?
I have created a new Customer-Data-module (to be precise, I have copied the street-address and renamed every instance of "street_address"), meant for collecting the phone number of the delivery address, in case it is different from the billing address. The new field shows up, I can also see it in admin->customers, but I don't know how to make it appear on admin->orders, and prefferably also on the invoice and packingslip?
I'm assuming that I'm missing something obvious, but could anyone help me find it? I'm afraid I've stared myself blind.
I forgot to mention the first time around: The version I'm working on here is 1.0.7.12
//Daniel
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 9:29 am
by heatherbell
Kofod95 wrote: ↑Thu Mar 18, 2021 8:58 am
I could not find help (at least that I understood), in the User-guide,
That's a bit beyond the scope of the User Guide at present but well done for getting as far as you have.
Presumably you now have a new column in the address_book table in DB so I guess you need to edit orders.php, invoice.php to call and show it, may be a hook file to do that?
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 9:37 am
by Kofod95
heatherbell wrote: ↑Thu Mar 18, 2021 9:29 am
That's a bit beyond the scope of the User Guide at present but well done for getting as far as you have.
Presumably you now have a new column in the address_book table in DB so I guess you need to edit orders.php, invoice.php to call and show it, may be a hook file to do that?
I actually thought that orders.php called the customer data modules automaticly, and I just missed a setting to "activate" that call for my new module. That was why I looked in the User-guide

I have a new column, yes, so I will look into creating a hook for it, if my original assumption is wrong.
//Daniel
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 9:54 am
by ecartz
Kofod95 wrote: ↑Thu Mar 18, 2021 9:37 am
orders.php called the customer data modules automaticly
No, it does not.
It may call the address module. Certainly the packing slip and invoice do. You could add a field to the address by creating a replacement address module. But I'm not sure if you want this field to appear everywhere the address does.
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 10:03 am
by Kofod95
ecartz wrote: ↑Thu Mar 18, 2021 9:54 am
No, it does not.
It may call the address module. Certainly the packing slip and invoice do. You could add a field to the address by creating a replacement address module. But I'm not sure if you want this field to appear everywhere the address does.
Thank you for the answer, and for correcting me.
Just to clarify, I copied the street-address in the hope that it would be included on those pages, and added it to the "Delivery-Adress"-group. Do you mean something else with creating a replacement address module? Sorry for being stupid, I am a little bit smarter in Danish, but not much
I want it to appear everywhere with the address, as it is something that is needed by the courriers (is that the right word?)
//Daniel
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 10:20 am
by ecartz
I mean copy cd_traditional_address.php (e.g. to cd_address_with_phone.php) and modify it to include what you need. Note that the shortest path might require editing the address_formats table in the database as well. Although you might look at how it handles the company field as an alternative. Note that this will make it expect the same field to exist for the billing and customer addresses as well. It doesn't know the difference between different types of addresses.
Courier is an English word. It's a little out of place in the context of package delivery over a distance. It's more commonly used, at least in the US, for local deliveries of small things. Delivery drivers would be a more common term for something like UPS or FedEx. Of course, perhaps you are using a courier service in your business. I'm more inclined to think in terms of UPS/FedEx.
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 10:42 am
by Kofod95
Thank you very much!
I will do as you suggested, most likely some time tomorrow, and share my experience here when done. Your help is very appreciated, as I would never have come to that conclusion by myself, and even if I had, you have saved me hours og trial and error! I will look into the handling of the company-field, as that sounds like a possibility for the most elegant solution.
Delivery drivers sounds as what I meant, thank you for that clarification as well!
//Daniel
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 10:56 am
by heatherbell
Kofod95 wrote: ↑Thu Mar 18, 2021 10:42 am
Delivery drivers sounds as what I meant, thank you for that clarification as well!
Delivery companies in UK, including FedEx, commonly advertise themselves as 'couriers' so you weren't wrong. The words 'hauliers', 'carriers' and 'consigners' are also commonly used.
Re: Adding a new adress-field in orders.php
Posted: Thu Mar 18, 2021 3:26 pm
by Kofod95
English is confusing some times - especially when mixing American, British, other and foreign (people like me, who has english as a second language)
Thank you for letting me feel a little smarter
//Daniel
Re: Adding a new adress-field in orders.php
Posted: Sat Mar 20, 2021 7:41 am
by Kofod95
Okay, I copied and installed cd_traditional_address and added the phone field there, using the inclusion of company as a template - this was quite simple to do, big thank you ecartz! Both for the help to do it, and for the creation of customer data!
This makes my new field show up on the front-end with the delivery-address, so that's a start. However, in admin $address['recievers_phone'] is an illegal offset (I have included the ?? '' to make it not error, when a number is not present, but when one is on front-end, it's not included in admin). I have not added a field to any of the orders tables, and will try this next, unless someone can point out to me what I should do instead based on the info I provide here.
I think I will write a how-to on this, once I'm done, just in case others could find it useful. Untill now, it has required nothing but copy-paste and replace; Phoenix is awesome for making it simple to do things with no real knowledge of code!
//Daniel