我已将minicart js实施到我的网站中,我可以将项目添加到购物车中,并且它可以正常工作。我想做的是,当用户以特定价格(例如11.99)添加2件商品时,它会将其折扣降至20件。
我知道minicart js有折扣功能,但文档不太清楚。我想知道实现这个目标的最佳方法吗?
这是我正在使用的代码:
<?php
// Connect to the MySQL database
include "store_scripts/connect_to_mysql.php";
$dynamicList = '';
$sql = mysqli_query($dbc, "SELECT * FROM products where category = 'Rings'");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while($row = mysqli_fetch_array($sql))
{
$id = $row['id'];
$product_name = $row['product_name'];
$price = $row['price'];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '
<div id="floatedImage">
<a href="product.php?id=' . $id . '"><img src="images/' . $product_name . '.jpg" alt="' . $product_name . '" /></a>
<p>' . $product_name . '</p>
<p>€' . $price . '</p>
<p><a href="product.php?id=' . $id . '">View Product Details</a><p>
<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="business" value="test@test.com"/>
<input type="hidden" name="item_name" value="' . $product_name . '"/>
<input type="hidden" name="amount" value="' . $price . '"/>
<input type="hidden" name="currency_code" value="EUR"/>
<input type="hidden" name="add" value="1"/>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!"/>
<img alt="" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
</form>
</div>';
}
}
else
{
$dynamicList = "We have no products listed in our store yet";
}
mysqli_close($dbc);
?>
<!DOCTYPE html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="css/styles.css" rel="stylesheet" type="text/css" media="screen"/>
<title>Rings</title>
</head>
<body>
<div id="wrapper">
<div id="top">
<?php include('templates/top_template.php'); ?>
</div>
<div id="topnav">
<?php include('templates/topnav_template.php'); ?>
</div>
<div id="banner">
</div>
<div id="content">
<p><?php echo $dynamicList ?></p>
</div>
<div id="rightSide">
<?php include('templates/rightSide_template.php'); ?>
</div>
<div id="footer">
<?php include('templates/footer_template.php'); ?>
</div>
<div id="copyrightFooter">
<?php include('templates/copyrightFooter_template.php'); ?>
</div>
<script src="minicart.js"></script>
<script>
paypal.minicart.render();
</script>
</div>
</body>
</html>