Process Shopify webhooks asynchronously
This commit is contained in:
@@ -5,6 +5,7 @@ require_once __DIR__ . '/../../../modules/shared/db.php';
|
||||
require_once __DIR__ . '/../../../modules/shared/webhook_throttle.php';
|
||||
require_once __DIR__ . '/shopify-api.php';
|
||||
require_once __DIR__ . '/service.php';
|
||||
require_once __DIR__ . '/shopify-source.php';
|
||||
require_once __DIR__ . '/../bestellungen/shopify-projection.php';
|
||||
|
||||
function shopify_delta_argument(string $name, array $argv, ?string $default = null): ?string
|
||||
@@ -74,33 +75,6 @@ GQL;
|
||||
return $orders;
|
||||
}
|
||||
|
||||
function shopify_delta_load_order(array $env, string $orderGid): array
|
||||
{
|
||||
$query = <<<'GQL'
|
||||
query ($id: ID!) {
|
||||
order(id: $id) {
|
||||
id name createdAt updatedAt cancelledAt displayFinancialStatus displayFulfillmentStatus
|
||||
currentSubtotalPriceSet { shopMoney { amount currencyCode } }
|
||||
totalShippingPriceSet { shopMoney { amount currencyCode } }
|
||||
totalTaxSet { shopMoney { amount currencyCode } }
|
||||
totalPriceSet { shopMoney { amount currencyCode } }
|
||||
customer { id firstName lastName email phone }
|
||||
billingAddress { firstName lastName company address1 address2 zip city provinceCode country countryCodeV2 phone }
|
||||
shippingAddress { firstName lastName company address1 address2 zip city provinceCode country countryCodeV2 phone }
|
||||
lineItems(first: 50) {
|
||||
nodes { id sku name quantity originalUnitPriceSet { shopMoney { amount currencyCode } } variant { id sku product { id } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
GQL;
|
||||
$data = shopify_graphql_query($env, $query, ['id' => $orderGid]);
|
||||
$order = $data['order'] ?? null;
|
||||
if (!is_array($order)) {
|
||||
throw new RuntimeException("Shopify-Bestellung nicht gefunden: {$orderGid}");
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
function run_shopify_delta(array $env, PDO $pdo, string $cutoff, bool $dryRun): array
|
||||
{
|
||||
$cutoffDate = new DateTimeImmutable($cutoff);
|
||||
@@ -132,7 +106,7 @@ function run_shopify_delta(array $env, PDO $pdo, string $cutoff, bool $dryRun):
|
||||
$result = project_shopify_order(
|
||||
$pdo,
|
||||
$orderGid,
|
||||
static fn (string $gid): array => shopify_delta_load_order($env, $gid),
|
||||
static fn (string $gid): array => shopify_load_order_by_gid($env, $gid),
|
||||
$dryRun
|
||||
);
|
||||
if (!$dryRun && ($result['status'] ?? '') === 'imported') {
|
||||
|
||||
Reference in New Issue
Block a user