Hi all,
I am building a solution that has three different kinds of shipping methods. However two of them cannot be used if the total weight of the order is more than 20kg. Therefore I would like to disable them if they are not valid.
I think i have found a solution for this - but i am not sure if it is a valid approach or (in lack of better words) a stupid one.
If the total weight of the order exceeds 20kg i have set the price of the two invalid shipping methods to 1000
In the @LoopStart(Shippingmethods) i have made a check - if the price is 1000 then the shipping method is not shown.
If the user has ordered products that weigh less than 20kg and started the checkout flow and selected one of the shipping methods that can be invalid (depending on the weight) - and then decides to put more stuff into the cart that makes the total weight exceed 20kg and then proceeds to the checkout flow - then i have made a check on (Ecom:Order.ShippingFee.Price>999)
If @If(Ecom:Order.ShippingFee.Price>999) is true the loop below is executed:
$(document).ready(function(){
<!--@LoopStart(Shippingmethods)-->
<!--@If(Ecom:Cart.ShippingMethod.Price.Price<1000)-->
$("#EcomCartShippingmethodID_<!--@Ecom:Cart.Shippingmethod.ID-->").prop('checked', true);
<!--@EndIf-->
<!--@LoopEnd(Shippingmethods)-->
});
It seems to be working. I know that it is not bulletproof and will fail if the user have javascript disabled - but apart from that - does it look like something that safe to use?
Kind regards
Sonni T.