mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
The product page has a new "Add multiple URLs" action that takes up to 50
URLs, one per line. POST /api/products/{id}/urls does the same for API
clients and needs the product:update ability. Invalid, repeated and existing
URLs are skipped and reported. Each other URL is scraped by a queued job,
because one scrape can take up to 30 seconds. A URL that cannot be added sends
a "URL not added" notification.
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Product;
|
|
use Filament\Notifications\Actions\Action;
|
|
use Filament\Notifications\Notification as DatabaseNotification;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Str;
|
|
|
|
class AddUrlFailedNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(public Product $product, public string $url) {}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database'];
|
|
}
|
|
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
return [
|
|
'product_id' => $this->product->getKey(),
|
|
'url' => $this->url,
|
|
];
|
|
}
|
|
|
|
public function toDatabase($notifiable): array
|
|
{
|
|
return DatabaseNotification::make()
|
|
->title('Unable to add URL to '.Str::limit($this->product->title, 60))
|
|
->body(Str::limit($this->url, 200).' has no price, or no store matches it.')
|
|
->status('warning')
|
|
->actions([
|
|
Action::make('view')
|
|
->url(parse_url($this->product->view_url, PHP_URL_PATH))
|
|
->label('View product'),
|
|
])
|
|
->getDatabaseMessage();
|
|
}
|
|
}
|