What is the best way to handle shipping cost?

Hello,

I am going to use strapi as the backend for ecommerce site. May I ask what is the best to handle shipping cost? Currently I have the order collection type which includes address component, order details component, tracking component and also status and payment fields. The shipping cost shall vary on countries and the amount of items purchased (in my case).

I don’t want to handle that in the frontend because it will be hard to modify.

Best

You should create an API which calculates the shipping cost when the countries are changed in front-end, then display it in cart during checkout. All the rules (prices/calculations) should be definen in backend, not in frontend.

1 Like

Yeah custom controllers here, you could write a function also in the ./config/functions and customize the existing controllers to calculate it per request.

1 Like

Let’s say that there is a country selector in the checking out page. Once the user selects a country, send asynchronous POST request (for example to the router /order/checkshipping) with items in cart and country name to strapi (the order is not yet created). And in the checkShipping controller, it calls a custom shipping.js within functions folder to calculate the shipping cost and return the result.

Then directly get the response result and show it in frontend.

Do I understand correctly?

1 Like

Yup exactly :slight_smile:

1 Like

Thank you all, I have tested my code and solved the problem.

1 Like