# Your first extension

A step-by-step start for an agency or a shop's developer. The full reference is
[Writing an extension](extensions.md); the types you may use are in the [Extension API](extension-api.md).

## 1. Create it

In the shop's project (the SyncSHOP skeleton):

```bash
php artisan syncshop:make:extension acme/syncshop-erp --name="Acme ERP" --owner=agency
composer config repositories.syncshop-erp path extensions/syncshop-erp
composer require acme/syncshop-erp:@dev
php artisan migrate && php artisan permissions:sync
```

`extensions/syncshop-erp` now holds a working extension:

| File | What it does |
| --- | --- |
| `composer.json` | Type `syncshop-extension`, its provider for Laravel's package discovery, `extra.syncshop` (name, owner), the `syncshop/core` versions it works with |
| `src/ErpServiceProvider.php` | Registers a permission, an admin screen under `/admin/syncshop-erp` and its sidebar entry, its views, strings and migrations |
| `src/Models/Item.php`, `src/Http/ItemController.php`, `resources/views/index.blade.php` | The screen: a list of the extension's own rows |
| `database/migrations/…_create_syncshop_erp_items_table.php` | Its own table, given to the shop with `ShopTables::scope()` |
| `lang/ro`, `lang/en` | Its strings, Romanian first |
| `tests/ContractTest.php` | Fails if `src/` uses a core type that is not `@api` |

Sign in as the owner: **Acme ERP** is in the sidebar, and under Settings → Extensions with its version.

## 2. Grow it

Add what you need in the provider's `boot()`, one registry at a time:

- a card under Settings: `SettingsSections::add(new SettingsSection(...))`, with settings of its own
  (`SettingsClasses::add()` and a settings migration);
- a recurring job: `ScheduledTaskRegistry::add(new ScheduledTaskDefinition(...))`, never a `Schedule::` line;
- something on a storefront or admin page: `ViewSlots::add(ViewSlot::ProductAfterPrice, 'syncshop-erp::slots.price')`;
- a price rule: `TotalsStages::after(TotalsStages::PROMOTIONS, YourStage::class)`;
- an API endpoint: `ApiResources::add(YourResource::class)`, listed in the OpenAPI file;
- a reaction to an order: `Event::listen(OrderPlaced::class, YourListener::class)`.

Each is a row in [Writing an extension](extensions.md#the-service-provider), with what it needs.

## 3. Keep it working across updates

- Use only `@api` types: `tests/ContractTest.php` checks, and they keep their shape across minor releases.
- Never edit `vendor/`, never alter a core table: keep your data in your own tables (scoped) or a `meta` column.
- Before a SyncSHOP update, Settings → Updates shows whether the extension's `syncshop/core` constraint accepts the
  new version.
- A design change is a child theme, not an extension: `php artisan syncshop:theme:override <view>`, and after each
  update `php artisan syncshop:theme:diff`.

## 4. On SyncSHOP hosting

The same extension runs on our hosting once we have reviewed it, switched on per shop. Keep per-request state out
of static properties and register through the registries above, so it runs only for the shops it is on for. An
extension for other shops is sold only through the SyncSHOP marketplace.
