Skip to content

Commit 907e648

Browse files
authored
bug #299 Fix ProcessPayPalOrderAction (maikrosenthal)
This PR was merged into the 1.6 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.6 (bug fixes, improvements) | Bug fix? | yes | New feature? | no A customer name can contain more than just a first name and last name. It could also contain a salutation, middle names or a title. Using only the first two words of the full_name is therefore not sufficient. The customer is also added to the address created. This means that the customer can change their shipping address after completing the order and can therefore influence the calculation of shipping costs and tax. Commits ------- a75f2d2 Do not add the customer to the address 464d258 Save the full name of the shipping address 415eda5 Removed unused constructor parameter
2 parents 71c9bc2 + 415eda5 commit 907e648

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

UPGRADE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@
3434
)
3535
```
3636

37+
`Sylius\PayPalPlugin\Controller\ProcessPayPalOrderAction`:
38+
```diff
39+
public function __construct(
40+
- private readonly OrderRepositoryInterface $orderRepository,
41+
private readonly CustomerRepositoryInterface $customerRepository,
42+
private readonly FactoryInterface $customerFactory,
43+
private readonly AddressFactoryInterface $addressFactory,
44+
private readonly ObjectManager $orderManager,
45+
private readonly StateMachineFactoryInterface|StateMachineInterface $stateMachineFactory,
46+
private readonly PaymentStateManagerInterface $paymentStateManager,
47+
private readonly CacheAuthorizeClientApiInterface $authorizeClientApi,
48+
private readonly OrderDetailsApiInterface $orderDetailsApi,
49+
private readonly OrderProviderInterface $orderProvider,
50+
)
51+
```
52+
3753
### UPGRADE FROM 1.5.1 to 1.6.0
3854

3955
1. Support for Sylius 1.13 has been added, it is now the recommended Sylius version to use.

src/Controller/ProcessPayPalOrderAction.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Sylius\Component\Core\Model\PaymentMethodInterface;
2424
use Sylius\Component\Core\OrderCheckoutTransitions;
2525
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
26-
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
2726
use Sylius\Component\Resource\Factory\FactoryInterface;
2827
use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface;
2928
use Sylius\PayPalPlugin\Api\OrderDetailsApiInterface;
@@ -36,7 +35,6 @@
3635
final class ProcessPayPalOrderAction
3736
{
3837
public function __construct(
39-
private readonly OrderRepositoryInterface $orderRepository,
4038
private readonly CustomerRepositoryInterface $customerRepository,
4139
private readonly FactoryInterface $customerFactory,
4240
private readonly AddressFactoryInterface $addressFactory,
@@ -78,12 +76,12 @@ public function __invoke(Request $request): Response
7876

7977
$purchaseUnit = (array) $data['purchase_units'][0];
8078

81-
$address = $this->addressFactory->createForCustomer($customer);
79+
$address = $this->addressFactory->createNew();
8280

8381
if ($order->isShippingRequired()) {
8482
$name = explode(' ', $purchaseUnit['shipping']['name']['full_name']);
85-
$address->setFirstName($name[0]);
86-
$address->setLastName($name[1]);
83+
$address->setLastName(array_pop($name) ?? '');
84+
$address->setFirstName(implode(' ', $name));
8785
$address->setStreet($purchaseUnit['shipping']['address']['address_line_1']);
8886
$address->setCity($purchaseUnit['shipping']['address']['admin_area_2']);
8987
$address->setPostcode($purchaseUnit['shipping']['address']['postal_code']);

0 commit comments

Comments
 (0)