1

How can I get the user ID from an Ubercart order?

closed as too broad by kiamlaluno Apr 9 '18 at 7:10

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

3
use Drupal\uc_order\Entity\Order;
$order_load = Order::load($order_id); //Load Order
$ownerinfo = $order_load->getOwner(); //Fetch Owner Info
$ownerID = $order_load->getOwnerId(); //Fetch Owner ID
$ownerEmail = $order_load->getEmail(); //Fetch owner email
-2
    $connection = \Drupal::database();
$query = $connection->query("SELECT uc_orders.order_id AS order_id, users_field_data_uc_orders.uid AS users_field_data_uc_orders_uid FROM  {uc_orders} uc_orders LEFT JOIN {users_field_data} users_field_data_uc_orders ON uc_orders.uid = users_field_data_uc_orders.uid");
$result = $query->fetchAll();
foreach ($result as $record) { 
  if($record->users_field_data_uc_orders_uid != 0){ 
     $user = \Drupal\user\Entity\User::load($record->users_field_data_uc_orders_uid); // pass your uid
     $name = $user->getUsername();
     if ($name) {
        $user->addRole('attandee_role');
        $user->save();
     }
  }      
}
  • Loading DB query for getting single info is not required. And that to your query will give results of all users who have orders. If you want user id for particular order check above answer. – Ajay Reddy Apr 9 '18 at 4:51
  • On top of that the user save has nothing to do with the question – Kevin Apr 9 '18 at 14:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.