Custom payments for wholesale

ricco
New Community Member

Hi,

I am trying to setup a wholesale page where price per item changes with the purchased quantity. I am also trying to setup shipping option on the same page 9therefore overriding Paypal's). I ma trying to combine two javascript functions and I am doing errors. I would greatly appreciate any help.

 

This is where I am stuck.

 

Code below

*******************************************

<?php # - index.php
$page_title = 'IBB';
include ('./protect.txt');
include ('./header.txt');
?>

<!-- Start of Script -->
<SCRIPT type=text/javascript>
<!--
var ac = 0;    // table for qty/amt pairs
var aqty = new Array ();  // qty brkpt
var aamt = new Array ();  // amount to charge

var pc = 0;    // table for qty/percent pairs
var pqty = new Array ();  // qty brkpt
var pper = new Array ();  // percent to discount

function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) { // quantity based discounts
var i,amt,des,qty;
  amt = obj1.baseamt.value*1.0; // base amount
  des = obj1.basedes.value;     // base description
  qty = obj1.qty.value;         // get user quantity
  if (isNaN (qty) || qty < 1) { // make sure it's good
    alert ('"' + qty + '"' + ' is not a valid number!');
    ac = 0;                     // always zap the table
    pc = 0;
    return false;               // th-th-that's all, folks.
  }
  qty = qty*1.0;                // force to numeric

  for (i=ac-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= aqty[i]) {       // use this entry
      amt = aamt[i];            // this is the real amount
      break;                    // get out, we're done
    }
  }
  for (i=pc-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= pqty[i]) {       // use this entry
      amt = amt - (amt/100.0 * pper[i]);
      break;                    // get out, we're done
    }
  }

  obj1.item_name.value = des + ", " + qty + " books @ US $" +
                         Dollar (amt) + " each.";
  obj1.amount.value = Dollar (amt * qty);
  ac = 0;  // reset item discount
  pc = 0;
}

function SetAmt (q1, a1) {  // set up a quantity-based amount table
var i;
  ac = 0;
  for (i=0; i<arguments.length; i=i+2) {  // build the table
    aqty[ac] = arguments[i];   // get real args and store
    aamt[ac] = arguments[i+1];
    ac = ac + 1;               // number of pairs in table
  }
}
//-->
</SCRIPT>
<!-- End of Script -->

<!-- Start of First Script CalculateOrder1 -->
<SCRIPT language=javascript>
<!--
function CalculateOrder1(form)
{
 if (document.myform.os2.value == "US"){
 document.myform.shipping.value = "10.00";
 document.myform.shipping2.value = "3.00";
 }
 if (document.myform.os2.value == "Canada"){
 document.myform.shipping.value = "15.00";
 document.myform.shipping2.value = "4.00";
 }
 if (document.myform.os2.value == "Mexico"){
 document.myform.shipping.value = "16.00";
 document.myform.shipping2.value = "5.00";
 }
 if (document.myform.os2.value == "Europe"){
 document.myform.shipping.value = "20.00";
 document.myform.shipping2.value = "6.00";
 }
}
//--> 
</SCRIPT>
<!-- End of First Script CalculateOrder1 -->

<div id="mainbody">

<div id="maintext" class="bodytext">

<h2>Instructions for Wholesalers</h2>

<p>Dear Wholesaler, wholesale prices are as follows:
<li> 40% discount when you buy more than 10 books</li>
<li> 45% discount when you buy more than 50 books</li><br>
Please <b>Enter Desired Quality</b> in the field below and discount will be reflected.<br>
<b>Enter Desired Quantity:</b>&nbsp;&nbsp;<INPUT size="2" value="1" name="qty">

<br><br>

<form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="paypal" name="myform">

Select Shipping Destination:&nbsp;&nbsp;
<input type="hidden" name="on0" value="Shipping Destination">
<select name="os0">
<option value="US" selected>US | $10 First Item | $3.00 Each Additional</option>
<option value="Canada">Canada | $15 First Item | $4.00 Each Additional</option>
<option value="Mexico">Mexico | $16 First Item | $5.00 Each Additional</option>
<option value="Europe">Europe | $20 First Item | $6.00 Each Additional</option>
</select>
</p>

<h2>ABC Italiano - article w-0001.</h2>

<div id="w_cartgif">  <!-- This is the Add To Cart button for item w001 for Wholesalers  -->

<!-- Start of Form -->
<!-- Note: target="paypal" was replaced with the variable target="_self" -->
<!-- Note: shopping_url also added to code -->
<!-- These two changes allow better functionality with IE and Firefox -->


<input onclick=CalculateOrder1(document.myform)>
<input onsubmit="this.target = '_self'; SetAmt (1, 9.95, 11, 6.00, 51, 5.50); return ReadForm (this); "action="https://www.paypal.com/cgi-bin/webscr" method="post">
<INPUT type="hidden" name="cmd" value="_cart">
<INPUT type="hidden" name="add" value="1">
<INPUT type="hidden" name="business" value="tttatemaildotcom">
<INPUT type="hidden" name="item_name">
<INPUT type="hidden" name="item_number" value="W-0001">
<INPUT type="hidden" name="amount">
<INPUT type="hidden" name="shopping_url" value="www.">
<INPUT type="hidden" name="return" value="www.">
<input type="hidden" name="cancel_return" value="www.">
<INPUT type="hidden" name="no_shipping" value="2">
<input type="hidden" name="shipping">
<input type="hidden" name="shipping2">
<INPUT type="hidden" name="currency_code" value="USD">
<INPUT type="hidden" name="lc" value="US">
<INPUT type="hidden" name="baseamt" value=5.00>
<INPUT type="hidden" name="basedes" value="ABC Italiano">
<input type="hidden" name="bn" value="PP-ShopCartBF:x-click-but22.gif:NonHosted">

<br><br>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</FORM>
<!-- End of Form -->

<br><br>
For special requests, please <a href="contact_us.php">Contact Us</a>.

</div> <!-- cartgif -->

</div> <!-- maintext -->

<div id="framegallery">
<div id="gallery">
    <div id="framethumbnails">
    <ul id="thumbnails">
        <li><a href="#pic1"><img src="images/front_cover_thumbnail.jpg" alt="pic1" /></a></li>
        <li><a href="#pic2"><img src="images/l_thumbnail.jpg" alt="pic2" /></a></li>
        <li><a href="#pic3"><img src="images/e_thumbnail.jpg" alt="pic3" /></a></li>
        <li><a href="#pic4"><img src="images/z_thumbnail.jpg" alt="pic4" /></a></li>
        <li><a href="#pic5"><img src="images/r_thumbnail.jpg" alt="pic5" /></a></li>
    </ul></div>
    <div id="fullsize">
        <div id="pic1"><img src="images/front_cover_sample.jpg" alt="pic1" /></div>
        <div id="pic2"><img src="images/l_sample.jpg" alt="pic2" /></div>
        <div id="pic3"><img src="images/e_sample.jpg" alt="pic3" /></div>
        <div id="pic4"><img src="images/z_sample.jpg" alt="pic4" /></div>
        <div id="pic5"><img src="images/r_sample.jpg" alt="pic5" /></div>
    </div>

</div> <!-- gallery -->
</div> <!-- framegallery -->


<div id="addtocart">
<table class="bodytext" cellpadding="0" cellspacing="0">
<tr>
<td><b>Price: </b></td><td>&nbsp;&nbsp;&nbsp;$9.95</td>
</tr>
<tr>
<td><b>Size: </b></td><td>&nbsp;&nbsp;&nbsp;6" high x 5" wide x 0.5" thick</td>
</tr>
<tr>
<td><b>Pages: </b></td><td>&nbsp;&nbsp;&nbsp;24</td>
</tr>
</table>



</div> <!-- addtocart -->

<?php
include ('./footer.txt');
?>

</div> <!-- mainbody -->

</div> <!-- Closes Container from header.txt -->
</body>
</html>

Login to Me Too
1 REPLY 1

skier
Advisor
Advisor

You can get some shipping/delivery coding ideas here and see ways to buy more pay less here and here.    Here is a Buy More Pay Less example.

 

Regards,

 

skier

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.