Page 1 of 1
hook for firstname / lastname needed for orders Class
Posted: Wed Jun 08, 2022 9:19 am
by loop
Hi All
whenn i make a
$order = new order( $_POST['oID'] );
the array is for customer / billing / delivery like this
Code: Select all
[delivery] => Array
(
[name] => firstname lastname
[company] =>
[company2] =>
[street_address] => xxx
[suburb] =>
[city] => xxx
[postcode] => xxx
[state] =>
[country] => Array
(
[title] => xxx
)
[country_id] => 204
[address_format_id] => 1
[format_id] => 1
)
but what i need is firstname separate to lastname
so i can make $order->customer['firstname']
is this possible with a hook? thank you
Re: hook for firstname / lastname needed for orders Class
Posted: Wed Jun 08, 2022 10:06 am
by ecartz
loop wrote: ↑Wed Jun 08, 2022 9:19 am
is this possible with a hook? thank you
Well, in the sense that you can use the databaseOrderBuild hook to set arbitrary fields, yes. The problem is that the order table doesn't save the first name separately. The way that other things handle this is to split on the first space. But there's little point in doing that in the hook. You can just do that whenever you need it.
Note that if you build the order from the cart, it will have a separate first name.
Re: hook for firstname / lastname needed for orders Class
Posted: Wed Jun 08, 2022 10:16 am
by loop
hi ecartz
that's my exactly issue, in the cart prozess, i can have it as firstname, but afterwares, whenn order is done, i can't
about the "split" is difficult, as i don't know if the firstname for example "peter frank lastname" is peter oder peter frank so i can't split on a space....
Re: hook for firstname / lastname needed for orders Class
Posted: Wed Jun 08, 2022 10:39 am
by ecartz
If you don't want to split on space, you would need to save the firstname in the orders table. You can do that with
Code: Select all
class hook_shop_siteWide_firstname {
public function listen_insertOrder($parameters) {
$parameters['sql_data']['orders']['customers_firstname'] = $GLOBALS['customer_data']->get('firstname', $GLOBALS['order']->customer);
$parameters['sql_data']['orders']['delivery_firstname'] = $GLOBALS['customer_data']->get('firstname', $GLOBALS['order']->delivery);
$parameters['sql_data']['orders']['billing_firstname'] = $GLOBALS['customer_data']->get('firstname', $GLOBALS['order']->billing);
}
}
Note that you need to add the firstname columns to the orders table before doing that.
Re: hook for firstname / lastname needed for orders Class
Posted: Wed Jun 08, 2022 10:57 am
by loop
i think i found a good workarround. I search the adressbook for the names and as soon as i have a match, i use this entry
Code: Select all
$customer_query = tep_db_query("SELECT entry_firstname, entry_lastname FROM address_book WHERE customers_id = '".(int)$order->customer['id']."'");
while($customer_arr = tep_db_fetch_array($customer_query)){
if($order->billing['name'] == $customer_arr['entry_firstname']." ".$customer_arr['entry_lastname']){
echo $customer_arr['entry_firstname']." ".$customer_arr['entry_lastname']."<br>";
}
}