removed the conditions empty bug

This commit is contained in:
Prashant Singh 2019-05-28 14:20:16 +05:30
parent 5ca9e67cad
commit 088bccf7ab
9 changed files with 111 additions and 89 deletions

View File

@ -259,14 +259,6 @@
<span class="control-error" v-if="errors.has('disc_amount')">@{{ errors.first('disc_amount') }}</span>
</div>
<div class="control-group" :class="[errors.has('disc_amount') ? 'has-error' : '']">
<label for="disc_amount" class="required">{{ __('admin::app.promotion.general-info.disc_qty') }}</label>
<input type="number" step="1" class="control" name="disc_quantity" v-model="disc_quantity" v-validate="'required|decimal'" value="{{ old('disc_quantity') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.disc_qty') }}&quot;">
<span class="control-error" v-if="errors.has('disc_quantity')">@{{ errors.first('disc_quantity') }}</span>
</div>
<div class="control-group" :class="[errors.has('disc_threshold') ? 'has-error' : '']">
<label for="disc_threshold" class="required">{{ __('admin::app.promotion.cart.buy-atleast') }}</label>
@ -275,6 +267,14 @@
<span class="control-error" v-if="errors.has('disc_threshold')">@{{ errors.first('disc_threshold') }}</span>
</div>
<div class="control-group" :class="[errors.has('disc_quantity') ? 'has-error' : '']">
<label for="disc_quantity" class="required">{{ __('admin::app.promotion.general-info.disc_qty') }}</label>
<input type="number" step="1" class="control" name="disc_quantity" v-model="disc_quantity" v-validate="'required|decimal|min_value:1'" value="{{ old('disc_quantity') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.disc_qty') }}&quot;">
<span class="control-error" v-if="errors.has('disc_quantity')">@{{ errors.first('disc_quantity') }}</span>
</div>
<div class="boolean-control-container">
<div class="control-group" :class="[errors.has('free_shipping') ? 'has-error' : '']">
<label for="free_shipping" class="required">{{ __('admin::app.promotion.general-info.free-shipping') }}</label>
@ -338,7 +338,7 @@
<accordian :active="false" title="labels">
<div slot="body">
<input type="hidden" name="all_conditions[]" v-model="all_conditions">
<input type="hidden" name="all_conditions" v-model="all_conditions">
<div class="control-group" :class="[errors.has('label') ? 'has-error' : '']" v-if="dedicated_label">
<label for="label" class="required">Global Label</label>
@ -398,9 +398,9 @@
apply_prct: false,
apply_to_shipping: null,
buy_atleast: null,
disc_amount: 0.0,
disc_threshold: 0,
disc_quantity: 0,
disc_amount: null,
disc_threshold: null,
disc_quantity: null,
end_other_rules: null,
coupon_type: null,
free_shipping: null,
@ -510,37 +510,9 @@
}
});
// for (index in this.conditions_list) {
// if (this.conditions_list[index].condition == null || this.conditions_list[index].condition == "" || this.conditions_list[index].condition == undefined) {
// window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
// this.$root.addFlashMessages();
// return false;
// } else if (this.conditions_list[index].value == null || this.conditions_list[index].value == "" || this.conditions_list[index].value == undefined) {
// window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
// this.$root.addFlashMessages();
// return false;
// }
// }
// if (this.conditions_list.length == 0) {
// window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
// this.$root.addFlashMessages();
// return false;
// }
this.all_conditions = JSON.stringify(this.conditions_list);
},
// genericGroupCondition() {
// this.generic_condition = false;
// },
addFlashMessages() {
const flashes = this.$refs.flashes;

View File

@ -267,10 +267,10 @@
<span class="control-error" v-if="errors.has('disc_threshold')">@{{ errors.first('disc_threshold') }}</span>
</div>
<div class="control-group" :class="[errors.has('disc_amount') ? 'has-error' : '']">
<div class="control-group" :class="[errors.has('disc_quantity') ? 'has-error' : '']">
<label for="disc_amount" class="required">{{ __('admin::app.promotion.general-info.disc_qty') }}</label>
<input type="number" step="1" class="control" name="disc_quantity" v-model="disc_quantity" v-validate="'required|decimal'" value="{{ old('disc_quantity') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.disc_qty') }}&quot;">
<input type="number" step="1" class="control" name="disc_quantity" v-model="disc_quantity" v-validate="'required|decimal|min_value:1'" value="{{ old('disc_quantity') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.disc_qty') }}&quot;">
<span class="control-error" v-if="errors.has('disc_quantity')">@{{ errors.first('disc_quantity') }}</span>
</div>
@ -338,7 +338,7 @@
<accordian :active="false" title="labels">
<div slot="body">
<input type="hidden" name="all_conditions[]" v-model="all_conditions">
<input type="hidden" name="all_conditions" v-model="all_conditions">
<div class="control-group" :class="[errors.has('label') ? 'has-error' : '']" v-if="dedicated_label">
<label for="label" class="required">Global Label</label>
@ -395,9 +395,9 @@
apply_prct: false,
apply_to_shipping: null,
buy_atleast: null,
disc_amount: 0.0,
disc_threshold: 0,
disc_quantity: 0,
disc_amount: null,
disc_threshold: null,
disc_quantity: null,
end_other_rules: null,
coupon_type: null,
free_shipping: null,
@ -489,7 +489,10 @@
this.free_shipping = data.free_shipping;
this.all_conditions = null;
this.conditions_list = JSON.parse(JSON.parse(data.conditions));
if (data.conditions != null) {
this.conditions_list = JSON.parse(JSON.parse(data.conditions));
}
this.dedicated_label = false;
global_label = null;
@ -517,6 +520,7 @@
}
if (this.condition_on == 'cart') {
console.log(this.conditions_list);
this.conditions_list.push(this.cart_object);
this.cart_object = {

View File

@ -1233,28 +1233,31 @@ class Cart {
}
}
public function setNonCouponAble() {
public function setNonCoupon() {
return $this->discount->checkNonCouponConditions($this->getCart());
}
public function setCouponAble() {
return $this->discount->checkCouponConditions($this->getCart());
}
public function setCoupon()
{
return $this->setCouponAble();
return $this->discount->checkCouponConditions($this->getCart());
}
public function leastWorthItem()
{
$cart = $this->getCart();
$leastSubTotal = 0;
$leastValue = 999999999999;
$leastSubTotal = [];
foreach ($cart->items as $item) {
if ($item->sub_total > $leastSubTotal) {
$leastSubTotal = $item->sub_total;
if ($item->base_total < $leastValue) {
$leastValue = $item->total;
$leastSubTotal = [
'id' => $item->id,
'base_total' => $leastValue
];
}
}
return $leastSubTotal;
}
}

View File

@ -126,21 +126,26 @@ return [
'type' => 'numeric'
],
3 => [
'code' => 'shipping_method',
'name' => 'Shipping Method',
'type' => 'string'
],
4 => [
'code' => 'payement_method',
'name' => 'Payment Method',
'type' => 'string'
],
4 => [
5 => [
'code' => 'shipping_postcode',
'name' => 'Shipping Postcode',
'type' => 'string'
],
5 => [
6 => [
'code' => 'shipping_state',
'name' => 'Shipping State',
'type' => 'string'
],
6 => [
7 => [
'code' => 'shipping_country',
'name' => 'Shipping Country',
'type' => 'string'

View File

@ -52,7 +52,7 @@ class Discount
public function getGuestBestRules()
{
$rules = $this->cartRule->findWhere(['status' => 1, 'is_guest' => 1]);
$rules = $this->cartRule->findWhere(['status' => 1, 'end_other_rules' => 0, 'is_guest' => 1]);
$currentChannel = core()->getCurrentChannel();
$guestRules = array();
@ -234,11 +234,13 @@ class Discount
if (count($id)) {
return [
'end_rule' => false,
'noncouponable' => true,
'id' => $id
];
} else {
return [
'end_rule' => false,
'noncouponable' => false,
'id' => null
];
@ -256,11 +258,13 @@ class Discount
if (!$rule->use_coupon) {
return [
'end_rule' => true,
'noncouponable' => true,
'id' => $id
];
} else {
return [
'end_rule' => true,
'noncouponable' => false,
'id' => null
];

View File

@ -115,12 +115,12 @@ class CartRuleController extends Controller
'per_customer' => 'numeric|min:0',
'action_type' => 'required|string',
'disc_amount' => 'required|numeric',
'discount_quantity' => 'numeric|required_if:action_type,buy_a_get_b',
'disc_threshold' => 'numeric|required_if:action_type,buy_a_get_b',
'disc_quantity' => 'numeric',
'disc_threshold' => 'numeric',
'free_shipping' => 'required|boolean',
'apply_to_shipping' => 'required|boolean',
'code' => 'string|required_if:auto_generation,0',
'all_conditions' => 'array',
'all_conditions' => 'required',
'label' => 'array|nullable'
]);
@ -152,7 +152,11 @@ class CartRuleController extends Controller
unset($data['cart_attributes']);
unset($data['attributes']);
$data['conditions'] = $data['all_conditions'];
if (count(json_decode($data['all_conditions'])) == 0) {
$data['conditions'] = null;
} else {
$data['conditions'] = $data['all_conditions'];
}
unset($data['all_conditions']);
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {
@ -264,12 +268,12 @@ class CartRuleController extends Controller
'per_customer' => 'numeric|min:0',
'action_type' => 'required|string',
'disc_amount' => 'required|numeric',
'discount_quantity' => 'numeric|required_if:action_type,buy_a_get_b',
'disc_threshold' => 'numeric|required_if:action_type,buy_a_get_b',
'disc_quantity' => 'required|numeric',
'disc_threshold' => 'required|numeric',
'free_shipping' => 'required|boolean',
'apply_to_shipping' => 'required|boolean',
'code' => 'string|required_if:auto_generation,0',
'all_conditions' => 'array',
'all_conditions' => 'required',
'label' => 'array|nullable'
]);
@ -304,7 +308,11 @@ class CartRuleController extends Controller
unset($data['cart_attributes']);
unset($data['attributes']);
$data['conditions'] = $data['all_conditions'];
if (count(json_decode($data['all_conditions'])) == 0) {
$data['conditions'] = null;
} else {
$data['conditions'] = $data['all_conditions'];
}
unset($data['all_conditions']);
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {

View File

@ -254,17 +254,15 @@ class CartController extends Controller
*/
public function applyCoupons()
{
// dd(request()->all());
$this->validate(request(), [
'code' => 'string|required'
]);
$code = request()->input('code');
$rules = Cart::setCoupon();
$appliedRule = null;
$coupons = [];
foreach($rules['id'] as $rule) {
array_push($coupons, $rule->coupons->code);
if ($rule->use_coupon && $rule->auto_generation == 0) {
@ -278,14 +276,18 @@ class CartController extends Controller
}
}
if(! isset($appliedRule)) {
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 (isset($appliedRule->starts_from) && $appliedRule->starts_from == null) {
if ($appliedRule->condititions != null) {
$conditions = json_decode($appliedRule->condtions);
}
// check all the conditions associated with the rule
if (isset($appliedRule) && $appliedRule->starts_from == null) {
$action_type = $appliedRule->action_type;
$disc_threshold = $appliedRule->disc_threshold;
$disc_amount = $appliedRule->disc_amount;
@ -294,25 +296,43 @@ class CartController extends Controller
$newBaseSubTotal = 0;
$newQuantity = 0;
if ($cart->items_qty >= $disc_threshold) {
$leastWorthItem = Cart::leastWorthItem();
if ($action_type == config('pricerules.cart.validation.0')) {
//CART
$newBaseSubTotal = ($cart->base_sub_total * $disc_amount) / 100;
$newBaseSubTotal = ($leastWorthItem['base_total'] * $disc_amount) / 100;
} else if ($action_type == config('pricerules.cart.validation.1')) {
$newBaseSubTotal = $cart->base_sub_total - $disc_amount;
$newBaseSubTotal = $leastWorthItem['base_total'] - $disc_amount;
} else if ($action_type == config('pricerules.cart.validation.2')) {
//CART
$newQuantity = $cart->items()->first()->quantity + $disc_amount;
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_amount;
} else if ($action_type == config('pricerules.cart.validation.3')) {
$newBaseSubTotal = $disc_amount ;
$base_total = $disc_amount;
}
if ($action_type == config('pricerules.cart.validation.2')) {
dd($newQuantity);
return response()->json([
'message' => 'Success',
'action' => $action_type,
'amount_given' => false,
'amount' => $newQuantity
]);
} else {
dd($newBaseSubTotal);
return response()->json([
'message' => 'Success',
'action' => $action_type,
'amount_given' => true,
'amount' => $newBaseSubTotal
]);
}
} else {
return response()->json([
'message' => 'failed',
'action' => $action_type,
'amount_given' => null,
'amount' => null,
'least_value_item' => null
]);
}
} else {
} else if (isset($appliedRule) && $appliedRule->start_from != null) {
//time based rules
$action_type = $appliedRule->action_type;
$disc_threshold = $appliedRule->disc_threshold;
@ -322,6 +342,8 @@ class CartController extends Controller
$newBaseSubTotal = 0;
$newQuantity = 0;
if ($cart->items_qty >= $disc_threshold) {
$leastWorthItem = Cart::leastWorthItem();
dd($leastWorthItem);
if ($action_type == config('pricerules.cart.validation.0')) {
//CART
$newBaseSubTotal = ($cart->base_sub_total * $disc_amount) / 100;
@ -337,12 +359,14 @@ class CartController extends Controller
if ($action_type == config('pricerules.cart.validation.2')) {
return response()->json([
'message' => 'Success',
'action' => $action_type,
'amount_given' => false,
'amount' => $newQuantity
]);
} else {
return response()->json([
'message' => 'Success',
'action' => $action_type,
'amount_given' => true,
'amount' => $newBaseSubTotal
]);
@ -350,6 +374,7 @@ class CartController extends Controller
} else {
return response()->json([
'message' => 'failed',
'action' => $action_type,
'amount_given' => null,
'amount' => null,
'least_value_item' => Cart::leastWorthItem()

View File

@ -470,7 +470,8 @@
return {
templateRender: null,
code: null,
message: null
message: null,
qtyRevealed: false
}
},
@ -499,7 +500,6 @@
axios.post('{{ route('shop.checkout.check.coupons') }}', {
code: this_this.code
}).then(function(response) {
console.log(response.data.message);
this_this.message = response.data.message;
});
},

View File

@ -3,7 +3,8 @@
<div class="item-detail">
<label>
{{ intval($cart->items_qty) }}
<div v-if="! qtyRevealed">{{ intval($cart->items_qty) }}</div>
<div v-if="qtyRevealed">{{ intval($cart->items_qty) }} @{{ + amount_given (free) }}</div>
{{ __('shop::app.checkout.total.sub-total') }}
{{ __('shop::app.checkout.total.price') }}
</label>
@ -35,11 +36,11 @@
<form class="coupon-form" method="post" @submit.prevent="onSubmit">
<div class="control-group mt-20">
<input v-model="code" type="text" class="control" value="" name="code" placeholder="Enter Coupon Code" v-on:change="codeChange">
<input v-model="code" type="text" class="control" value="" name="code" placeholder="Enter Coupon Code" v-on:change="codeChange" style="width: 100%">
<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; color: #ff5656; margin-bottom: 5px;" v-if="message != 'Success' && message != 'success'">@{{ message }}</span>
<span class="coupon-message mt-5" style="display: block; 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 == 'success'">@{{ message }}</span>
<button class="btn btn-lg btn-primary">Apply Coupon</button>
</div>