Fixed issues related to empty attribute conditions

This commit is contained in:
Prashant Singh 2019-08-21 16:10:39 +05:30
parent 171b48453e
commit 151c7a830a
2 changed files with 40 additions and 8 deletions

View File

@ -505,23 +505,33 @@
mounted () {
data = @json($cart_rule[3]);
this.name = data.name;
this.description = data.description;
this.conditions_list = [];
this.channels = [];
for (i in data.channels) {
this.channels.push(data.channels[i].channel_id);
}
this.customer_groups = data.customer_groups;
for (i in data.customer_groups) {
this.customer_groups.push(data.customer_groups[i].customer_group_id);
}
this.ends_till = data.ends_till;
this.starts_from = data.starts_from;
this.priority = data.priority;
this.per_customer = data.per_customer;
this.status = data.status;
if (data.use_coupon == 0) {
// this.auto_generation = null;
this.use_coupon = 0;
@ -539,24 +549,36 @@
}
this.usage_limit = data.usage_limit;
this.is_guest = data.is_guest;
this.action_type = data.action_type;
this.apply = null;
this.apply_amt = false;
this.apply_prct = false;
this.apply_to_shipping = data.apply_to_shipping;
this.disc_amount = data.disc_amount;
// this.disc_threshold = data.disc_threshold;
this.disc_quantity = data.disc_quantity;
this.end_other_rules = data.end_other_rules;
this.coupon_type = data.coupon_type;
this.free_shipping = data.free_shipping;
this.all_conditions = null;
if (data.conditions != null) {
this.conditions_list = JSON.parse(JSON.parse(data.conditions));
this.match_criteria = this.conditions_list.pop().criteria;
}
@ -565,6 +587,16 @@
this.attribute_values = JSON.parse(JSON.parse(data.actions).attribute_conditions).attributes;
if (this.category_values == null) {
this.category_values = [];
}
if (this.attribute_values == null) {
this.attribute_values = [];
}
console.log(this.category_values);
// creating options and has option param on the frontend
for (i in this.attribute_values) {
for (j in this.attribute_input) {
@ -689,9 +721,7 @@
delete this.attribute_values[i].options;
}
if (this.category_values != null && this.category_values.length > 0) {
this.all_attributes.categories = this.category_values;
}
this.all_attributes.categories = this.category_values;
this.all_attributes.attributes = this.attribute_values;
@ -700,7 +730,7 @@
this.all_attributes = null;
}
if (this.conditions_list.length != 0) {
if (this.conditions_list != null) {
this.conditions_list.push({'criteria': this.match_criteria});
this.all_conditions = JSON.stringify(this.conditions_list);

View File

@ -272,7 +272,7 @@ class CartRuleController extends Controller
// create a cart rule
$ruleCreated = $this->cartRule->create($data);
// can execute convert x here after when the rule is updated
// can execute convertX here after when the rule is updated
if (isset($attribute_conditions) && $attribute_conditions != "[]" && $attribute_conditions != "") {
$this->convertX->convertX($ruleCreated->id, $attribute_conditions);
}
@ -420,7 +420,9 @@ class CartRuleController extends Controller
$data['disc_quantity'] = $data['disc_amount'];
} else {
if (! isset($attribute_conditions) || $attribute_conditions == "[]" || $attribute_conditions == "") {
$attribute_conditions = json_decode($attribute_conditions);
if (! (isset($attribute_conditions->categories) && count($attribute_conditions->categories)) && ! (isset($attribute_conditions->attributes) && count($attribute_conditions->attributes))) {
$data['uses_attribute_conditions'] = 0;
$data['actions'] = [
@ -435,7 +437,7 @@ class CartRuleController extends Controller
'action_type' => $data['action_type'],
'disc_amount' => $data['disc_amount'],
'disc_quantity' => $data['disc_quantity'],
'attribute_conditions' => $attribute_conditions
'attribute_conditions' => json_encode($attribute_conditions)
];
}
}
@ -498,7 +500,7 @@ class CartRuleController extends Controller
// update cart rule
$ruleUpdated = $this->cartRule->update($data, $id);
if (isset($attribute_conditions) && $attribute_conditions != "[]" && $attribute_conditions != "") {
if (isset($attribute_conditions) && $data['uses_attribute_conditions']) {
// can execute convert X here after when the rule is updated
$this->convertX->convertX($ruleUpdated->id, $attribute_conditions);
} else {