hook for firstname / lastname needed for orders Class

Open to all! Ask other shopowners for help.
Post Reply
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

hook for firstname / lastname needed for orders Class

Post 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: hook for firstname / lastname needed for orders Class

Post 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.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: hook for firstname / lastname needed for orders Class

Post 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....
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: hook for firstname / lastname needed for orders Class

Post 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.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: hook for firstname / lastname needed for orders Class

Post 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>";
      }
    }


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply