feat: implement product and variant CRUD management service with attachment handling

This commit is contained in:
2026-07-01 11:44:56 -03:00
parent 6d0d600b4b
commit a150a9f694
4 changed files with 79 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ use App\Domains\Tenant\Models\Tenant;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ProductService
@@ -332,6 +333,12 @@ class ProductService
throw new NotFoundHttpException('Product variant not found for product.');
}
if ($variantId !== null && $selectedVariant->stock <= 0) {
throw ValidationException::withMessages([
'variant_id' => 'La variante seleccionada no tiene stock.',
]);
}
$selectedVariant ??= $product->variants->first();
if ($selectedVariant !== null) {