mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Add availability field to URLs for tracking product stock status (in stock, pre-order, back order, special order, out of stock, discontinued). Includes configurable match rules per store with exact match and regex support, priority-based matching, and a default status fallback. Out-of-stock products can now be added with price set to 0. Added The Tech Geeks store with availability detection and seeded Ubiquiti products.
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ProductResource\Pages;
|
|
|
|
use App\Filament\Resources\ProductResource;
|
|
use App\Models\Url;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class CreateProduct extends CreateRecord
|
|
{
|
|
protected static string $resource = ProductResource::class;
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
protected function handleRecordCreation(array $data): Model
|
|
{
|
|
$url = data_get($data, 'url');
|
|
$productId = data_get($data, 'product_id');
|
|
|
|
$urlModel = Url::createFromUrl(
|
|
url: $url,
|
|
productId: $productId,
|
|
userId: auth()->id(),
|
|
createStore: data_get($data, 'create_store', false),
|
|
priceFactor: (float) data_get($data, 'price_factor', 1),
|
|
);
|
|
|
|
if ($urlModel === false) {
|
|
throw ValidationException::withMessages([
|
|
'url' => __('Unable to create product from this URL'),
|
|
]);
|
|
}
|
|
|
|
return $urlModel->product;
|
|
}
|
|
|
|
public function getFooterWidgetsColumns(): int|array
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
protected function getFooterWidgets(): array
|
|
{
|
|
return [
|
|
ProductResource\Widgets\CreateViaSearchForm::class,
|
|
];
|
|
}
|
|
}
|