Lilli73
Lilli73

Reputation: 1

Shipping = Quantity Weight Simplecart

Hello my name is Mirella and I'm Italian. Excuse me as I write because I use the Google translator. Use Simplecart but I have problems with shipping costs. My client has different shipping costs. The site will sell bottles of wine of different weights. This is the function that I created using your help but I do perform multiplication between weight and quantity. It does not work Ok. Sorry but it is the first time I write on this site and do not know good English.

me.shipping = function()
{ 
    var q = 0; 
    q += item.weight*item.quantity; 

    if(q <= 3000){ 
        return 19.00; 
    } 
    if((q >= 10000)) { 
        return 23.00; 
    } 
    if((q <= 20000)){ 
        return 24.00; 
    } 
    if((q <= 30000)){ 
        return 26.00; 
    } 
    if((q <= 50000)){ 
        return 32.00; 
    } 
    if((q <= 75000)){ 
        return 35.00; 
    } 
    if((q <= 100000)){ 
        return 39.00; 
    } 
} 

Upvotes: 0

Views: 499

Answers (3)

Lilli73
Lilli73

Reputation: 1

Function for different shipping. Problem var Q for weight. Weight X Quantity = Total Weight. Is correcty script?

me.shipping = function()
    { 
        var q = 0; 
        q += item.weight*item.quantity;

    if(q <= 3000){ 
        return 19.00; 
    } 
    if((q >= 10000)) { 
        return 23.00; 
    } 
    if((q <= 20000)){ 
        return 24.00; 
    } 
    if((q <= 30000)){ 
        return 26.00; 
    } 
    if((q <= 50000)){ 
        return 32.00; 
    } 
    if((q <= 75000)){ 
        return 35.00; 
    } 
    if((q <= 100000)){ 
        return 39.00; 
    } 
} 

Upvotes: 0

NibblyPig
NibblyPig

Reputation: 52952

if((q >= 10000)) { 
    return 23.00; 
} 

This line means that all the lines below it will never run

All of your weight checks should use <= not >=

eg.

if (q <= 100)
  // less than 100

if (q <= 200)
  // 101 to 200

if (q <= 300)
  // 201 to 300

etc.

you can finish with

else
 // more than 300

Upvotes: 1

paul
paul

Reputation: 13536

First off, it would be nice if you formatted your question - especially the code. Makes it more readable.

You could almost halve your code by doing this;

if(q <= 3000){ 
    return 19.00; 
}
if(q <= 10000){ 
    return 23.00;
} 
if(q <= 20000){ 
    return 24.00; 
} 
// ... and so on

Perhaps the real problem will become a bit clearer then :-)

Upvotes: 0

Related Questions