From 256556a8721cef87795dce9b3913b56ed57bf79c Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Thu, 5 Sep 2019 19:51:02 +0530 Subject: [PATCH] Fixed issue #1391 --- README.md | 2 +- .../Http/Controllers/CartRuleController.php | 71 +++++++------------ 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 613b440cb..82a444eb2 100755 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Bagisto is using power of both of these frameworks and making best out of it out * **OS**: Ubuntu 16.04 LTS or higher / Windows 7 or Higher (WAMP / XAMP). * **SERVER**: Apache 2 or NGINX. * **RAM**: 3 GB or higher. -* **PHP**: 7.2 or higher. +* **PHP**: 7.1.3 or higher. * **Processor**: Clock Cycle 1 Ghz or higher. * **For MySQL users**: 5.7.23 or higher. * **For MariaDB users**: 10.2.7 or Higher. diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index 3beca8b8c..d51400faa 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -175,34 +175,25 @@ class CartRuleController extends Controller // unset labels unset($data['label']); - // prepare json object from actions - if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) { + $attribute_conditions = json_decode($attribute_conditions); + + if (! isset($attribute_conditions) || $attribute_conditions == "[]" || $attribute_conditions == "" || ! (count($attribute_conditions->categories) && count($attribute_conditions->attributes))) { + $data['uses_attribute_conditions'] = 0; + $data['actions'] = [ 'action_type' => $data['action_type'], 'disc_amount' => $data['disc_amount'], - 'disc_threshold' => $data['disc_threshold'] + 'disc_quantity' => $data['disc_quantity'] ]; - - $data['disc_quantity'] = $data['disc_amount']; } else { - if (! isset($attribute_conditions) || $attribute_conditions == "[]" || $attribute_conditions == "") { - $data['uses_attribute_conditions'] = 0; + $data['uses_attribute_conditions'] = 1; - $data['actions'] = [ - 'action_type' => $data['action_type'], - 'disc_amount' => $data['disc_amount'], - 'disc_quantity' => $data['disc_quantity'] - ]; - } else { - $data['uses_attribute_conditions'] = 1; - - $data['actions'] = [ - 'action_type' => $data['action_type'], - 'disc_amount' => $data['disc_amount'], - 'disc_quantity' => $data['disc_quantity'], - 'attribute_conditions' => $attribute_conditions - ]; - } + $data['actions'] = [ + 'action_type' => $data['action_type'], + 'disc_amount' => $data['disc_amount'], + 'disc_quantity' => $data['disc_quantity'], + 'attribute_conditions' => $attribute_conditions + ]; } // prepare json object from conditions @@ -269,7 +260,6 @@ class CartRuleController extends Controller // $coupons['limit'] = $data['usage_limit']; // } - // create a cart rule $ruleCreated = $this->cartRule->create($data); @@ -413,34 +403,25 @@ class CartRuleController extends Controller unset($data['attributes']); // prepare actions from data for json action - if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) { + $attribute_conditions = json_decode($attribute_conditions); + + if (! isset($attribute_conditions) || $attribute_conditions == "[]" || $attribute_conditions == "" || ! (count($attribute_conditions->categories) && count($attribute_conditions->attributes))) { + $data['uses_attribute_conditions'] = 0; + $data['actions'] = [ 'action_type' => $data['action_type'], 'disc_amount' => $data['disc_amount'], + 'disc_quantity' => $data['disc_quantity'] ]; - - $data['disc_quantity'] = $data['disc_amount']; } else { - $attribute_conditions = json_decode($attribute_conditions); + $data['uses_attribute_conditions'] = 1; - if (! (isset($attribute_conditions->categories) && count($attribute_conditions->categories)) && ! (isset($attribute_conditions->attributes) && count($attribute_conditions->attributes))) { - $data['uses_attribute_conditions'] = 0; - - $data['actions'] = [ - 'action_type' => $data['action_type'], - 'disc_amount' => $data['disc_amount'], - 'disc_quantity' => $data['disc_quantity'] - ]; - } else { - $data['uses_attribute_conditions'] = 1; - - $data['actions'] = [ - 'action_type' => $data['action_type'], - 'disc_amount' => $data['disc_amount'], - 'disc_quantity' => $data['disc_quantity'], - 'attribute_conditions' => json_encode($attribute_conditions) - ]; - } + $data['actions'] = [ + 'action_type' => $data['action_type'], + 'disc_amount' => $data['disc_amount'], + 'disc_quantity' => $data['disc_quantity'], + 'attribute_conditions' => $attribute_conditions + ]; } // encode php array to json for actions