# The catalog

The Catalog module owns products, variants, categories, brands, attributes, and the manufacturer details GPSR
requires. There are no admin screens for it yet; this page describes the data model they will edit.

## Products and variants

A **product** is what a customer reads about: name, descriptions, brand, categories, specifications and its VAT
class. A **variant** is what they buy, and every product has at least one. `CreateProduct` makes the product and its
first, default variant together.

The variant holds what can differ between, say, the 500 ml and the 2 l bottle:

| Column | What it holds |
| --- | --- |
| `sku` | unique, case-insensitive (`ABC-1` and `abc-1` are the same SKU); a deleted variant's SKU can be reused |
| `gtin`, `mpn` | barcode (8–14 digits) and manufacturer part number |
| `price_amount` | the retail price in bani, VAT included (`$variant->price` is a `Money` in RON) |
| `fulfilment_type` | shipped, download, licence key, access, gift card or service |
| `deposit_units` | SGR containers in one unit sold: 1 for a bottle, 6 for a six-pack |
| weight and size | for shipping |

Stock is not on the variant: it is kept per location, in the Inventory module.

`deposit_units` sits on the variant, not the product as the plan first had it, because a six-pack and a single
bottle of the same product hold different numbers of containers.

A product starts as a **draft**. `PublishProduct` makes it **active**; **archived** products are no longer sold.
Slugs are set from the name once, per language and without diacritics (`Îngrijire și sănătate` becomes
`ingrijire-si-sanatate`), and change only when someone edits them.

## Categories

Categories form a tree. Each one stores its `path` from the root as a PostgreSQL `ltree` of ids (`3.17.42`), so a
whole subtree or the breadcrumb trail is a single indexed query:

```php
$category->descendants()->get();   // everything below, at any depth
$category->ancestors()->get();     // root first, for breadcrumbs
```

Move a category only with `MoveCategory`, which rewrites the paths of its subtree in one statement and refuses to
move a category below itself. Changing `parent_id` directly throws. A product can sit in several categories and
names one as its primary category.

## Attributes

An attribute is a specification, a filter, or a variant axis:

- **select** and **multiselect** attributes have a list of values (`Roșu`, `500 ml`). Each value has a slug from its
  Romanian label, used in filter URLs, which stays the same when the label is edited;
- **number**, **text** and **boolean** attributes take a value per product (`500` ml, `Spălare la 30 °C`, yes/no);
- a **variant axis** (colour, size) must be a select attribute, and each variant has exactly one value per axis.

A category lists the attributes its products use and which of them it offers as filters.

## GPSR

Under GPSR (Regulation (EU) 2023/988, art. 19), a product page must name the manufacturer with a postal and an
electronic address. If the manufacturer is outside the EU, the page must also name the responsible person in the
EU, and each product needs an identifier. Manufacturers and responsible persons are set on a brand and can be
overridden per product.

`PublishProduct` refuses a product until `GpsrCheck` finds nothing missing:

- a manufacturer, with a street, a city, and an email address or a website;
- an EU responsible person, when the manufacturer's country is outside the EU;
- a barcode or a manufacturer part number on every active variant that is shipped.

Products with no shipped variant (downloads, licences, services) are outside GPSR. A shop can switch the check off
in the catalog settings (`gpsr_required`).

## Images and storage

Product images use `spatie/laravel-medialibrary` in the product's `images` collection, on the `media` disk
(`storage/app/public/media`, served at `/storage/media` after `php artisan storage:link`, which `composer setup` and
the deploy run). Conversions (`thumb` 160 px square, `card` 600 px, `medium` 900 px, `large` 1600 px, all WebP at quality 75) are
made on the queue; the product page offers card, medium and large in its `srcset`, so phones get medium. After
adding a size, `php artisan media-library:regenerate --only=<size>` makes it for existing images. The alt text is a per-language custom property, `alt`. A variant's `image_id` points at one of its product's
images, and the database clears it when the image is deleted.

Files that must not be public (invoices, return documents, B2B files) go to the `private` disk, which is never served
directly. External storage (S3-compatible buckets) is configured later from Settings → Storage.

## Bundles and packs

- `variant_components` (`variant_id`, `component_id`, `quantity`, `position`): what one unit of a variant holds.
- `Contracts\Bundles` (`Bundles\DatabaseBundles`, bound **scoped**, keeps what it read for the request): `components()`,
  `componentsOf()`, `contents()` (`BundlePart`, through `VariantDirectory::cards()`, resolved lazily: the directory's
  visitor reaches Inventory's `Stock`, which needs `Bundles`), `describe()` (the order line's Romanian snapshot),
  `usedIn()`.
- `Actions\SaveBundle` parses "SKU quantity" lines and refuses: an unknown SKU, the variant itself, non-shipped
  variants, nesting (a component that is a bundle, or a bundle that is a component), a different `vat_class`, a variant
  with stock or reservations of its own, more than 20 components. It sets `deposit_units` (and `weight_grams` when
  empty) from the components. Admin: `BundleController` (`admin.catalog.products.variants.components`).
- `DeleteVariant` refuses a variant that is a component. `VariantDirectory::page(physicalOnly: true)` leaves bundles out.

