Adding a supplier (developers)

A supplier is a small PHP class that returns one page of products in a common format. Register it with the bwse_suppliers filter, for example from a small custom plugin, and it appears under Settings → Supplier.

The contract

add_filter('bwse_suppliers', function ($suppliers) {
    $suppliers['acme'] = new My_Acme_Supplier();
    return $suppliers;
});

class My_Acme_Supplier extends BWSE\JsonApiSupplier {
    public function id(): string { return 'acme'; }          // must match the array key
    public function label(): string { return 'Acme Wholesale'; } // optional display name
    public function fetch(string $cursor = ''): array {
        $data = $this->get('https://api.acme.example/products?page=' . max(1, (int) $cursor), ACME_API_TOKEN);
        return [
            'products' => array_map(fn($p) => [
                'id' => 'acme-' . $p['id'],
                'sku' => $p['sku'],
                'name' => $p['title'],
                'cost' => $p['price'],
                'stock' => $p['qty'],
                'currency' => 'USD',
                'category' => $p['category'],              // "Parent > Child" allowed
                'description' => $p['html'] ?? '',         // optional
                'brand' => $p['brand'] ?? null,            // optional
                'attributes' => ['Material' => $p['material'] ?? ''], // optional facts for the AI
                'images' => $p['images'] ?? [],            // optional, up to 4 used
            ], $data['items']),
            'next_cursor' => $data['has_more'] ? (string) ((int) $cursor + 1) : '', // '' = last page
        ];
    }
}

Rules

  • Return at most 100 products per page and a string next_cursor; an empty string ends the scan. Returning the same cursor twice stops the run.
  • id must be stable: it identifies the product across syncs.
  • Leave a field out when the supplier does not provide it; validation then blocks the product instead of guessing.
  • BWSE\JsonApiSupplier::get($url, $token) requires HTTPS, sends a Bearer token if given, refuses redirects and private network addresses, and limits responses to 2 MB. Implement BWSE\Supplier directly for other formats (CSV, XML).
  • Keep credentials in wp-config.php constants or environment variables, never in a distributed plugin.

Other filters

  • bwse_run_seconds (default 20) and bwse_content_seconds (default 25): time budget per run.
  • bwse_delist_min (default 10): minimum number of missing products before the outage safety hold applies.
  • bwse_ai_provider: supply your own BWSE\AiProvider implementation.

Was this article helpful to you?

Novice

Ostani obveščen

Prejmi obvestila o novih vstavitvah, posodobitvah in ekskluzivnih učbenikih.

Nikakršnega spama. Odjavi se kadarkoli.