added coupon box on checkout screen
This commit is contained in:
parent
62a7954c33
commit
5ca9e67cad
|
|
@ -817,7 +817,7 @@ return [
|
|||
'specific-coupon' => 'Specific Coupon(Check) / Auto Generated(Unheck)',
|
||||
'free-shipping' => 'Free Shipping',
|
||||
'is-guest' => 'For Guests',
|
||||
'disc_qty' => 'Max. Quantity Allowed To Be Discounted'
|
||||
'disc_qty' => 'Max. Quantity Allowed To Be Discounted',
|
||||
],
|
||||
|
||||
'status' => [
|
||||
|
|
@ -828,7 +828,11 @@ return [
|
|||
'update-coupon-success' => 'Success! rule updated along with coupon',
|
||||
'update-failed' => 'Error! cannot update',
|
||||
'delete-success' => 'Sucess! rule deleted',
|
||||
'delete-failed' => 'Error! cannot delete'
|
||||
'delete-failed' => 'Error! cannot delete',
|
||||
'coupon-applied' => 'Coupon Applied',
|
||||
'no-coupon' => '* Coupon not applicable',
|
||||
'coupon-expired' => 'Coupon expired',
|
||||
'coupon-failed' => 'Invalid coupon'
|
||||
],
|
||||
|
||||
'catalog' => [
|
||||
|
|
|
|||
|
|
@ -405,7 +405,7 @@
|
|||
coupon_type: null,
|
||||
free_shipping: null,
|
||||
|
||||
all_conditions: null,
|
||||
all_conditions: [],
|
||||
|
||||
code: null,
|
||||
suffix: null,
|
||||
|
|
|
|||
|
|
@ -377,7 +377,6 @@
|
|||
return {
|
||||
name: 'Name of rule',
|
||||
description: 'Enter Some Description',
|
||||
conditions_list: [],
|
||||
channels: [],
|
||||
customer_groups: [],
|
||||
ends_till: null,
|
||||
|
|
@ -439,7 +438,6 @@
|
|||
|
||||
mounted () {
|
||||
data = @json($cart_rule[3]);
|
||||
console.log(data);
|
||||
this.name = data.name;
|
||||
this.description = data.description;
|
||||
this.conditions_list = [];
|
||||
|
|
@ -491,6 +489,7 @@
|
|||
this.free_shipping = data.free_shipping;
|
||||
|
||||
this.all_conditions = null;
|
||||
this.conditions_list = JSON.parse(JSON.parse(data.conditions));
|
||||
|
||||
this.dedicated_label = false;
|
||||
global_label = null;
|
||||
|
|
@ -569,7 +568,6 @@
|
|||
},
|
||||
|
||||
onSubmit: function (e) {
|
||||
console.log(this.$validator);
|
||||
this.$validator.validateAll().then(result => {
|
||||
if (result) {
|
||||
e.target.submit();
|
||||
|
|
|
|||
|
|
@ -1240,4 +1240,21 @@ class Cart {
|
|||
public function setCouponAble() {
|
||||
return $this->discount->checkCouponConditions($this->getCart());
|
||||
}
|
||||
|
||||
public function setCoupon()
|
||||
{
|
||||
return $this->setCouponAble();
|
||||
}
|
||||
|
||||
public function leastWorthItem()
|
||||
{
|
||||
$cart = $this->getCart();
|
||||
$leastSubTotal = 0;
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->sub_total > $leastSubTotal) {
|
||||
$leastSubTotal = $item->sub_total;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -254,6 +254,7 @@ class CartController extends Controller
|
|||
*/
|
||||
public function applyCoupons()
|
||||
{
|
||||
// dd(request()->all());
|
||||
$this->validate(request(), [
|
||||
'code' => 'string|required'
|
||||
]);
|
||||
|
|
@ -262,24 +263,29 @@ class CartController extends Controller
|
|||
|
||||
$rules = Cart::setCoupon();
|
||||
|
||||
$impacts = array();
|
||||
$appliedRule;
|
||||
|
||||
$appliedRule = null;
|
||||
$coupons = [];
|
||||
foreach($rules['id'] as $rule) {
|
||||
array_push($coupons, $rule->coupons->code);
|
||||
if ($rule->use_coupon && $rule->auto_generation == 0) {
|
||||
if ($rule->coupons->code == $code) {
|
||||
$appliedRule = $rule;
|
||||
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
dd('auto_generation in next version');
|
||||
}
|
||||
}
|
||||
|
||||
if(! isset($appliedRule)) {
|
||||
return response()->json(['message' => trans('admin::app.promotion.status.no-coupon'), 'coupons' => $coupons], 200);
|
||||
}
|
||||
|
||||
$cart = Cart::getCart();
|
||||
// check all the conditions associated with the rule
|
||||
if ($appliedRule->starts_from == null) {
|
||||
if (isset($appliedRule->starts_from) && $appliedRule->starts_from == null) {
|
||||
|
||||
$action_type = $appliedRule->action_type;
|
||||
$disc_threshold = $appliedRule->disc_threshold;
|
||||
$disc_amount = $appliedRule->disc_amount;
|
||||
|
|
@ -329,10 +335,25 @@ class CartController extends Controller
|
|||
}
|
||||
|
||||
if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
dd($newQuantity);
|
||||
return response()->json([
|
||||
'message' => 'Success',
|
||||
'amount_given' => false,
|
||||
'amount' => $newQuantity
|
||||
]);
|
||||
} else {
|
||||
dd($newBaseSubTotal);
|
||||
return response()->json([
|
||||
'message' => 'Success',
|
||||
'amount_given' => true,
|
||||
'amount' => $newBaseSubTotal
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'failed',
|
||||
'amount_given' => null,
|
||||
'amount' => null,
|
||||
'least_value_item' => Cart::leastWorthItem()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -469,7 +469,8 @@
|
|||
data: function() {
|
||||
return {
|
||||
templateRender: null,
|
||||
code: null
|
||||
code: null,
|
||||
message: null
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -493,15 +494,21 @@
|
|||
|
||||
methods: {
|
||||
onSubmit: function() {
|
||||
console.log(this.code);
|
||||
var this_this = this;
|
||||
|
||||
axios.post('{{ route('shop.checkout.check.coupons') }}', {
|
||||
code: this.code
|
||||
code: this_this.code
|
||||
}).then(function(response) {
|
||||
console.log(response);
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
console.log(response.data.message);
|
||||
this_this.message = response.data.message;
|
||||
});
|
||||
},
|
||||
|
||||
codeChange: function() {
|
||||
if (this.code.length == 0 || this.code.length == 1)
|
||||
{
|
||||
this.message = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -35,11 +35,15 @@
|
|||
|
||||
<form class="coupon-form" method="post" @submit.prevent="onSubmit">
|
||||
<div class="control-group mt-20">
|
||||
<input type="text" class="control" value="" name="code" placeholder="Enter Coupon Code" v-model="code">
|
||||
<input v-model="code" type="text" class="control" value="" name="code" placeholder="Enter Coupon Code" v-on:change="codeChange">
|
||||
|
||||
<span class="coupon-message mt-5" style="display: block; color: #ff5656; margin-bottom: 5px;" v-if="message != 'success'">@{{ message }}</span>
|
||||
|
||||
<span class="coupon-message mt-5" style="display: block; margin-bottom: 5px;" v-if="message == 'success'">@{{ message }}</span>
|
||||
|
||||
<button class="btn btn-lg btn-primary">Apply Coupon</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue