sylius/archetype-bundle
Sylius ArchetypeBundle adds reusable archetypes to Sylius, letting you define product templates with shared attributes and options. It streamlines catalog setup, keeps similar products consistent, and reduces repetitive configuration when creating new items.
First, the honest read: this is a Symfony bundle. It will not boot in Laravel — no service provider, no config/archetypes.php, no Composer auto-discovery. composer require sylius/archetype-bundle will either fail resolution against laravel/framework/PHP 8.x or install a package that does nothing. Do not put it in composer.json.
What you actually do on day one:
vendor/) and read, in this order:
DependencyInjection/Configuration.php — the archetype config shape (attributes, properties, options attached to a parent template).Resources/config/services.xml — the service IDs that reveal the domain seams: a builder (constructs an archetype from a parent + overrides), a resolver (product → archetype lookup), and a registry (archetype lookup by name/type).Model/ and Resources/config/doctrine/ — the actual entity relationships, which are the only part you will port.Archetype → product_archetypes, plus pivot tables for archetype↔attribute, archetype↔property, archetype↔option, and a nullable archetype_id on products.Where to look in your own codebase first: whatever currently duplicates attribute or option setup across product creation — admin form defaults, import mappers, and seeders are the three usual offenders. That duplication is the thing the archetype pattern removes.
Only install it if you are maintaining a live Sylius 0.x install and need to read schema/behaviour before migrating off. Even then you read it; you do not add it to a Laravel project.
Native Laravel reimplementation (the recommended path). The bundle's four pieces map cleanly onto Laravel primitives:
ProductArchetype with hasMany/belongsToMany to your existing attributes, properties, and options tables. Keep the pivots dumb (id pairs + a position column); keep behaviour in services.archetype_id on products with nullOnDelete() so an archetype can be retired without orphaning catalog data. Children read the archetype's collections only for defaults; they must own their finalised values so editing an archetype later doesn't retroactively rewrite live products.App\Catalog\ArchetypeBuilder). Signature roughly build(ProductArchetype $archetype, array $overrides = []): Product. It copies attributes/options/properties onto the new product and applies overrides last. This is the single place inheritance logic lives — mirroring the bundle's builder instead of scattering $product->fill($archetype->toArray()) across controllers.ArchetypeResolver). resolveFor(Product|string $subject): ?ProductArchetype, backed by an explicit column in the common case and by a strategy/chain for custom rules (category → archetype, SKU prefix → archetype). Inject the resolver; never hard-code ProductArchetype::find(3) in a controller.ArchetypeRegistry). A keyed collection populated from a config file (config/archetypes.php) so product families have stable string handles ('apparel.tshirt') usable in importers, seeders, and admin dropdowns without coupling to database IDs.VariantMatrixGenerator::expand(Product $product): Collection) that materialises one variant per option-value combination, with a uniqueness guard on the combination key. Port the idea; the Sylius implementation won't run.Workflow and integration tips:
updateOrCreate on the registry key) so re-seeding doesn't duplicate templates or detach products.archetype: {id, key, name}) on product responses rather than inlining its attributes — clients that need the template can fetch it, and you avoid stale snapshots.ProductCreatedFromArchetype when the builder runs so search indexing, pricing rules, and third-party syncs can react to the template that produced the product.composer audit will flag it; architecture review will reject it. Treat any adoption as a permanent fork with an owner and an exit date.ProductBundle, AttributeBundle, OptionBundle, ResourceBundle) and collapses under modern PHP.ProductAttribute / ProductOption / ProductVariant in later Sylius. Grep exhaustively for Archetype before estimating a migration; you'll find it in fixtures, admin templates, form types, and serialized payloads, not just entities. Missing one leaves you chasing phantom data after the port.with('archetype.attributes', 'archetype.options')) and consider a cached, flattened "defaults" payload if the list is large.products.archetype_id (or be blocked), never cascade into products. Enforce it at the FK level, not just in the model, so an importer bug can't wipe a catalog.config/archetypes.php and validate registry keys at boot — silent missing keys are how you end up with a null archetype in production.How can I help you explore Laravel packages today?