Solved

I am looking for a perl shipping formula

Posted on 2011-09-21
5
385 Views
Last Modified: 2013-12-25
I have the following perl formula and I would like to find a way to change the Home_Accessories part only where it will calculate the shipping charges by using a 25% of the subtotal.
sub custom4
 {
 local ($shipMethod, $subtotal, $weight, $total_shipping, 
 $category_count) = @_; local ($shipping_price);

 if ($category_count{'Home_Accessories!'} eq "1") {

     if ($subtotal <= 100.00)      { $shipping_price = 0.00;  }

       elsif ($subtotal >= 101.00 && $subtotal <= 250.00)   { $shipping_price
 = 0.00;  }
       elsif ($subtotal >= 250.00 && $subtotal <= 1500.00)   { $shipping_price
 = 0.00; }
       
       # All orders over the previous value
       else { $shipping_price = 0.00; }
    

 } else {

if ($category_count{'Cookware!'} eq "1") {

     if ($subtotal <= 100.00)      { $shipping_price = 0.00;  }

       elsif ($subtotal >= 101.00 && $subtotal <= 250.00)   { $shipping_price
 = 0.00;  }
       elsif ($subtotal >= 250.00 && $subtotal <= 1500.00)   { $shipping_price
 = 0.00; }
       
       # All orders over the previous value
       else { $shipping_price = 0.00; }
    

 } else {
 if ($category_count{'Clocks!'} eq "1") {

     if ($subtotal <= 100.00)      { $shipping_price = 0.00;  }

       elsif ($subtotal >= 101.00 && $subtotal <= 250.00)   { $shipping_price
 = 0.00;  }
       elsif ($subtotal >= 250.00 && $subtotal <= 1500.00)   { $shipping_price
 = 0.00; }
       
       # All orders over the previous value
       else { $shipping_price = 0.00; }
    

 } else {

 if ($category_count{'Western_Accessories!'} eq "1") {
 if ($subtotal <= 29.99)      { $shipping_price = 8.50;  }

       elsif ($subtotal >= 30.00 && $subtotal <= 39.99)   { $shipping_price =
 11.50;  }
       elsif ($subtotal >= 40.00 && $subtotal <= 49.99)   { $shipping_price =
 12.00; }
       elsif ($subtotal >= 50.00 && $subtotal <= 59.99)   { $shipping_price =
 13.50; }
       elsif ($subtotal >= 60.00 && $subtotal <= 69.99)   { $shipping_price =
 15.00; }
       elsif ($subtotal >= 70.00 && $subtotal <= 79.99)   { $shipping_price =
 19.00; }
       elsif ($subtotal >= 80.00 && $subtotal <= 89.99)   { $shipping_price =
 23.00; }
       elsif ($subtotal >= 90.00 && $subtotal <= 99.99)   { $shipping_price =
 27.00; }
       elsif ($subtotal >= 100.00 && $subtotal <= 119.99)  { 
 $shipping_price = 31.00; }
       elsif ($subtotal >= 120.00 && $subtotal <= 129.99)  { 
 $shipping_price = 35.00; }
 elsif ($subtotal >= 130.00 && $subtotal <= 139.99)  { 
 $shipping_price = 39.00; }
 elsif ($subtotal >= 140.00 && $subtotal <= 149.99)  { 
 $shipping_price = 43.00; }
 elsif ($subtotal >= 150.00 && $subtotal <= 159.99)  { 
 $shipping_price = 47.00; }
 elsif ($subtotal >= 160.00 && $subtotal <= 169.99)  { 
 $shipping_price = 52.00; }     
       
       # All orders over the previous value
       else { $shipping_price = 0.00; }
    
} else {
 if ($subtotal <= 29.99)      { $shipping_price = 8.50;  }

       elsif ($subtotal >= 30.00 && $subtotal <= 39.99)   { $shipping_price =
 11.50;  }
       elsif ($subtotal >= 40.00 && $subtotal <= 49.99)   { $shipping_price =
 12.00; }
       elsif ($subtotal >= 50.00 && $subtotal <= 59.99)   { $shipping_price =
 13.50; }
       elsif ($subtotal >= 60.00 && $subtotal <= 69.99)   { $shipping_price =
 15.00; }
       elsif ($subtotal >= 70.00 && $subtotal <= 79.99)   { $shipping_price =
 19.00; }
       elsif ($subtotal >= 80.00 && $subtotal <= 89.99)   { $shipping_price =
 23.00; }
       elsif ($subtotal >= 90.00 && $subtotal <= 99.99)   { $shipping_price =
 27.00; }
       elsif ($subtotal >= 100.00 && $subtotal <= 119.99)  { 
 $shipping_price = 31.00; }
       elsif ($subtotal >= 120.00 && $subtotal <= 129.99)  { 
 $shipping_price = 35.00; }
 elsif ($subtotal >= 130.00 && $subtotal <= 139.99)  { 
 $shipping_price = 39.00; }
 elsif ($subtotal >= 140.00 && $subtotal <= 149.99)  { 
 $shipping_price = 43.00; }
 elsif ($subtotal >= 150.00 && $subtotal <= 159.99)  { 
 $shipping_price = 47.00; }
 elsif ($subtotal >= 160.00 && $subtotal <= 169.99)  { 
 $shipping_price = 52.00; }
     
       # All orders over the previous value
       else { $shipping_price = 0.00; }
  
}
    return ($shipping_price);
}}
}

}
 1;

Open in new window

0
Comment
Question by:starview
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
wesly_chen earned 500 total points
ID: 36577669
if ($category_count{'Home_Accessories!'} eq "1") {

     $subtotal *= 0.25;   # add this line
     if ($subtotal <= 100.00)      { $shipping_price = 0.00;  }

       elsif ($subtotal >= 101.00 && $subtotal <= 250.00)   { $shipping_price
 = 0.00;  }
       elsif ($subtotal >= 250.00 && $subtotal <= 1500.00)   { $shipping_price
 = 0.00; }
       
       # All orders over the previous value
       else { $shipping_price = 0.00; }
   

 } else {
0
 
LVL 38

Assisted Solution

by:wesly_chen
wesly_chen earned 500 total points
ID: 36577774
> it will calculate the shipping charges by using a 25% of the subtotal.
So the $shipping_price = 25% of $subtotal ?

Then change to $shipping_price = $subtotal * 0.25;  in line 6 ~16
if ($category_count{'Home_Accessories!'} eq "1") {

     if ($subtotal <= 100.00)      { $shipping_price = 0.00;  }

       elsif ($subtotal >= 101.00 && $subtotal <= 250.00)   { $shipping_price = $subtotal * 0.25;  }
       elsif ($subtotal >= 250.00 && $subtotal <= 1500.00)   { $shipping_price = $subtotal * 0.25; }
       
       # All orders over the previous value
       else { $shipping_price = $subtotal * 0.25; }

Open in new window

0
 

Author Comment

by:starview
ID: 36577883
Is there a way to calculalte the 25% shipping charge of the subtotal  no matter what the subtotal is ?
and no use the:
if ($subtotal <= 100.00)      { $shipping_price = 0.00;  }
       elsif ($subtotal >= 101.00 && $subtotal <= 250.00)   { $shipping_price = $subtotal * 0.25;  }
       elsif ($subtotal >= 250.00 && $subtotal <= 1500.00)   { $shipping_price = $subtotal * 0.25; }
       
0
 
LVL 38

Assisted Solution

by:wesly_chen
wesly_chen earned 500 total points
ID: 36577969
> no matter what the subtotal is ?
Replace line 6 to line 19 to

if ($category_count{'Home_Accessories!'} eq "1") {

     $shipping_price = $subtotal * 0.25;

 } else {

Open in new window

0
 

Author Closing Comment

by:starview
ID: 36584863
Thank you
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
OS Selection Menu 1 81
Error when Running powershell script 6 43
powershell automatic variable for results 21 38
Script to move computer from one domain to another 6 50
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question