From 83e6dfe599257b629db6a9dd5dd7e2a9dbfe7afb Mon Sep 17 00:00:00 2001 From: EugeneShab Date: Tue, 5 Dec 2023 13:14:29 +0200 Subject: [PATCH] feat: Fix saving billing address on completing checkout with a virtual product. Refs: #7 --- src/SubscribePro/Service/Subscription/Subscription.php | 4 ++++ src/SubscribePro/Service/Subscription/SubscriptionFactory.php | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/SubscribePro/Service/Subscription/Subscription.php b/src/SubscribePro/Service/Subscription/Subscription.php index 31dfcdf..3044c34 100755 --- a/src/SubscribePro/Service/Subscription/Subscription.php +++ b/src/SubscribePro/Service/Subscription/Subscription.php @@ -133,6 +133,10 @@ public function getFormData() $formData[self::SHIPPING_ADDRESS] = $this->getShippingAddress()->getAsChildFormData($this->isNew()); } + if ($this->getBillingAddress() instanceof AddressInterface) { + $formData[self::BILLING_ADDRESS] = $this->getBillingAddress()->getAsChildFormData($this->isNew()); + } + if (!empty($formData[self::SHIPPING_ADDRESS_ID])) { unset($formData[self::SHIPPING_ADDRESS]); } else { diff --git a/src/SubscribePro/Service/Subscription/SubscriptionFactory.php b/src/SubscribePro/Service/Subscription/SubscriptionFactory.php index e8fd231..8e95ad8 100644 --- a/src/SubscribePro/Service/Subscription/SubscriptionFactory.php +++ b/src/SubscribePro/Service/Subscription/SubscriptionFactory.php @@ -53,6 +53,9 @@ public function create(array $data = []) $addressData = $this->getFieldData($data, SubscriptionInterface::SHIPPING_ADDRESS); $data[SubscriptionInterface::SHIPPING_ADDRESS] = $this->addressFactory->create($addressData); + $addressData = $this->getFieldData($data, SubscriptionInterface::BILLING_ADDRESS); + $data[SubscriptionInterface::BILLING_ADDRESS] = $this->addressFactory->create($addressData); + $paymentProfileData = $this->getFieldData($data, SubscriptionInterface::PAYMENT_PROFILE); $data[SubscriptionInterface::PAYMENT_PROFILE] = $this->paymentProfileFactory->create($paymentProfileData);