No Coupons discount for selected Users – Bug in Corals/modules/Ecommerce/Classes/Coupons/Advanced.php

Laraship QuestionsCategory: issues & BugsNo Coupons discount for selected Users – Bug in Corals/modules/Ecommerce/Classes/Coupons/Advanced.php
martin asked 5 years ago

In

Corals/modules/Ecommerce/Classes/Coupons/Advanced.php

is this code - which makes no sense at this point:

if ($this->settings->products->count() > 0) {

$productlimited = true;

$cartitems = ShoppingCart::getItems();

foreach ($cartitems as $cartitem) {

if ($this->settings->users->contains($cartitem->id->product->id)) {

$productstotalprice += ($cartitem->qty $cartitem->price);

$productlimited += $cartitem->qty;

}

}

    }

It should be:

if ($this->settings->users->count() > 0) {

$product_limited = true;

$cart_items = \ShoppingCart::getItems();

foreach ($cart_items as $cart_item) {

if ($this->settings->users->contains($user->id)) {

$products_total_price += ($cart_item->qty * $cart_item->price);

$product_limited += $cart_item->qty;

}

}

}

2 Answers
Best Answer
laraship Staff answered 5 years ago

Hello,

User Validation validation is in the validate function

public function validate($throwErrors = false, $user = null)

{

.

.

.

if (!$user) {

$user = user();

}

if ($this->settings->users->count() > 0) {

if ($this->settings->users->contains($user->id)) {

return true;

} else {

if ($throwErrors) {

throw new CouponException(trans('Ecommerce::exception.coupon.not_eligible_use_coupon'));

} else {

return false;

}

}

}

laraship Staff answered 5 years ago

Hello,

Thanks for Pointing out the issue above, howeve I think instead of

        if ($this->settings->users->contains($user->id)) {

it should be

            if ($this->settings->products->contains($cart_item->id->product->id)) {

we just pushed a fix to the ecmmerce module