Add email and phone properties to Shipping class

This commit is contained in:
Philipp Stracker 2025-06-16 19:22:04 +02:00
parent fb079bc456
commit 4c0cf0abfa
No known key found for this signature in database

View file

@ -28,6 +28,16 @@ class Shipping {
*/
private $address;
/**
* Custom contact email address, usually added via the Contact Module.
*/
private ?string $email_address = null;
/**
* Custom contact phone number, usually added via the Contact Module.
*/
private ?Phone $phone_number = null;
/**
* Shipping methods.
*
@ -38,14 +48,18 @@ class Shipping {
/**
* Shipping constructor.
*
* @param string $name The name.
* @param Address $address The address.
* @param ShippingOption[] $options Shipping methods.
* @param string $name The name.
* @param Address $address The address.
* @param string|null $email_address Contact email.
* @param Phone|null $phone_number Contact phone.
* @param ShippingOption[] $options Shipping methods.
*/
public function __construct( string $name, Address $address, array $options = array() ) {
$this->name = $name;
$this->address = $address;
$this->options = $options;
public function __construct( string $name, Address $address, string $email_address = null, Phone $phone_number = null, array $options = array() ) {
$this->name = $name;
$this->address = $address;
$this->email_address = $email_address;
$this->phone_number = $phone_number;
$this->options = $options;
}
/**
@ -66,6 +80,24 @@ class Shipping {
return $this->address;
}
/**
* Returns the contact email address, or null.
*
* @return null|string
*/
public function email_address() : ?string {
return $this->email_address;
}
/**
* Returns the contact phone number, or null.
*
* @return null|Phone
*/
public function phone_number() : ?Phone {
return $this->phone_number;
}
/**
* Returns the shipping methods.
*
@ -87,6 +119,17 @@ class Shipping {
),
'address' => $this->address()->to_array(),
);
$contact_email = $this->email_address();
$contact_phone = $this->phone_number();
if ( $contact_email ) {
$result['email_address'] = $contact_email;
}
if ( $contact_phone ) {
$result['phone_number'] = $contact_phone->to_array();
}
if ( $this->options ) {
$result['options'] = array_map(
function ( ShippingOption $opt ): array {