Sylius / ShopApiPlugin

Shop API for Sylius.
https://sylius.com
129 stars 89 forks source link

[HELP] - Get available shipping methods - Is there any way to get shipping methods using the province, city, zone, or postcode of the address? #690

Closed hasithaarimac closed 3 years ago

hasithaarimac commented 3 years ago

Hi,

I have a little problem to clarify from you guys. In my scenario, I need to set multiple shipping methods with multiple Provinces (Which have a single parent country).

Please look at the below steps:

  1. Added "Germany" to the countries list.
  2. Added two provinces under Germany (Berlin and Hamburg).
  3. Created a Zone (Type: Country) using 'Germany'.
  4. Created a Zone (Type: Province) by using "Berlin".
  5. Created a shipping method using the "Berlin" zone and defined a shipping Amount.
  6. Again, Created a shipping method using the "Hamburg" zone and defined a shipping Amount.

Below scenarios simulated using sylius shop-apis,

  1. Logged as a user and created a cart.
  2. Added an Item to the cart.
  3. Then addressed the cart. ( Country code: DE / Province name: Berlin)
  4. Hit "/shop-api/checkout/{{cart}}/shipping" method to get available shipping methods of the Berlin area.

Unfortunately, I'm not getting any shipping methods for the above address. ("/shop-api/checkout/{{cart}}/shipping"). But If created a shipping method using the Germany zone, then I'm getting created shipping methods. Is there any way to simulate this process? I need to define shipping methods for multiple areas of a single country. And also I need to get matching shipping methods after we addressing the cart. Is there any way to get these shipping methods using the province, city, zone, or postcode of the given address instead of the country code?

County added :

image

Provinces added :

image

Shipping method added :

image

Addressed the cart :

image

Get available shipping methods :

image

mamazu commented 3 years ago

Hello, first of all your steps are all correct and this the correct way to address the order and get shipping information by province. However it looks like you are missing the provinceCode property (this is actually a missing feature in the documentation). If you set the provinceCode instead of the provinceName in your address, it will validate if the province exists and set name and code on the order.

About your second question: If I understand it right you are looking for an endpoint that takes any address and returns a list of shipping methods. This is not part of the standard shopapi. But using the ShippingMethodResolver like here: https://github.com/Sylius/ShopApiPlugin/blob/8fe5f49cb1c3015922fff2c362cb0d03782f3373/src/Controller/Checkout/ShowAvailableShippingMethodsAction.php#L79 you can display shipping methods for any address. You just need to create a seperate endpoint.

hasithaarimac commented 3 years ago

Thank you @mamazu for the response. I'll update the province code. Thanks for the valuable inputs. Cheers