diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php index d0f568c52..5299e1c80 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php @@ -457,8 +457,8 @@ match_criteria: 'all_are_true', all_attributes: { - 'categories' : null, - 'attributes' : null + 'categories' : [], + 'attributes' : [] }, code: null, @@ -481,7 +481,6 @@ conditions: @json($cart_rule[0]).conditions, cart_input: @json($cart_rule[0]).attributes, actions: @json($cart_rule[0]).actions, - conditions_list:[], cart_object: { attribute: [], condition: [], @@ -547,13 +546,7 @@ }, detectApply() { - if (this.apply == 'percent_of_product' || this.apply == 'buy_a_get_b') { - this.apply_prct = true; - this.apply_amt = false; - } else if (this.apply == 'fixed_amount' || this.apply == 'fixed_amount_cart') { - this.apply_prct = false; - this.apply_amt = true; - } + return; }, enableCondition(event, index) { @@ -597,26 +590,25 @@ }, onSubmit: function (e) { - if (this.attribute_values != null || this.category_values != null) { + if (this.attribute_values.length != 0 || this.category_values.length != 0) { for (i in this.attribute_values) { delete this.attribute_values[i].options; } - if (this.category_values != null) { - this.all_attributes.categories = this.category_values; - } + this.all_attributes.categories = this.category_values; this.all_attributes.attributes = this.attribute_values; - this.all_attributes = JSON.stringify(this.all_attributes); - } else { - this.all_attributes = null; } - if (this.conditions_list.length != 0) { + this.all_attributes = JSON.stringify(this.all_attributes); + + if (this.conditions_list != null && this.conditions_list.length != 0) { this.conditions_list.push({'criteria': this.match_criteria}); this.all_conditions = JSON.stringify(this.conditions_list); + + this.conditions_list.pop(); } this.$validator.validateAll().then(result => { diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php index 6086c1d61..69a6e4008 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php @@ -228,7 +228,7 @@ - + @@ -489,9 +489,10 @@ country_and_states: @json($cart_rule[2]), category_options: @json($cart_rule[1]), - category_values: [], + category_values: [], attribute_values: [], + attr_object: { attribute: null, condition: null, @@ -504,12 +505,11 @@ mounted () { data = @json($cart_rule[3]); + this.name = data.name; this.description = data.description; - this.conditions_list = []; - this.channels = []; for (i in data.channels) { @@ -576,22 +576,25 @@ this.all_conditions = null; - if (data.conditions != null) { + if (data.hasOwnProperty('conditions') && data.conditions != null) { this.conditions_list = JSON.parse(JSON.parse(data.conditions)); this.match_criteria = this.conditions_list.pop().criteria; } - if (JSON.parse(data.actions).attribute_conditions) { - this.category_values = JSON.parse(data.actions).attribute_conditions.categories; + hasSubSelectionConditions = JSON.parse(data.actions).hasOwnProperty('attribute_conditions'); - this.attribute_values = JSON.parse(data.actions).attribute_conditions.attributes; + if (hasSubSelectionConditions) { - if (this.category_values == null) { + if (JSON.parse(data.actions).attribute_conditions.hasOwnProperty('categories')) { + this.category_values = JSON.parse(data.actions).attribute_conditions.categories; + } else { this.category_values = []; } - if (this.attribute_values == null) { + if (JSON.parse(data.actions).attribute_conditions.hasOwnProperty('attributes')) { + this.attribute_values = JSON.parse(data.actions).attribute_conditions.attributes; + } else { this.attribute_values = []; } @@ -660,13 +663,7 @@ }, detectApply() { - if (this.apply == 'percent_of_product' || this.apply == 'buy_a_get_b') { - this.apply_prct = true; - this.apply_amt = false; - } else if (this.apply == 'fixed_amount' || this.apply == 'fixed_amount_cart') { - this.apply_prct = false; - this.apply_amt = true; - } + return; }, enableCondition(event, index) { @@ -714,7 +711,7 @@ }, onSubmit: function (e) { - if (this.attribute_values != null || this.category_values != null) { + if (this.attribute_values.length != 0 || this.category_values.length != 0) { for (i in this.attribute_values) { delete this.attribute_values[i].options; } @@ -728,7 +725,7 @@ this.all_attributes = null; } - if (this.conditions_list != null) { + if (this.conditions_list.length != 0) { this.conditions_list.push({'criteria': this.match_criteria}); this.all_conditions = JSON.stringify(this.conditions_list); diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index dbb680b12..b9208aefd 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -192,7 +192,7 @@ class CartRuleController extends Controller 'action_type' => $data['action_type'], 'disc_amount' => $data['disc_amount'], 'disc_quantity' => $data['disc_quantity'], - 'attribute_conditions' => json_encode($attribute_conditions) + 'attribute_conditions' => $attribute_conditions ]; }