Implementation of Multi-Supplier Dropshipping
Working with multiple suppliers solves two tasks: expanding assortment and backup reservation — when main supplier runs out, order goes to backup. Technically much more complex than single supplier: need to manage competing prices for one item, priorities, order routing rules, and consolidated stock.
Key Concepts
Supplier routing — logic for selecting supplier for specific order. Can consider: stock availability, price, priority, delivery region, processing speed.
Product mapping — one product in store catalog may correspond to multiple suppliers' SKUs. Need matching table.
Price aggregation — if multiple suppliers offer same product, catalog price formed based on best wholesale price.
Stock consolidation — aggregated stock across all suppliers or only primary supplier.
Data Schema
// One product → multiple suppliers
Schema::create('product_supplier_mappings', function (Blueprint $table) {
$table->id();
$table->foreignId('product_id')->constrained();
$table->foreignId('supplier_id')->constrained('dropship_suppliers');
$table->string('supplier_sku');
$table->integer('priority')->default(10); // lower = higher priority
$table->decimal('supplier_price', 10, 2)->nullable();
$table->integer('supplier_stock')->default(0);
$table->boolean('is_active')->default(true);
$table->timestamp('price_synced_at')->nullable();
$table->timestamp('stock_synced_at')->nullable();
$table->unique(['product_id', 'supplier_id']);
$table->index(['product_id', 'is_active', 'priority']);
});
Supplier Router
class SupplierRouter
{
/**
* Select optimal supplier for order item
*/
public function route(OrderItem $item, RoutingStrategy $strategy): ?ProductSupplierMapping
{
$candidates = ProductSupplierMapping::where('product_id', $item->product_id)
->where('is_active', true)
->where('supplier_stock', '>=', $item->quantity)
->with('supplier')
->orderBy('priority')
->get();
if ($candidates->isEmpty()) {
return null; // no available suppliers
}
return $strategy->select($candidates, $item);
}
}
// Strategy: minimum wholesale price
class CheapestSupplierStrategy implements RoutingStrategy
{
public function select(Collection $candidates, OrderItem $item): ProductSupplierMapping
{
return $candidates->sortBy('supplier_price')->first();
}
}
// Strategy: maximum priority (manually configured)
class PrioritySupplierStrategy implements RoutingStrategy
{
public function select(Collection $candidates, OrderItem $item): ProductSupplierMapping
{
return $candidates->sortBy('priority')->first();
}
}
// Strategy: nearest warehouse to delivery address (needs warehouse coordinates)
class NearestWarehouseStrategy implements RoutingStrategy
{
public function select(Collection $candidates, OrderItem $item): ProductSupplierMapping
{
$deliveryCoords = $this->geocode($item->order->delivery_address);
return $candidates->sortBy(function ($mapping) use ($deliveryCoords) {
$warehouse = $mapping->supplier->primaryWarehouse;
return $this->haversineDistance($deliveryCoords, $warehouse->coordinates);
})->first();
}
}
Price Aggregation
class MultiSupplierPriceAggregator
{
/**
* Calculate retail price based on best wholesale price among suppliers
*/
public function aggregate(Product $product): float
{
$bestMapping = ProductSupplierMapping::where('product_id', $product->id)
->where('is_active', true)
->where('supplier_stock', '>', 0)
->whereNotNull('supplier_price')
->orderBy('supplier_price')
->first();
if (!$bestMapping) {
// All suppliers out of stock — keep current price
return $product->price;
}
return $this->calculator->calculate(
supplierPrice: $bestMapping->supplier_price,
marginRule: $this->resolveMarginRule($product, $bestMapping->supplier),
);
}
}
Stock Consolidation
class StockConsolidator
{
public function getDisplayStock(Product $product, string $mode = 'sum'): int
{
$mappings = ProductSupplierMapping::where('product_id', $product->id)
->where('is_active', true)
->get();
return match($mode) {
// Sum all suppliers (show 999+ if > 100)
'sum' => min($mappings->sum('supplier_stock'), 9999),
// Only primary supplier
'priority' => $mappings->sortBy('priority')->first()?->supplier_stock ?? 0,
// Maximum among suppliers
'max' => $mappings->max('supplier_stock') ?? 0,
// Boolean: available at any supplier
'any' => $mappings->where('supplier_stock', '>', 0)->isNotEmpty() ? 1 : 0,
};
}
}
Order Item Distribution to Suppliers
One order with multiple items can go to different suppliers:
class OrderSplitter
{
public function split(Order $order): Collection
{
$groups = collect();
foreach ($order->items as $item) {
$mapping = $this->router->route($item, new PrioritySupplierStrategy());
if (!$mapping) {
throw new NoSupplierAvailableException($item->product);
}
$supplierId = $mapping->supplier_id;
if (!$groups->has($supplierId)) {
$groups->put($supplierId, [
'supplier' => $mapping->supplier,
'items' => collect(),
]);
}
$groups[$supplierId]['items']->push([
'item' => $item,
'supplier_sku' => $mapping->supplier_sku,
]);
}
return $groups;
}
}
Fallback When Stock Insufficient
If primary supplier cannot fulfill order completely:
public function routeWithFallback(OrderItem $item): array
{
$remaining = $item->quantity;
$allocations = [];
$mappings = ProductSupplierMapping::where('product_id', $item->product_id)
->where('is_active', true)
->where('supplier_stock', '>', 0)
->orderBy('priority')
->get();
foreach ($mappings as $mapping) {
if ($remaining <= 0) break;
$take = min($remaining, $mapping->supplier_stock);
$allocations[] = ['mapping' => $mapping, 'quantity' => $take];
$remaining -= $take;
}
if ($remaining > 0) {
throw new InsufficientMultiSupplierStockException($item, $remaining);
}
return $allocations;
}
Supplier Reporting
Admin panel displays:
- Revenue per supplier
- Average order fulfillment time
- Rejection rate (item not available after order acceptance)
- Wholesale price dynamics
Timeline
| Component | Timeline |
|---|---|
| Data schema, supplier mapping | 2 days |
| SupplierRouter + 2–3 strategies | 3 days |
| Price aggregation and stock consolidation | 2 days |
| Order split + fallback | 3 days |
| Admin reporting | 2 days |
| Testing scenarios | 3 days |
Total: 15–20 business days depending on supplier count and routing complexity.







