Q:

how to get customer name for a resesrvation in magento 2

good morning guys, in my case I want to retrieve the customer name which is responsible for doing a reservation, but I can't get any attribute from reservation describe me the customer name 
Can anyone please tell me how to get costumer name from the reservation ? , because any reservation was done by a customer.

this is  how do i get the current reservation :

public function getReservation()
    {
        return $this->_coreRegistry->registry('current_reservation');
    }

this is another way , but why it throws for me an error while fetching why ?

Why there are a problems when fetching the data 

the block :

 public function getReservationCollection()
    {
        $collection = $this->_reservationCollectionFactory->create();
        $collection->addAttributeToSelect('*');
        $collection->setPageSize();
        return $collection;
    }

the phtml file :

<?php
$res = $block->getReservationCollection();
var_dump($res);
foreach ($res as $re) {
    print_r($re->getData());
    echo "<br>";
}?>

A:

try this

Add this in block

    protected $_customers;

    public function __construct(
        .........................
        \Magento\Customer\Model\Customer $customers,
         ........................
    )
    {
        .............................
        $this->_customers = $customers;
        ...............................
    }
............................
............................

    public function getCustomer($customerId)
    {
        $customer = $this->_customers->load($customerId);
        $customer_name = $customer->getFirstname() . " " . $customer->getLastname();
        return $customer_name;
    }

Add this in phtml file 

<?php

    $res = $block->getReservationCollection();
    //var_dump($res);
    foreach ($res as $re) {
        //print_r($re->getData());
        $cust_name =  $block->getCustomer($re->getCustomerId());
        echo "quote_id : ".$re->getQuoteId()." And  Customer Name: ".$cust_name;
        echo "<br>";
    }
?>

I Hope This Helps You.

