Supplier Prioritization (Price/Stock) for Auto-Fill

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1 servicesAll 2065 services
Supplier Prioritization (Price/Stock) for Auto-Fill
Complex
~5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Implementing Supplier Prioritization (Price/Availability) During Auto-Population

When the same product exists with multiple suppliers, you need rules: who to order from, whose price goes into the card, whose data to consider primary. Without explicit prioritization rules, the catalog becomes chaos — prices jump, photos change with every import, no predictability for the buyer.

Priority Levels

Prioritization works on several levels simultaneously:

Level Determines Example
Content Whose name, description, photo to use Supplier A has better content
Price Which price to show the buyer Minimum among suppliers with stock
Order Who actually fulfills the order Cheapest, then backup
Availability How to count total stock Sum, or only primary supplier

Priority Configuration Model

CREATE TABLE supplier_priority_rules (
    id              BIGSERIAL PRIMARY KEY,
    name            VARCHAR(255) NOT NULL,
    scope_type      VARCHAR(20) NOT NULL,   -- 'global', 'category', 'brand', 'product'
    scope_id        BIGINT,                  -- NULL for global
    price_strategy  VARCHAR(30) NOT NULL,    -- 'min', 'primary', 'markup'
    content_mode    VARCHAR(20) NOT NULL,    -- 'primary_first', 'best_score'
    order_mode      VARCHAR(20) NOT NULL,    -- 'cheapest', 'priority_rank', 'round_robin'
    stock_mode      VARCHAR(20) NOT NULL,    -- 'sum', 'primary_only', 'max'
    is_active       BOOLEAN DEFAULT TRUE,
    priority        INT DEFAULT 0            -- rule priority (higher = more important)
);

-- Supplier ranks within rule context
CREATE TABLE supplier_rule_ranks (
    rule_id         BIGINT REFERENCES supplier_priority_rules(id),
    supplier_id     INT REFERENCES suppliers(id),
    rank            SMALLINT NOT NULL,       -- 1 = highest priority
    markup_pct      NUMERIC(5,2) DEFAULT 0, -- markup on supplier price
    is_content_src  BOOLEAN DEFAULT FALSE,   -- content source
    PRIMARY KEY (rule_id, supplier_id)
);

Pricing Strategies

enum PriceStrategy: string
{
    case Min       = 'min';       // Minimum price among suppliers with stock
    case Primary   = 'primary';   // Primary supplier price
    case Markup    = 'markup';    // Base price + markup from rule
}

class PriceResolver
{
    public function resolve(Product $product, PriorityRule $rule): ?float
    {
        $offers = $product->offers()
            ->where('stock', '>', 0)
            ->with('supplier')
            ->get();

        return match ($rule->price_strategy) {
            PriceStrategy::Min->value => $this->resolveMin($offers, $rule),
            PriceStrategy::Primary->value => $this->resolvePrimary($offers, $rule),
            PriceStrategy::Markup->value => $this->resolveWithMarkup($offers, $rule),
        };
    }

    private function resolveMin(Collection $offers, PriorityRule $rule): ?float
    {
        // Account for each supplier's markup when calculating minimum
        return $offers->map(function ($offer) use ($rule) {
            $rank = $rule->ranks->firstWhere('supplier_id', $offer->supplier_id);
            $markup = $rank?->markup_pct ?? 0;
            return $offer->price * (1 + $markup / 100);
        })->min();
    }

    private function resolvePrimary(Collection $offers, PriorityRule $rule): ?float
    {
        // Primary supplier — first by rank with stock
        $rankedOffers = $offers->sortBy(function ($offer) use ($rule) {
            $rank = $rule->ranks->firstWhere('supplier_id', $offer->supplier_id);
            return $rank?->rank ?? PHP_INT_MAX;
        });

        $primaryOffer = $rankedOffers->first();
        if (!$primaryOffer) return null;

        $rank = $rule->ranks->firstWhere('supplier_id', $primaryOffer->supplier_id);
        return $primaryOffer->price * (1 + ($rank?->markup_pct ?? 0) / 100);
    }
}

Content Source Selection Strategies

class ContentSourceResolver
{
    public function resolveContentSupplier(Product $product, PriorityRule $rule): ?int
    {
        return match ($rule->content_mode) {
            'primary_first' => $this->primaryFirst($product, $rule),
            'best_score'    => $this->bestScore($product, $rule),
            default         => null,
        };
    }

    private function primaryFirst(Product $product, PriorityRule $rule): ?int
    {
        // Take supplier with is_content_src = true, if they have an offer
        $contentSupplierIds = $rule->ranks
            ->where('is_content_src', true)
            ->sortBy('rank')
            ->pluck('supplier_id');

        foreach ($contentSupplierIds as $supplierId) {
            if ($product->offers->firstWhere('supplier_id', $supplierId)) {
                return $supplierId;
            }
        }

        // Fallback: first by rank with stock
        return $product->offers
            ->sortBy(fn($o) => $rule->ranks->firstWhere('supplier_id', $o->supplier_id)?->rank ?? 999)
            ->first()?->supplier_id;
    }

    private function bestScore(Product $product, PriorityRule $rule): ?int
    {
        // Score supplier content completeness
        return $product->offers->sortByDesc(function ($offer) {
            $sp = SupplierProduct::where([
                'supplier_id' => $offer->supplier_id,
                'external_id' => $offer->supplier_sku,
            ])->first();

            if (!$sp) return 0;

            $score = 0;
            if (!empty($sp->attributes['description'])) $score += 30;
            if (!empty($sp->attributes['images']))      $score += 25;
            if (!empty($sp->attributes['brand']))       $score += 15;
            if (mb_strlen($sp->name) > 50)              $score += 10;
            if (!empty($sp->attributes['specs']))       $score += 20;

            return $score;
        })->first()?->supplier_id;
    }
}

Applying Rules

class ProductSyncService
{
    public function syncProduct(Product $product): void
    {
        $rule = $this->ruleResolver->findApplicableRule($product);

        if (!$rule) return;

        // Price
        $newPrice = $this->priceResolver->resolve($product, $rule);

        // Availability
        $newStock = match ($rule->stock_mode) {
            'sum'          => $product->offers->sum('stock'),
            'primary_only' => $this->getPrimaryOffer($product, $rule)?->stock ?? 0,
            'max'          => $product->offers->max('stock'),
        };

        // Content
        $contentSupplierId = $this->contentResolver->resolveContentSupplier($product, $rule);

        $product->update([
            'price'             => $newPrice,
            'stock'             => $newStock,
            'content_supplier'  => $contentSupplierId,
        ]);

        if ($contentSupplierId) {
            $this->applySupplierContent($product, $contentSupplierId);
        }
    }
}

Conflict Resolution at Equal Prices

When multiple suppliers offer the same price, preference order:

  1. Supplier with shortest delivery time (lead_time_days)
  2. Supplier with larger stock
  3. Supplier with highest reliability rating (percentage of successful orders)
  4. Rank in supplier_rule_ranks table

Rule Management Interface

In the admin panel, rules must be configurable without deployment:

  • Select scope (globally, by category, by brand)
  • Drag-and-drop supplier ranking
  • Strategy toggles (min/primary/markup)
  • Markup field for each supplier
  • Test rule on specific product

Timeline

  • Data schema + models: 1 day
  • PriceResolver + ContentSourceResolver: 1–2 days
  • ProductSyncService + Observer triggers: 1 day
  • Rule management interface in admin: 2 days
  • Tests + operator documentation: 1 day

Total: 6–7 business days.