Z
Z
Zittz2017-03-01 13:37:11
Prestashop
Zittz, 2017-03-01 13:37:11

How to correctly calculate the shipping cost in your prestashop shipping module?

Hello.
I'm trying to write my own delivery module for Prestashop 1.6. The official documentation says that the getOrderShippingCost() method is used for the calculation, which should return the shipping cost. But the situation is that, as debugging shows, this method is called on each page of the store, if the user has specified an address that matches.
In this method, I calculate the cost of delivery through a third-party API, because it is wrong to calculate it when entering any page of the store. You need to calculate the cost only when the user already makes an order.
How to implement it correctly? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zitttz, 2017-03-02
@Zitttz

In general, I will describe what I did myself ... I
created an intermediate cache table in which I store the user's address, the weight for which there was already a calculation and the amount of delivery.
When calling getOrderShippingCost(), first, an entry in cache is searched for by the address and total weight of the user, if it is not found, then api is called. Also, records older than one day are deleted with each search.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question