# Need advice on shipping calculation

## 8 posts in this topic

Recently our store started selling online fireplaces and its accessories, products are really heavy, starting from 50Kg to 500kg and maybe more.

The shipping company DHL charges us 5\$ for each 0.5Kg

Using the zone rates, i have to write a string of incremental weight and price, starting from 0 to reach 500kg+, I have to write 1000 piece of mordor code for every geozone, e.g. 3:8.50,7:10.50,99:20.00 ...............................

is there a way to write only something like : 5\$ per 0.5Kg ?

##### Share on other sites

should not be too difficult to change it do that you apply the rate (per kg) to the actual shopping cart weight upto a certain limit

##### Share on other sites

if you post the code, we ll indicate what to change ...

##### Share on other sites

Posted (edited)

Here is the conceptual code:

```\$rate_table = preg_split("/[:,]/" , constant('MODULE_SHIPPING_ZONE_COST_' . \$dest_zone));
\$table_size = sizeof(\$rate_table);
\$tmp_weight = ceil(\$shipping_weight);

for (\$i=0; \$i<\$table_size-2 && \$tmp_weight>0; \$i+=2) {                 #####################################################
\$shipping += min(\$tmp_weight, \$rate_table[\$i]) * \$rate_table[\$i+1];  #  If zone shipping is 2:5.3,4:4.2,1:3.1            #
\$tmp_weight -= floatval(\$rate_table[\$i]);                            #  it means the first 2KG costs \$5.3 per kilo       #
}                                                                      #           the next 4KG costs \$4.2 per kilo        #
#           the rest of weight costs \$3.1 per kilo  #
if (\$tmp_weight > 0) \$shipping += \$tmp_weight * \$rate_table[\$i+1];     #####################################################
```

So you simply double the total weight and the rate table would be as simple as 1:5 if you charge \$5 for every 0.5 kilo.

Edited by Moxamint
Psytanium and bruyndoncx like this

##### Share on other sites

conceptually looking good to me , the proof is in the pudding or not ? @@Psytanium

##### Share on other sites

@@Moxamint thank you, its working as you said. but is there a way to make it work per 0.5 kg ?

##### Share on other sites

Posted (edited)

@@Moxamint thank you, its working as you said. but is there a way to make it work per 0.5 kg ?

@@Psytanium Double the weight.

Cheers, Eddy

Edited by Moxamint

##### Share on other sites

Line 3 => \$tmp_weight = 2 * ceil(\$shipping_weight);

Psytanium likes this