doulezhi5326 2011-05-15 21:59
浏览 64

根据表单中的行数将商品添加到购物车

I am looking for a way to link the number of rows in a form to items in a simple shopping cart/checkout script.

Here is the scenario. Users are booking places at a conference. There is a three tier pricing structure, and a section of the form for each price. When the user first navigates to the booking page he is asked to add the number of people he/she wishes to book into the conference at each pricing structure. Extra rows can be added to each section of the form using javascript. Once the names/details of each person being booked in has been completed the user clicks on a 'Submit' button which submits all of the information to a MySQL Database and redirects the user to a payment page.

I would like this payment page to consist of a simple shopping cart/checkout which is automatically filled with the number of people at each rate, with the total for each rate, and a grand total. The user could then just click on a button to complete the PayPal payment.

So the parts I am stuck on is how to automatically pass the information from the forms (i.e. the number of rows (people) at each rate) to the 'checkout' page, and which script I might use to generate the checkout page.

I'd be grateful for any help to get this working,

Thanks,

Nick

  • 写回答

3条回答 默认 最新

  • duanchique1196 2011-05-20 06:38
    关注

    It sounds like you have the adding of users handled, so let me touch on submitting the shopping cart. I did something similar, but created a PHP function to handle the addition of each item, which essentially echoed each product (desc, price, etc) inside a form, then simply submitted this form at the proper time to PayPal.

    function FormatPaypal($iItemno, $sItemname, $iQty, $fPrice, $fDiscountAmount, $sCode)
    {
        global $iUser;
    $s1 = sprintf('<input type="hidden" name="item_name_%d" value="%s">', $iItemno, $sItemname); 
    $s2 = sprintf('<input type="hidden" name="amount_%d" value="%.2f"> ', 
    $iItemno, $fPrice); 
    $s3 = sprintf('<input type="hidden" name="quantity_%d" value="%d"> ', 
    $iItemno, $iQty); 
    
    $s4 = sprintf('<input type="hidden" name="discount_amount_%d" value="%.2f">', $iItemno, $fDiscountAmount); 
    
    $sCode = sprintf("%s-%d", $sCode, $iUser );
    $s5 = sprintf('<input type="hidden" name="item_number_%d" value="%s">', $iItemno, $sCode); 
    
    $sReturn = $s1.$s2.$s3.($fDiscountAmount ?  $s4 : '').$s5;
    echo $s5;
    
    return $sReturn;
    }
    

    which was placed inside a standard PayPal form:

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="frmPaypal"> <input type="hidden" name="cmd" value="_cart">
    

    Using this method I only have to increment the $iItemNo with each use. I am currently building a PHP class to simplify this even further by managing the items and total item count, if interested I'll try to remember to come back and share it here.

    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算