November Happy Hour will be moved to Thursday December 5th.

Get shipping fee based on weight of order

Vote:
 

Hi!

Basically I'm wondering how to set up shipping cost based on weight of the ordered items? For example, the base price for shipping is $5 then if the total weight > 1 kg add an extra $5 to the shipping cost. In CM, we have setup a shipping method with the weight/jurisdiction gateway. When calculating the shipping cost we do:

var methods = ShippingManager.GetShippingMethodsByMarket(MarketId.Default.Value, false).ShippingMethod;

var rates = methods.Where(shippingMethodRow =>

    currentLanguage.Equals(shippingMethodRow.LanguageId, StringComparison.OrdinalIgnoreCase) &&

    String.Equals(currencyId, shippingMethodRow.Currency, StringComparison.OrdinalIgnoreCase)).

    OrderBy(shippingMethodRow => shippingMethodRow.Ordering).

    Select(shippingMethodRow => GetRate(shipment, shippingMethodRow));

This selects the correct shipping method but GetRate returns null. Any ideas why or is there another(better?) way to do it?

We are using Commerce 9.4.

Thanks!

#172739
Dec 09, 2016 15:54
Vote:
 

Hi,

This's the right way to using weight jurisdiction gateway to get shipping rate. But when i look at your implement, i don't think the GetRate() used correctly. It should be 

GetRate(shippingMethodId, shipment, ref message);

There're some reasons GetRate returns null, i example shipment or shipment.ShippingAddress is null.

#172816
Dec 13, 2016 8:41
Vote:
 

Adding shippingAddress to the shipment did the trick, thank you!

#172876
Dec 13, 2016 11:24
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.