fix: 🐛 add property_exists in getCustomerDiscountsCount

This commit is contained in:
Nicolas Demangeat 2025-08-21 15:43:50 +02:00
parent 427ee27f63
commit 7459d9450b

View file

@ -162,16 +162,22 @@ class Discount extends Model
/** @var \LDC\MESBR\MesBr */
$mesBr = app('mesBrAPI');
$customerWall = $mesBr->getMurCustomer($hashcode);
if ($customerWall->status === "KO") {
return 0;
}
if (isset($mesBr->getMurCustomer($hashcode)->coupons)) {
return collect($mesBr->getMurCustomer($hashcode)->coupons)->filter(function ($discount) {
return !$discount->used;
})->count();
if (!property_exists($customerWall, 'coupons')) {
return 0;
}
return 0;
if (!isset($customerWall->coupons)) {
return 0;
}
return collect($customerWall->coupons)
->filter(fn($discount) => !$discount->used)
->count();
}
/**