SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding a number to a calculation

    I'm trying to modify my shopping cart system to automatically add eight ounces to the weight of every order for a mailer when it calculates shipping. The people on the cart's forums aren't being any help so I was hoping that someone here could help me. I've found the part of the code that calculates the total weight of the cart:

    PHP Code:
            // work out weight
             
    if($product[0]['prodWeight']>&& $product[0]['digital']==0){
             
             
    $totalWeight = ($product[0]['prodWeight'] * $quantity) + $totalWeight;
             
             } 
    Can someone tell me how I would modify that code in order to add eight ounces to every order? The calculation is being done in ounces so there's no unit conversion or anything fancy like that, and the total number of ounces is converted to pounds and ounces by a function later on. I just need to add 8 to the final variable $totalweight. Can anyone help?
    Daniel

    http://www.dfbpunk.com

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Unless I'm missing something obvious ...

    PHP Code:
    $totalWeight = ($product[0]['prodWeight'] * $quantity) + $totalWeight 8
    ??
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    works perfectly! Thanks for doing in about two minutes what the cubecart forums couldn't do in two days.
    Daniel

    http://www.dfbpunk.com

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Note: if the above is part of a repeated cyle (like a loop or an Add To Cart feature) then the 8 oz may get added for every item. If you only want to add 8 oz to the final weight then you might need to do this at the Checkout process.

    (If the code you showed is from the checkout process then you can ignore the above).
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •