Skip to content

Shopify Commerce: Extension and action examples

Use the action functions with records and Data objects supplied by your application. They pass each argument to the package operation and return its result.

These adapters show container registration. Use the owning package registry when a contract requires contributor discovery.

Contract adapters wrap an existing implementation. Call their registration function from your service provider with that implementation; tagged contracts keep their declared tag. Resolve the backend by its concrete class before registration so the replacement contract does not resolve itself. Static contract metadata uses one backend class per adapter.

<?php
declare(strict_types=1);
namespace App\CapellExamples\ShopifyCommerce;
function runIngestShopifyWebhook(\Capell\ShopifyCommerce\Models\ShopifyConnection $connection, string $topic, array $payload, ?\Carbon\CarbonImmutable $triggeredAt = null, ?int $generation = null): void
{
\Capell\ShopifyCommerce\Actions\Webhooks\IngestShopifyWebhookAction::run($connection, $topic, $payload, $triggeredAt, $generation);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\ShopifyCommerce;
function runInstall(\Capell\Core\Data\PackageData $package, array $arguments = [], ?\Capell\Core\Contracts\ProgressReporter $reporter = null): void
{
\Capell\ShopifyCommerce\Actions\InstallShopifyCommercePackageAction::run($package, $arguments, $reporter);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\ShopifyCommerce;
function runPersistShopifyProduct(\Capell\ShopifyCommerce\Models\ShopifyConnection $connection, \Capell\ShopifyCommerce\Data\ShopifyProductData $product, \Carbon\CarbonInterface $syncedAt, bool $allowStaleCurrency = false, bool $currencyUnknown = false, bool $requireVerifiedCurrency = false): ?\Capell\ShopifyCommerce\Models\ShopifyProduct
{
return \Capell\ShopifyCommerce\Actions\Catalog\PersistShopifyProductAction::run($connection, $product, $syncedAt, $allowStaleCurrency, $currencyUnknown, $requireVerifiedCurrency);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\ShopifyCommerce;
function runPruneExpiredShopifyOAuthStates(): int
{
return \Capell\ShopifyCommerce\Actions\OAuth\PruneExpiredShopifyOAuthStatesAction::run();
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\ShopifyCommerce;
function runSyncShopifyCustomers(\Capell\ShopifyCommerce\Models\ShopifyConnection|int $connection): int
{
return \Capell\ShopifyCommerce\Actions\Customers\SyncShopifyCustomersAction::run($connection);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\ShopifyCommerce;
function runUpsertShopifyCustomer(\Capell\ShopifyCommerce\Models\ShopifyConnection $connection, array $snapshot): \Capell\ShopifyCommerce\Models\ShopifyCustomer
{
return \Capell\ShopifyCommerce\Actions\Customers\UpsertShopifyCustomerAction::run($connection, $snapshot);
}

ShopifyConnection::installation_generation advances on every OAuth install/reinstall and immediately on shop redaction. Pass the originating generation as the second argument to queued SyncShopifyProductsAction deliveries and as the third argument to queued ContinueShopifyProductBulkSyncAction deliveries (after the operation ID). Do not refresh an already-loaded connection before passing it to a write Action: its original generation is the fence. Stored webhook events carry their own generation even when their connection relation loads a later installation. Jobs from older code without a generation are logged and dropped. Matching legacy running bulk operations are retired only in installation zero when the operation has no generation; their dispatch receipts are cleared so a fresh sync can start.

Generation checks and writes share the connection row lock. Bulk work retains that lock through import and completion, so reconnect or shop redaction cannot interleave with persisted rows or pruning. Customer identity redaction markers survive shop redaction and reconnect. Reconnect clears redacted_at, bulk state and currency verification without restoring erased payloads.

Authenticated webhook triggers and derived erasure

Section titled “Authenticated webhook triggers and derived erasure”

Product/customer create and update webhooks supply object IDs only. Fetch with the destination connection credentials before persisting; the app HMAC and delivery headers do not establish shop provenance. Deletion requires an authenticated absence confirmation. Ordering, generation and digest guards remain necessary for replay handling.

ShopifyCustomerSynced carries scalar connectionId, customerId, customerGid and installationGeneration. Call withCurrentCustomer($consumer) to resolve the current customer and hold the redaction and generation fence through your write. Do not cache personal snapshots in queued events. Pre-upgrade events without a generation are rejected.

Listen synchronously to ShopifyCustomerRedacted and ShopifyShopRedacted after the producer has persisted its erasure fence. Derived erasure runs outside the connection lock. Contacts removes Shopify-derived fields, profile, provenance and activity while preserving other sources; only a Contact the installation provably created, holding nothing else, is fully anonymised. A legacy Contact without proof keeps its unproven details and gets a shopify_erasure_review activity (see upgrade notes). ShopifyCustomerDataRequested carries scalar connection/customer/request identifiers, with no model or token in its queued representation. Contacts consumes both; Shopify Commerce has no dependency on Contacts internals. Customer/shop erasure clears connection diagnostics as well as identity-linked payloads; the upgrade migration clears historical unstructured diagnostic text.

ShopifyShopRedacted::installationGeneration scopes derived erasure to the recorded installation. Consumers must preserve newer installation copies. ShopifyIdentityRehashRequested allows optional identity stores to rehash synchronously without a dependency from Shopify Commerce; honour its dry-run, after-ID and limit, and return the last scanned ID in checkpoints. See upgrade notes for key retention and resume rules.