Files
Gordon HeydonandJeremy 6e35588f49 [#127] Add product availability tracking with stock status matching
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.
2026-03-27 13:52:51 +11:00

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,
];
}
}