From 4c0cf0abfaeda6276f57b6b1e84437187e1320a6 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 16 Jun 2025 19:22:04 +0200
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20email=20and=20phone=20propert?=
=?UTF-8?q?ies=20to=20Shipping=20class?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ppcp-api-client/src/Entity/Shipping.php | 57 ++++++++++++++++---
1 file changed, 50 insertions(+), 7 deletions(-)
diff --git a/modules/ppcp-api-client/src/Entity/Shipping.php b/modules/ppcp-api-client/src/Entity/Shipping.php
index eeb4001dc..8af593fc9 100644
--- a/modules/ppcp-api-client/src/Entity/Shipping.php
+++ b/modules/ppcp-api-client/src/Entity/Shipping.php
@@ -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 {