Jump to content

can someone help please - need the sum of all quantities


kikonyc

Recommended Posts

can someone help please...

this php is to calculate shipping charges for paypal..

RULES:  ($7.00 FOR THE FIRST TWO ITEMS - $1.00 FOR EACH ADDITIONAL ITEM)

as is, the formula calculates the number of items - not total of quantity - adds $1 for each additional after 2.

any suggestions would be appreciated..

 

link to form:  http://crsecrets.com/test01/order.html

 

FORM LIST ITEMS FORMAT - HTML

<TD>Herbal Hair Rejuvenator, Unscented <FONT SIZE="-2">(4oz. jar)</FONT><input type="hidden" name="item_name_1" value="Herbal Hair Rejuvenator, Unscented (4oz. jar)" />                </TD>

                <TD align="center" id="table"><input name="quantity_1" type="text" value="" size="6" maxlength="2" /></TD>

                <TD align="center">$13.50<input type="hidden" name="amount_1" value="13.50" /></TD>

 

 

<?php

  $products = array();

  $url = "?business=*********$handling_cart=7.00";

 

  foreach ($_POST as $k=>$v) {

      preg_match("/\_(\d{1,3})$/",$k,$match);

      $key = $match[1];

      $products[$key][$k] = $v;

  }

 

  $i=1;

  foreach ($products as $k=>$v) {

      if ($v['quantity_'.$k] > 0) {

        foreach ($v as $k1=>$v1) {

            $key = explode("_",$k1);

            switch($key[0]) {

              case 'item':

                  $var = "item_name_" . $i;

                  break;

              case 'quantity':

                  $var = "quantity_" . $i;

                  break;

              case 'amount':

                  $var = "amount_" . $i;

                  break;

            }

           

            //get shipping for additional items above 3

            if ($i <= 2) {

              $shipping = "0.00";

            } else {

              $shipping = "1.00";

            }

            $shipping = ($shipping * $v['quantity_' . $k]);

           

            $url .= "&" . $var . "=" . urlencode($v1);

        }

        $url .= "&shipping_" . $i . "=" . $shipping;

        $i++;

      }

  }

  #echo $url;

  header("Location: https://www.paypal.com/cgi-bin/webscr" . $url);

  exit;

?>

Link to comment
Share on other sites

Since your code isn't really readable in its current state,

if (quantity     shipping = quantity * 7.00
} else {
    shipping = 2 * 7.00 + (quantity - 2) * 1.00
}

 

[edit] But now it is.

 

//get shipping for additional items above 3
if ($i    $shipping = "0.00";
} else {
    $shipping = "1.00";
}

Fix that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.