从购物车禁用结帐按钮-PHP [英] Disabling checkout button from shopping cart - php

查看:62
本文介绍了从购物车禁用结帐按钮-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个网站上设置一个查看购物车/购物篮页面,已登录的用户在其中获得积分/积分。一旦他们获得一定数量的这些积分,他们就可以去购物车并仅用这些积分付款。 (没有钱易手,因此不涉及贝宝/结帐/运费/税金等)

I am trying to setup a "view shopping cart/basket" page within a site in which logged in users earn points/credits. Once they earn a certain amount of these points they can then go to a shopping cart and pay with these points only. (No money changes hands, so no paypal/checkout/shipping/taxes etc are involved)

到目前为止,我已经登录了,积分表总计,添加

So far I have got the login, points total table, add product to cart and change of quantity feature to work.

我要在此 view_cart.php页面(下面的代码)上要做的是如果用户的积分总数小于购物车总价,则使结帐链接(submit_cart.php)消失或被禁用。无论如何,我可以在此脚本上执行此操作吗?
如果是这种情况,您没有足够的积分继续进行结帐提示会起作用,但是如果我可以将此结帐链接消失,那就太好了。

What I am trying to do on this ‘view_cart.php’ page (code below) is to make the ‘Checkout’ link (submit_cart.php) disappear or be disabled if the user's points total is less than the total shopping cart price. Is there anyway I can do this on this script? The ‘You don’t have enough points to proceed to checkout’ prompt works if this is the case but if I can this checkout link to disappear that would be great.

由于我是一名前端设计师,所以我对PHP的知识有限,但是请随时提供任何建议或方法的更改。
谢谢!

My php knowledge is limited as I’m more of a front end designer but please feel free to offer any suggestions or changes of approach. Thanks!

<?php
$page_title = 'Your Rewards Shopping Cart';
include ('./includes/header.html');

if (!isset($_SESSION['users_id'])) {

   $url = 'http://' . $_SERVER['HTTP_HOST']
    . dirname($_SERVER['PHP_SELF']);
   if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
        $url = substr ($url, 0, -1); 
   }
   $url .= '/login.php'; 

ob_end_clean(); // Delete the buffer.
header("Location: $url"); 
exit(); // Quit the script.
}

$rwp = $_SESSION['reward_user_points']; 

$problem = FALSE; 

if (isset($_POST['submitted']))
   { 

foreach ($_POST['qty'] as $k => $v) {

$pid = (int) $k;
$qty = (int) $v;

if ( $qty == 0 ) { 
unset ($_SESSION['cart'][$pid]);
} elseif ( $qty > 0 ) { 
$_SESSION['cart'][$pid] ['quantity'] = $qty;
}

} // End of FOREACH.
} // End of SUBMITTED IF.

$empty = TRUE;
if (isset ($_SESSION['cart'])) {
foreach ($_SESSION['cart'] as $key =>$value) {
if (isset($value)) {
$empty = FALSE;
break; // Leave the loop.
}

} // End of FOREACH.
} // End of ISSET IF.

if (!$empty) {

require_once ('/MySQL/database.php');

$query = "SELECT users_id, reward_user_points FROM reward_points
            WHERE reward_points.users_id = users.users_id";
$result = mysql_query($query);  

$query = "SELECT products_id, products_name FROM categories, products
   WHERE categories.categories_id = products.categories_id AND products.products_id 
   IN (";foreach ($_SESSION['cart'] as $pid =>$value) {
$query .= $pid . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY categories.categories_name ASC';
$result = mysql_query($query);
?>

 <h1>Your Shopping Cart</h1>

    <div id="sidebar">
    <div id="statusbar">
    <p><span class="statusbar_highlight">Name:</span><br />
    <?php echo " {$_SESSION['users_first_name']} " . " {$_SESSION['users_surname']}<br> ";?></p>
    <p><span class="statusbar_highlight">Outlet:</span><br />
    <?php echo " {$_SESSION['users_outlet']} ";?></p>
    <p><span class="statusbar_highlight">Sales Number:</span><br />
    <?php echo " {$_SESSION['users_sales_no']} ";?></p>     
    <p><span class="statusbar_highlight">My Points:</span><br />
    <font size="+1"><?php echo " {$_SESSION['reward_user_points']} ";?></font></p> 
    </div>
    <br /><br /><br /><br /><br /><br /><br /><br />
    </div>

  <div id="maincontent_inner">
  <div id="maincontent_inner2"> 

<?php
echo '<table border="0" width="100%" cellspacing="1" cellpadding="5" align="center">
<tr class="top">
<td align="left" width="46%"><b>Reward Product</b></td>
<td align="right" width="18%"><b>Price</b></td>
<td align="center" width="16%"><b>Qty</b></td>
<td align="right" width="20%"><b>Sub Total</b></td>
</tr>
<form action="view_cart.php" method="post">';

$total = 0; // Total cost of the order.

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

// Total and subtotals.
$subtotal = $_SESSION['cart'][$row
   ['products_id']]['quantity'] *
   $_SESSION['cart'][$row ['products_id']]['price'];
$total += $subtotal;

if ($rwp >= $total) {
    }   
    else {
    echo "You do not have enought points to proceed to checkout <br />";
    }

// Print the row.
echo " <tr>
<td align=\"left\">{$row['products_name']}</td>
<td align=\"right\">{$_SESSION['cart'][$row['products_id']] ['price']} pts</td>
<td align=\"center\"><input type=\"text\" size=\"3\"
   name=\"qty[{$row['products_id']}]\"
   value=\"{$_SESSION['cart'][$row['products_id']]['quantity']}\" /></td>
<td align=\"right\">" . number_format ($subtotal) . " pts</td>
</tr>\n";
} // End of the WHILE loop.

mysql_close($dbc); // Close the database connection.

// products the footer, close the table, and the form.
echo ' <tr class="even">
<td colspan="3" align="right"><b> TOTAL:<b></td>
<td align="right"><b>' . number_format ($total) . ' pts </b></td>
</tr>
</table>
<br />
<div align="center"><input type="submit" name="submit"
   value="Update" />
<input type="hidden" name="submitted"value="TRUE" />
</form><br /><br /></div>
<p><a href="browse_rewards.php"><img src="images/but_continue.png" /></a></p>
<p><a href="submit_cart.php"><img src="images/but_checkout.png" /></a></p>';

} else {
echo '<h1>Shopping Cart</h1><p>Your cart is currently empty.</p>
<p><a href="browse_rewards.php"><img src="images/but_continue.png" /></a></p>
<div id="maincontent_inner">
<div id="maincontent_inner2"> ';
}

?>
<br />
<p>
<span class="extras"><strong>Please Note the following:</strong><br />
1. To delete any item off your cart, simply type in '0' and click 'Update'<br />
2. To add in more than one item, simply click the desired amount and click 'Update'<br />
3. Your cart will be emptied upon logging out of your session<br />
</span></p>

</div>
</div>
</div>
</div>


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


推荐答案

在我看来,你真该死!

It looks to me like you're darn close:

if ($rwp >= $total) {    
  echo '<button>Checkout</button>';  //Just put the code you want here
}   
else {
  echo "You do not have enought points to proceed to checkout <br />";
}

在您的示例中,这些行在 会引起问题。只需将它们移到要显示此内容的位置,便可以使用。

In your sample, these lines are in the while which will cause a problem. Just move them out to where you want this to display and you're on your way.

这篇关于从购物车禁用结帐按钮-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆