@@ -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 = {
diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php
index fb52b5ca9..94fd38472 100755
--- a/packages/Webkul/Checkout/src/Cart.php
+++ b/packages/Webkul/Checkout/src/Cart.php
@@ -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;
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Config/rule-conditions.php b/packages/Webkul/Discount/src/Config/rule-conditions.php
index b5190e06e..02be38310 100644
--- a/packages/Webkul/Discount/src/Config/rule-conditions.php
+++ b/packages/Webkul/Discount/src/Config/rule-conditions.php
@@ -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'
diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php
index b7c4e63e0..2baee2c79 100644
--- a/packages/Webkul/Discount/src/Helpers/Discount.php
+++ b/packages/Webkul/Discount/src/Helpers/Discount.php
@@ -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
];
diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php
index 95da60aad..022a9ea8e 100644
--- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php
+++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php
@@ -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')) {
diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php
index 6cffaa8b9..cc6020957 100755
--- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php
+++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php
@@ -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()
diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php
index d665f8d5d..661e18343 100755
--- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php
@@ -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;
});
},
diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
index 38c8368d8..790d04000 100755
--- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
@@ -3,7 +3,8 @@
@@ -35,11 +36,11 @@