6
6
use Setono \SyliusPickupPointPlugin \Client \ClientInterface ;
7
7
use Setono \SyliusPickupPointPlugin \Factory \Bpost \ServicePointQueryFactory ;
8
8
use Setono \SyliusPickupPointPlugin \Factory \ServicePointQueryFactoryInterface ;
9
- use Setono \SyliusPickupPointPlugin \Model \Query \Bpost \ServicePointQueryInterface ;
9
+ use Setono \SyliusPickupPointPlugin \Model \Query \Bpost ;
10
+ use Setono \SyliusPickupPointPlugin \Model \Query \CountryAwareInterface ;
10
11
use Setono \SyliusPickupPointPlugin \Transformer \PickupPointTransformerInterface ;
11
12
use Setono \SyliusPickupPointPlugin \Exception \TimeoutException ;
12
13
use Setono \SyliusPickupPointPlugin \Model \PickupPointCode ;
13
14
use Setono \SyliusPickupPointPlugin \Model \PickupPointInterface ;
14
15
use Sylius \Component \Core \Model \OrderInterface ;
15
16
16
17
/**
17
- * @see https://pudo.bpost.be/ServicePointQuery for more information
18
+ * @see https://pudo.bpost.be/ for more information
18
19
*/
19
20
final class BpostProvider extends Provider
20
21
{
@@ -44,20 +45,12 @@ public function __construct(
44
45
45
46
public function findPickupPoints (OrderInterface $ order ): iterable
46
47
{
47
- $ shippingAddress = $ order ->getShippingAddress ();
48
- if (null === $ shippingAddress ) {
49
- return [];
50
- }
51
-
52
- $ countryCode = $ shippingAddress ->getCountryCode ();
53
- if (null === $ countryCode ) {
54
- return [];
55
- }
56
-
57
48
$ servicePointQuery = $ this ->getServicePointQueryFactory ()->createServicePointQueryForOrder ($ order );
58
49
$ servicePoints = $ this ->client ->locate ($ servicePointQuery );
59
50
foreach ($ servicePoints as $ item ) {
60
- $ item ['country ' ] = $ countryCode ;
51
+ if ($ servicePointQuery instanceof CountryAwareInterface) {
52
+ $ item ['country ' ] = $ servicePointQuery ->getCountry ();
53
+ }
61
54
yield $ this ->transform ($ item );
62
55
}
63
56
}
@@ -67,12 +60,16 @@ public function findPickupPoint(PickupPointCode $code): ?PickupPointInterface
67
60
$ servicePoints = [];
68
61
try {
69
62
$ servicePointQuery = $ this ->getServicePointQueryFactory ()->createServicePointQueryForPickupPoint ($ code );
70
- foreach (ServicePointQueryInterface::TYPES as $ type ) {
71
- $ servicePointQuery ->setType ($ type );
72
- $ servicePoints = $ this ->client ->locate ($ servicePointQuery );
73
- if (count ($ servicePoints ) > 0 ) {
74
- break ;
63
+ if ($ servicePointQuery instanceof Bpost \ServicePointQueryInterface) {
64
+ foreach (Bpost \ServicePointQueryInterface::TYPES as $ type ) {
65
+ $ servicePointQuery ->setType ($ type );
66
+ $ servicePoints = $ this ->client ->locate ($ servicePointQuery );
67
+ if (count ($ servicePoints ) > 0 ) {
68
+ break ;
69
+ }
75
70
}
71
+ } else {
72
+ $ servicePoints = $ this ->client ->locate ($ servicePointQuery );
76
73
}
77
74
} catch (NetworkExceptionInterface $ e ) {
78
75
throw new TimeoutException ($ e );
@@ -92,8 +89,6 @@ public function findAllPickupPoints(): iterable
92
89
try {
93
90
foreach ($ this ->countryCodes as $ countryCode ) {
94
91
$ servicePointQuery = $ this ->getServicePointQueryFactory ()->createServicePointQueryForAllPickupPoints ($ countryCode );
95
-
96
- $ servicePointQuery ->setCountry ($ countryCode );
97
92
$ servicePoints = $ this ->client ->locate ($ servicePointQuery );
98
93
foreach ($ servicePoints as $ item ) {
99
94
$ item ['country ' ] = $ countryCode ;
0 commit comments