9.4. 用户界面 - 使用优惠券下单
使用优惠券下单
接下来我们要实现功能是使用优惠券来下单,这是优惠券模块中最核心的部分。
1. 修改购物车前端模板
首先我们需要在购物车页面把优惠码与订单的其他信息一起提交上来:
resources/views/cart/index.blade.php
.
.
.
@section('scriptsAfterJs')
<script>
$(document).ready(function () {
.
.
.
$('.btn-create-order').click(function () {
var req = {
address_id: $('#order-form').find('select[name=address]').val(),
items: [],
remark: $('#order-form').find('textarea[name=remark]').val(),
coupon_code: $('input[name=coupon_code]').val(), // 从优惠码输入框中获取优惠码
};
.
.
.
});
.
.
.
})
</script>
@endsection
2. 校验优惠码
虽然我们在提交订单之前就已经检查过一次优惠码,但是提交时需要再次检查,因为有可能在用户检查优惠码和提交的时间空档中优惠券被其...