PHP code example of fostercommerce / meilisearch-connect
1. Go to this page and download the library: Download fostercommerce/meilisearch-connect library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fostercommerce / meilisearch-connect example snippets
Event::on(
Product::class,
Element::EVENT_AFTER_SAVE,
static function (\craft\events\ModelEvent $event) {
if (
! ElementHelper::isDraft($event->sender) &&
! $event->sender->resaving &&
! ElementHelper::isRevision($event->sender)
) {
$item = $event->sender;
$status = $item->getStatus();
if ($status === Entry::STATUS_LIVE) {
// If an entry is live, then we can add it to the index
Queue::push(new SyncJob([
'indexName' => 'pages',
'identifier' => $item->id,
]));
} else {
// Otherwise, we should make sure that it is not in the index
Queue::push(new DeleteJob([
'indexName' => 'pages',
'identifier' => $item->id,
]));
}
}
}
);