cart rules working
This commit is contained in:
parent
3bc27604b6
commit
62a7954c33
|
|
@ -1240,9 +1240,4 @@ class Cart {
|
|||
public function setCouponAble() {
|
||||
return $this->discount->checkCouponConditions($this->getCart());
|
||||
}
|
||||
|
||||
public function setCoupon() {
|
||||
$couponRules = $this->setCouponAble();
|
||||
return $couponRules;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,13 +16,6 @@ class Discount
|
|||
$this->cartRule = $cartRule;
|
||||
}
|
||||
|
||||
public function checkCoupon()
|
||||
{
|
||||
foreach($this->cartRule->all() as $rule) {
|
||||
return $rule->name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getGuestEndRules()
|
||||
{
|
||||
$rules = $this->cartRule->findWhere(['status' => 1, 'end_other_rules' => 1, 'is_guest' => 1]);
|
||||
|
|
|
|||
|
|
@ -261,20 +261,79 @@ class CartController extends Controller
|
|||
$code = request()->input('code');
|
||||
|
||||
$rules = Cart::setCoupon();
|
||||
|
||||
$impacts = array();
|
||||
$appliedRule;
|
||||
|
||||
foreach($rules['id'] as $rule) {
|
||||
if ($rule->use_coupon && $rule->auto_generation == 0) {
|
||||
// dump($rule->coupons->code, $rule->id);
|
||||
|
||||
if ($rule->coupons->code == $code) {
|
||||
return $rule->id;
|
||||
$appliedRule = $rule;
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
dump($rule->coupons->prefix, $rule->coupons->suffix, $rule->id);
|
||||
dd('auto_generation in next version');
|
||||
}
|
||||
}
|
||||
|
||||
die;
|
||||
$cart = Cart::getCart();
|
||||
// check all the conditions associated with the rule
|
||||
if ($appliedRule->starts_from == null) {
|
||||
$action_type = $appliedRule->action_type;
|
||||
$disc_threshold = $appliedRule->disc_threshold;
|
||||
$disc_amount = $appliedRule->disc_amount;
|
||||
$disc_quantity = $appliedRule->disc_quantity;
|
||||
|
||||
$newBaseSubTotal = 0;
|
||||
$newQuantity = 0;
|
||||
if ($cart->items_qty >= $disc_threshold) {
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
//CART
|
||||
$newBaseSubTotal = ($cart->base_sub_total * $disc_amount) / 100;
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
$newBaseSubTotal = $cart->base_sub_total - $disc_amount;
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
//CART
|
||||
$newQuantity = $cart->items()->first()->quantity + $disc_amount;
|
||||
} else if ($action_type == config('pricerules.cart.validation.3')) {
|
||||
$newBaseSubTotal = $disc_amount ;
|
||||
}
|
||||
|
||||
if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
dd($newQuantity);
|
||||
} else {
|
||||
dd($newBaseSubTotal);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//time based rules
|
||||
$action_type = $appliedRule->action_type;
|
||||
$disc_threshold = $appliedRule->disc_threshold;
|
||||
$disc_amount = $appliedRule->disc_amount;
|
||||
$disc_quantity = $appliedRule->disc_quantity;
|
||||
|
||||
$newBaseSubTotal = 0;
|
||||
$newQuantity = 0;
|
||||
if ($cart->items_qty >= $disc_threshold) {
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
//CART
|
||||
$newBaseSubTotal = ($cart->base_sub_total * $disc_amount) / 100;
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
$newBaseSubTotal = $cart->base_sub_total - $disc_amount;
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
//CART
|
||||
$newQuantity = $cart->items()->first()->quantity + $disc_amount;
|
||||
} else if ($action_type == config('pricerules.cart.validation.3')) {
|
||||
$newBaseSubTotal = $disc_amount ;
|
||||
}
|
||||
|
||||
if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
dd($newQuantity);
|
||||
} else {
|
||||
dd($newBaseSubTotal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue