Skip to content

Commit cd82902

Browse files
committed
STU-180 Added listener for commerce orders
Signed-off-by: Jan Henckens <[email protected]>
1 parent 6524c81 commit cd82902

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Scout.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Exception;
1818
use Illuminate\Support\Collection;
1919
use rias\scout\behaviors\SearchableBehavior;
20+
use rias\scout\events\ShouldBeSearchableEvent;
2021
use rias\scout\jobs\DeindexElement;
2122
use rias\scout\jobs\IndexElement;
2223
use rias\scout\models\Settings;
@@ -183,6 +184,18 @@ function(ElementEvent $event) {
183184
);
184185
}
185186

187+
Event::on(SearchableBehavior::class,
188+
SearchableBehavior::EVENT_SHOULD_BE_SEARCHABLE, function(ShouldBeSearchableEvent $event) {
189+
$element = $event->element;
190+
$class = get_class($element);
191+
if ($class === "craft\\commerce\\elements\\Order") {
192+
if (!$element->dateOrdered) {
193+
$event->shouldBeSearchable = false;
194+
}
195+
}
196+
}
197+
);
198+
186199
Event::on(
187200
Elements::class,
188201
Elements::EVENT_BEFORE_DELETE_ELEMENT,

0 commit comments

Comments
 (0)