30 lines
1.2 KiB
PHP
30 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
function shopify_load_order_by_gid(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;
|
|
}
|