Question:
I'm developing a virtual store and I need to implement the shipping calculation for the purchase, I managed to do this implementation but the problem is that with a single product in the cart I get the correct return, but with several products in the cart the values do not match with the simulator of the logistics company.
I wanted to know how do I calculate the shipping of several products together. If I calculate the cubage of each one separately and then add them all up, or if I calculate the cubage with the sum of the dimensions of the products, or what is the correct way to do this.
I'm lost in relation to this calculation because there is only content on the internet explaining the calculation of individual products and I can't solve this issue.
Answer:
To make a calculation that matches the logistics company's, you would have to do the same calculation they do. Each company can have its own criteria:

just weight

dimension: width + height + depth not exceeding a set value (airline type: the sum of width + height + depth cannot exceed 115 cm)

dimension: in the combination of product sizes, it is possible to assemble a box with maximum limits of width, height and depth, and having the problem of optimizing your products to fit in this box

a fixed amount for the first pack and then a smaller amount for each extra pack

a fixed amount for the first kilo and a smaller amount for each extra kilo

a combination of any of the above rules.
If the rules are on any website, use the rules they explain (eg you use Correios do Brasil, you can see the rules on their website)
If not, just asking and getting their answer.
And if they provide an interface that you can access, have your program feed them the data and have them calculate it for you, if your contract with them allows it.
Unfortunately, any answer without knowing your logistics company or the criteria they use will only be general tips and speculation and will be difficult to help.