0

我有一些代码有问题。我正在为我的网站制作一个捐赠页面,但我不确定如何将其中的一部分显示为它的“item_name”部分。对于可能的捐赠,我有几个选项,我想在他们被重定向付款时显示他们选择的选项显示在 item_name 中。这就是我所拥有的:

        $price = '6.50';
    if($_GET['prod'] == 1) //Price for package 1 (Regular Donator)
        $price = '6.50';
    if($_GET['prod'] == 2) //Price for package 2 (Extreme Donator)
        $price = '12.50';
    if($_GET['prod'] == 3) //Price for package 3 (10 SoF Spins)
        $price = '2.50';
    if($_GET['prod'] == 4) //Price for package 4 (20 SoF Spins)
        $price = '4.00';
    if($_GET['prod'] == 5) //Price for package 5 (Fight Kiln Completion)
        $price = '5.50';
    if($_GET['prod'] == 6) //Price for package 6 (1 Ragged Gold Key)
        $price = '2.00';
    if($_GET['prod'] == 7) //Price for package 7 (4 Ragged Gold Keys)
        $price = '9.99';
    if($_GET['prod'] == 8) //Price for package 8 (12 Ragged Gold Keys)
        $price = '20.00';
    if($_GET['prod'] == 9) //Price for package 9 (28 Ragged Gold Keys)
        $price = '40.00';

  $p->add_field('custom', $_GET['username']);
  $p->add_field('business', 'dtordik@gmail.com'); //edit to your email
  $p->add_field('return', $this_script.'?action=success');
  $p->add_field('cancel_return', $this_script.'?action=cancel');
  $p->add_field('notify_url', $this_script.'?action=ipn');
  $p->add_field('item_name', 'Package '.$_GET['prod']);
  $p->add_field('item_number', $_GET['prod']);
  $p->add_field('currency_code', 'USD');
  $p->add_field('amount', $price);
  //$p->add_field('quantity', $_GET['amm']);
  $p->add_field('lc', 'GB');
  $p->submit_paypal_post(); // submit the fields to paypal
  //$p->dump_fields();      // for debugging, output a table of all the fields
  break;

你看到$p->add_field('item_name', 'Package '.$_GET['prod']); 它获取了号码,然后在贝宝网站上显示为“套餐 1”。我怎样才能做到这一点,如果有人选择'prod' 1,它可以作为“常规捐赠者”,“prod”2 作为“极端捐赠者”等等。我不知道我是不是想太多了,但任何帮助将不胜感激,谢谢!

4

1 回答 1

0

这段代码效率有点低,如果你优化解决方案将是直截了当的。

定义所有产品、价格和标签的列表。

$products = array(
    1 => array(
        "price" => "6.00",
        "label" => "Regular Donator"
    ),
    2 => array(
        "price" => "60.00",
        "label" => "Extreme Donator"
    ),
    3 => array(
        "price" => "0.00",
        "label" => "Cheap bastard"
    )
);

$product = $_GET["prod"];
$price = $products[$product]["price"];
$label = $products[$product]["label"];

$p->add_field('item_name', $label);
$p->add_field('item_number', $product);
$p->add_field('amount', $price);
// etc
于 2013-07-25T15:51:13.540 回答