From 25cc2c0ef51307be0843e8f7c8166cc1f2d97847 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Sat, 3 Dec 2022 20:47:42 +0000 Subject: [PATCH] Fix review count automation condition attribute Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- automationrules/conditions/ReviewCount.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/automationrules/conditions/ReviewCount.php b/automationrules/conditions/ReviewCount.php index d75ac44..5cb528a 100644 --- a/automationrules/conditions/ReviewCount.php +++ b/automationrules/conditions/ReviewCount.php @@ -31,13 +31,12 @@ public function defineModelAttributes() public function getReviewCountAttribute($value, $object) { - $object = array_get($params, 'order', array_get($params, 'reservation')); if (!$object instanceof Model) return false; - return Reviews_model::where([ - 'sale_id' => $object->order_id ?? $object->reservation_id, - 'sale_type' => $object->order_id ? 'orders' : 'reservations', + return Reviews_model::query()->where([ + 'sale_id' => $object->getKey(), + 'sale_type' => $object->getMorphClass(), ])->count(); } }