# Remaining Variant & Catalog Product References

> After adding sales products to the catalog, standardizing products, and eliminating variant/catalog product categories, **the following areas still use the old system.**

---

## Summary

| Category | File Count | Status |
|----------|-----------|--------|
| `Catalog\Products\Models\Product` imports | 20+ files | ❌ Not migrated |
| `Catalog\Products\Models\ProductVariant` imports | 12+ files | ❌ Not migrated |
| `ProductVariantGroup` references | 4 files | ❌ Not migrated |
| `variant_id` field usage | 30+ files | ❌ Not migrated |
| `catalog_products` table validation rules | 14 rules | ❌ Not migrated |
| `catalog_product_variants` table references | 7 rules/files | ❌ Not migrated |
| Route files using Catalog controllers | 2 files | ❌ Not migrated |

---

## 1. Supply Domain — Still Using `variant_id`

> [!CAUTION]
> These files were **not** covered in the initial unification and still use `variant_id` to query inventory.

### Helpers

| File | Lines | Usage |
|------|-------|-------|
| [InventoryCheckHelper.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/Helpers/InventoryCheckHelper.php) | 19, 22, 35, 59, 77, 105, 108, 131, 134 | Queries `Inventory::where('variant_id', ...)` in multiple methods |

### DTOs

| File | Lines | Usage |
|------|-------|-------|
| [PurchaseOrderDTO.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/DTOs/PurchaseOrderDTO.php) | 89-90 | Validates `variant_id` as required |
| [GoodsReceiptDTO.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/DTOs/GoodsReceiptDTO.php) | 89-90 | Validates `variant_id` as required |
| [GoodsReceiptLineItemDTO.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/DTOs/GoodsReceiptLineItemDTO.php) | 30, 46, 63 | Uses `variantId` property + validation |

### Listeners

| File | Lines | Usage |
|------|-------|-------|
| [GoodsReceiptCompletedListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/Listeners/GoodsReceiptCompletedListener.php) | 30 | Passes `variant_id` from item |
| [FulfillBackOrdersListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/Listeners/FulfillBackOrdersListener.php) | 30, 35, 42, 58 | Checks/uses `variant_id` for back order fulfillment |

### Traits

| File | Lines | Usage |
|------|-------|-------|
| [TracksInventoryReservation.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/Traits/TracksInventoryReservation.php) | 76 | `whereHas('inventory', fn($q) => $q->where('variant_id', ...))` |

### Services

| File | Lines | Usage |
|------|-------|-------|
| [GoodsReceiptService.php](file:///Users/net/Desktop/websites/building/app/Domains/Supply/SubDomains/GoodsReceipts/Services/GoodsReceiptService.php) | 132 | `Catalog\Products\Models\Product::find($item->temporary_product_id)` |

---

## 2. Catalog Domain — Internal References

### Inventory Models (still have `variant()` relationship)

| File | Line | Reference |
|------|------|-----------|
| [Inventory.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Models/Inventory.php) | 35 | `belongsTo(ProductVariant::class, 'variant_id')` |
| [InventoryTransaction.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Models/InventoryTransaction.php) | 41 | `belongsTo(ProductVariant::class, 'variant_id')` |
| [InventoryBatch.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Models/InventoryBatch.php) | 37 | `belongsTo(ProductVariant::class, 'variant_id')` |
| [InventorySerial.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Models/InventorySerial.php) | 35 | `belongsTo(ProductVariant::class, 'variant_id')` |
| [InventoryCost.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Models/InventoryCost.php) | 38 | `belongsTo(ProductVariant::class, 'variant_id')` |

### Inventory Listeners

| File | Lines | Usage |
|------|-------|-------|
| [CreateInventoryReservationListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Listeners/CreateInventoryReservationListener.php) | 33 | `variant_id` in event data |
| [NotifySupplyDomainListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Listeners/NotifySupplyDomainListener.php) | 29 | `variant_id` in notification data |
| [InitializeInventoryForVariantListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Listeners/InitializeInventoryForVariantListener.php) | 32, 42 | Creates inventory with `variant_id` |

### Inventory Requests

| File | Line | Usage |
|------|------|-------|
| [StoreInventoryRequest.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Requests/StoreInventoryRequest.php) | 25 | `'product_variant_id' => 'required|exists:catalog_product_variants,id'` |
| [UpdateInventoryRequest.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Inventory/Requests/UpdateInventoryRequest.php) | 24 | `'product_variant_id' => 'nullable|exists:catalog_product_variants,id'` |

### Allocation Domain (entire subsystem)

| File | Lines | Usage |
|------|-------|-------|
| [AllocationPolicyListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Allocation/Listeners/AllocationPolicyListener.php) | 33, 37, 42, 47, 66, 74, 82 | Heavy `variant_id` usage for allocation logic |
| [ReservationTrackerListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Allocation/Listeners/ReservationTrackerListener.php) | 50, 55, 64, 73 | Queries inventory by `variant_id` |
| [BackOrderListener.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Allocation/Listeners/BackOrderListener.php) | 44, 48, 67, 82, 90 | Back order processing by `variant_id` |
| [AllocationRequestDTO.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Allocation/DTOs/AllocationRequestDTO.php) | 32, 49, 67 | `variantId` property |
| [AllocationResultDTO.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Allocation/DTOs/AllocationResultDTO.php) | 34, 52 | `variantId` property |
| [BackOrderDTO.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Allocation/DTOs/BackOrderDTO.php) | 34, 52, 71 | `variantId` property |

### Pricing Domain

| File | Usage |
|------|-------|
| [ClientProductPricingService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Services/ClientProductPricingService.php) | `use Catalog\Products\Models\Product` |
| [SupplierProductPricingService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Services/SupplierProductPricingService.php) | `use Catalog\Products\Models\Product` |
| [PriceHistoryService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Services/PriceHistoryService.php) | `use Catalog\Products\Models\Product` |
| [PriceHistoryController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Controllers/PriceHistoryController.php) | `use Catalog\Products\Models\Product` |
| [ClientPricingController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Controllers/ClientPricingController.php) | `use Catalog\Products\Models\Product` |
| [SupplierPricingController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Controllers/SupplierPricingController.php) | `use Catalog\Products\Models\Product` |
| [ProductPriceAudit.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Models/ProductPriceAudit.php) | `use Catalog\Products\Models\Product` |
| [ClientProductPrice.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Models/ClientProductPrice.php) | `use Catalog\Products\Models\Product` |
| [SupplierProductPrice.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Models/SupplierProductPrice.php) | `use Catalog\Products\Models\Product` |
| [StoreClientPricingRequest.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Requests/StoreClientPricingRequest.php) | `exists:catalog_products,id` |
| [UpdateClientPricingRequest.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Requests/UpdateClientPricingRequest.php) | `exists:catalog_products,id` |
| [StoreSupplierPricingRequest.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Requests/StoreSupplierPricingRequest.php) | `exists:catalog_products,id` |
| [UpdateSupplierPricingRequest.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Pricing/Requests/UpdateSupplierPricingRequest.php) | `exists:catalog_products,id` |

### Products Domain (internal — expected)

These files are within the `Catalog\Products` domain itself and would be removed/retired entirely when the old system is deprecated:

| File | Usage |
|------|-------|
| [ProductController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Controllers/ProductController.php) | CRUD for old products |
| [ProductVariantController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Controllers/ProductVariantController.php) | CRUD for variants |
| [ProductVariantGroupController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Controllers/ProductVariantGroupController.php) | CRUD for variant groups |
| [ProductAccountingController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Controllers/ProductAccountingController.php) | Product ↔ accounting mapping |
| [ProductBundleController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Controllers/ProductBundleController.php) | Product bundles |
| [ProductAliasController.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Controllers/ProductAliasController.php) | Product aliases |
| [ProductService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductService.php) | Main service (6 variant model imports) |
| [ProductVariantService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductVariantService.php) | Variant CRUD service |
| [ProductVariantGroupService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductVariantGroupService.php) | Variant group service |
| [ProductBaseService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductBaseService.php) | Base service |
| [ProductBundleService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductBundleService.php) | Bundle service |
| [ProductAliasService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductAliasService.php) | Alias service |
| [ProductAccountingService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductAccountingService.php) | Accounting mapping service |
| [ProductTreeService.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Services/ProductTreeService.php) | Tree service |
| All `Products/Events/*.php` | 6 event classes |
| All `Products/Requests/*.php` | 7 request classes |
| All `Products/Repositories/*.php` | 3 repository classes |
| All `Products/Contracts/*.php` | 2 contract interfaces |
| [Product.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Models/Product.php) | Model using `catalog_products` table |
| [ProductVariant.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Products/Models/ProductVariant.php) | Model using `catalog_product_variants` table |

### Other

| File | Usage |
|------|-------|
| [Unit.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Units/Models/Unit.php) | `hasMany(ProductVariantUnit::class)` |
| [Material.php](file:///Users/net/Desktop/websites/building/app/Domains/Catalog/Materials/Models/Material.php) | `hasMany(ProductVariantMaterial::class)` |
| [AppServiceProvider.php](file:///Users/net/Desktop/websites/building/app/Providers/AppServiceProvider.php) | `use Catalog\Products\Models\Product` |

---

## 3. Routes

| File | Usage |
|------|-------|
| [Products.php](file:///Users/net/Desktop/websites/building/routes/apis/ProductsCatalog/Products.php) | Routes for `Catalog\Products` controllers |
| [Bundles.php](file:///Users/net/Desktop/websites/building/routes/apis/ProductsCatalog/Bundles.php) | Routes for bundle controllers |

---

## 4. Migrations (existing schema references)

11 migration files define `variant_id` columns, FK constraints to `catalog_products` and `catalog_product_variants` tables. These represent the current database schema and would only be cleaned up once the old tables are fully deprecated.

---

## Recommended Next Actions

1. **High priority** — Update Supply DTOs (`PurchaseOrderDTO`, `GoodsReceiptDTO`, `GoodsReceiptLineItemDTO`) to use `sales_product_id`
2. **High priority** — Update `InventoryCheckHelper` to use `sales_product_id`
3. **High priority** — Update remaining Supply listeners (`GoodsReceiptCompletedListener`, `FulfillBackOrdersListener`)
4. **High priority** — Update `TracksInventoryReservation` trait
5. **Medium priority** — Update Catalog Allocation subsystem (3 listeners + 3 DTOs)
6. **Medium priority** — Update Catalog Inventory listeners and requests
7. **Medium priority** — Update Pricing domain to use SalesProduct
8. **Medium priority** — Add `salesProduct()` to `InventoryBatch`, `InventorySerial`, `InventoryCost`
9. **Low priority** — Retire/deprecate entire `Catalog\Products` domain (controllers, services, events, requests, repositories)
10. **Low priority** — Update route files + `AppServiceProvider`
