# eBay Order Platform Icon Detection

## Background

eBay orders arrive in Cydekick via Shopify's **Marketplace Connect** app — they are created in Shopify first, then synced to Cydekick via the `orders/create` webhook. Because the Cydekick channel is a Shopify channel, the platform icon defaulted to Shopify for all orders, including those originating from eBay.

## What was built (18 Jun 2026)

- Added a `source_name` column to `channel_orders_orders`
- `ShopifyOrderImporter::resolveSourcePlatform()` extracts the originating marketplace from the Shopify payload and stores it in `source_name`
- All three icon display points in `OrderResource.php` now prefer `source_name` over the channel platform slug when set

**Detection logic (in priority order):**

1. **`note_attributes`** — Marketplace Connect apps often add a note attribute with key `marketplace`, `external_marketplace`, or `marketplace_id`. If found, its value (e.g. `"ebay"`) is stored directly.
2. **`source_name` field** — Falls back to the Shopify order's `source_name` field and pattern-matches against known strings (`"ebay"`, `"amazon"`, `"woocommerce"`).

## What to check when the next eBay order arrives

Run in tinker:

```bash
php artisan tinker
```

```php
// Check what source_name was stored for the most recent order
\Webkul\ChannelOrders\Models\Order::latest()->value('source_name')

// Or find the specific eBay order by Shopify reference
\Webkul\ChannelOrders\Models\Order::where('external_channel_reference', 'like', '#137%')->value('source_name')
```

### Expected outcomes

| `source_name` value | Icon shows | Action needed |
|---------------------|-----------|---------------|
| `"ebay"` | eBay icon ✓ | None — working |
| `null` | Shopify icon | See fix below |
| `"marketplace-connect"` | Shopify icon | See fix below |
| Some numeric app ID | Shopify icon | See fix below |

### If source_name is not "ebay" — fix

Open `plugins/webkul/channels/src/Services/ShopifyOrderImporter.php` and find `resolveSourcePlatform()`.

Add the actual value to the match block. For example, if the value is `"marketplace-connect"`:

```php
return match (true) {
    str_contains($sourceName, 'ebay')          => 'ebay',
    str_contains($sourceName, 'amazon')        => 'amazon',
    str_contains($sourceName, 'woocommerce')   => 'woocommerce',
    str_contains($sourceName, 'marketplace')   => 'ebay',  // ← add this
    default                                    => null,
};
```

If it is a numeric app ID or something else entirely, add an exact match:

```php
$sourceName === '1234567' => 'ebay',
```

## Existing orders

Orders imported before 18 Jun 2026 have `source_name = null` and will continue to show the Shopify icon. This is cosmetic only — the orders are correct.

To backfill a specific order manually:

```php
\Webkul\ChannelOrders\Models\Order::where('name', 'C1369')->update(['source_name' => 'ebay']);
```

## Related files

| File | Role |
|------|------|
| `plugins/webkul/channels/src/Services/ShopifyOrderImporter.php` | `resolveSourcePlatform()` method — detection logic |
| `plugins/webkul/channel-orders/src/Filament/Resources/OrderResource.php` | Icon display — uses `$record->source_name ?? $record->channel->platform` |
| `plugins/webkul/channel-orders/database/migrations/2026_06_18_000001_add_source_name_to_channel_orders_orders_table.php` | Migration that added the column |
| `public/vendor/channels/platforms/ebay.svg` | The eBay icon (already exists) |
| `z_notes/Plugins/Channel Orders/platform-icons.rmd` | Full platform icon documentation |
