mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Notify users when a tracked URL becomes available again after being out of stock (PriceGhost parity, task 4). - Url::updatePrice() dispatches a new AvailabilityChangedEvent whenever a URL's availability transitions between scrapes (the existing change detection now carries the previous/current StockStatus) - AvailabilityChangedListener fires a StockAlertNotification on the out-of-stock -> in-stock transition, gated by a per-product opt-in - StockAlertNotification reuses all 8 channels (mail, database, Pushover, Gotify, Apprise, Telegram, Discord, ntfy) with its own mail template - New products.notify_in_stock flag + 'Notify when back in stock' toggle in the product form - Tests for the end-to-end transition (opted in / not opted in / going out of stock) and the notification message formatting - Docs updated (features, products) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34 lines
830 B
PHP
34 lines
830 B
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Enums\StockStatus;
|
|
use App\Models\Url;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
/**
|
|
* Fired when a URL's availability changes between scrapes.
|
|
*
|
|
* `$previous` and `$current` are null when the item is in stock (PriceBuddy
|
|
* stores in-stock as a null availability) or a StockStatus when unavailable.
|
|
*/
|
|
class AvailabilityChangedEvent
|
|
{
|
|
use Dispatchable, SerializesModels;
|
|
|
|
public function __construct(
|
|
public Url $url,
|
|
public ?StockStatus $previous,
|
|
public ?StockStatus $current,
|
|
) {}
|
|
|
|
/**
|
|
* Whether the item just became purchasable (was unavailable, now in stock).
|
|
*/
|
|
public function isBackInStock(): bool
|
|
{
|
|
return $this->previous !== null && $this->current === null;
|
|
}
|
|
}
|