Skip to content

Commit 47e031e

Browse files
committed
Fix SubscriptionOrderCloner in ORM 3
1 parent c798446 commit 47e031e

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/Cloner/SubscriptionOrderCloner.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Sylius\MolliePlugin\Entity\OrderInterface;
2525
use Sylius\MolliePlugin\Model\AdjustmentInterface;
2626
use Webmozart\Assert\Assert;
27+
use Sylius\Component\Core\Model\AddressInterface;
2728

2829
final class SubscriptionOrderCloner implements SubscriptionOrderClonerInterface
2930
{
@@ -67,10 +68,14 @@ public function clone(
6768
$clonedOrder->setPaymentState(OrderPaymentStates::STATE_AWAITING_PAYMENT);
6869
$clonedOrder->setPromotionCoupon($order->getPromotionCoupon());
6970

70-
Assert::notNull($order->getShippingAddress());
71+
$shippingAddress = $order->getShippingAddress();
72+
Assert::notNull($shippingAddress);
73+
$clonedOrder->setShippingAddress($this->hydrateAndClone($shippingAddress));
74+
75+
$billingAddress = $order->getBillingAddress();
7176
Assert::notNull($order->getBillingAddress());
72-
$clonedOrder->setShippingAddress(clone $order->getShippingAddress());
73-
$clonedOrder->setBillingAddress(clone $order->getBillingAddress());
77+
$clonedOrder->setBillingAddress($this->hydrateAndClone($billingAddress));
78+
7479
$clonedOrder->setShippingState(OrderShippingStates::STATE_READY);
7580
$clonedOrder->setTokenValue($this->randomnessGenerator->generateUriSafeString(10));
7681

@@ -113,4 +118,22 @@ public function clone(
113118

114119
return $clonedOrder;
115120
}
121+
122+
/** Hydrates the proxy data of the address before cloning it */
123+
private function hydrateAndClone(AddressInterface $address): AddressInterface
124+
{
125+
$address->getFirstName();
126+
$address->getLastName();
127+
$address->getCompany();
128+
$address->getStreet();
129+
$address->getCity();
130+
$address->getPostcode();
131+
$address->getCountryCode();
132+
$address->getProvinceCode();
133+
$address->getProvinceName();
134+
$address->getPhoneNumber();
135+
$address->getCustomer();
136+
137+
return clone $address;
138+
}
116139
}

src/Subscription/Processor/SubscriptionProcessor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ private function process(MollieSubscriptionInterface $subscription): PaymentInte
8080
$subscription->getSubscriptionConfiguration(),
8181
$clonedOrder,
8282
);
83-
$payment->setDetails(
84-
$details,
85-
);
83+
$payment->setDetails($details);
8684
$clonedOrder->addPayment($payment);
8785
$this->orderRepository->add($clonedOrder);
8886

0 commit comments

Comments
 (0)