66use  Setono \SyliusPickupPointPlugin \Client \ClientInterface ;
77use  Setono \SyliusPickupPointPlugin \Factory \Bpost \ServicePointQueryFactory ;
88use  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 ;
1011use  Setono \SyliusPickupPointPlugin \Transformer \PickupPointTransformerInterface ;
1112use  Setono \SyliusPickupPointPlugin \Exception \TimeoutException ;
1213use  Setono \SyliusPickupPointPlugin \Model \PickupPointCode ;
@@ -44,20 +45,12 @@ public function __construct(
4445
4546    public  function  findPickupPoints (OrderInterface   $ order ): iterable 
4647    {
47-         $ shippingAddress  = $ order ->getShippingAddress ();
48-         if  (null  === $ shippingAddress ) {
49-             return  [];
50-         }
51- 
52-         $ countryCode  = $ shippingAddress ->getCountryCode ();
53-         if  (null  === $ countryCode ) {
54-             return  [];
55-         }
56- 
5748        $ servicePointQuery  = $ this  ->getServicePointQueryFactory ()->createServicePointQueryForOrder ($ order );
5849        $ servicePoints  = $ this  ->client ->locate ($ servicePointQuery );
5950        foreach  ($ servicePoints  as  $ item ) {
60-             $ item ['country ' ] = $ countryCode ;
51+             if  ($ servicePointQuery  instanceof  CountryAwareInterface) {
52+                 $ item ['country ' ] = $ servicePointQuery ->getCountry ();
53+             }
6154            yield  $ this  ->transform ($ item );
6255        }
6356    }
@@ -67,12 +60,16 @@ public function findPickupPoint(PickupPointCode $code): ?PickupPointInterface
6760        $ servicePoints  = [];
6861        try  {
6962            $ 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+                     }
7570                }
71+             } else  {
72+                 $ servicePoints  = $ this  ->client ->locate ($ servicePointQuery );
7673            }
7774        } catch  (NetworkExceptionInterface   $ e ) {
7875            throw  new  TimeoutException ($ e );
@@ -92,8 +89,6 @@ public function findAllPickupPoints(): iterable
9289        try  {
9390            foreach  ($ this  ->countryCodes  as  $ countryCode ) {
9491                $ servicePointQuery  = $ this  ->getServicePointQueryFactory ()->createServicePointQueryForAllPickupPoints ($ countryCode );
95- 
96-                 $ servicePointQuery ->setCountry ($ countryCode );
9792                $ servicePoints  = $ this  ->client ->locate ($ servicePointQuery );
9893                foreach  ($ servicePoints  as  $ item ) {
9994                    $ item ['country ' ] = $ countryCode ;
0 commit comments