Developer forum

Forum » Ecommerce - Standard features » Hide invalid shipping methods / a valid approach

Hide invalid shipping methods / a valid approach

Sonni Tost
Reply

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.


Replies

 
Jonas Krarup Dam
Reply

Hi Sonni,

It feels slightly hacky (I guess that's why you're asking here :-) ), but I don't see a problem with it.

a more "correct" way to handle it, but which would probably require more work, would be to add settings for the weight limits somehow, maybe a template extender in a custom module or something, and compare to the <!--@Ecom:Order.Weight--> value. However, I only think this makes sense if these limits and values change often, and  if they will be handled by an editor with low technical skills.

Regards, Jonas

 
Sonni Tost
Reply

Hi Jonas,

Thank you for your input. I'll try my 'hacky' approach - and if problems occur then i'll look into your solution. Thanks!

Sonni T.

 

You must be logged in to post in the forum