Created
December 14, 2023 20:55
-
-
Save kaioken/26909e65b647a81ab17a71083fa4b2e8 to your computer and use it in GitHub Desktop.
Update a shopify Order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
require 'vendor/autoload.php'; | |
// Set up your Shopify credentials | |
$config = [ | |
'ShopUrl' => '{store}.myshopify.com', | |
'ApiKey' => '', | |
'Password' => '', | |
'AccessToken' => '', | |
]; | |
$shopify = new PHPShopify\ShopifySDK($config); | |
// Get the order ID you want to update | |
$orderId = 0; // Replace with the actual order ID | |
$tempOrder = $shopify->GraphQL->post('mutation beginEdit{ | |
orderEditBegin(id: "gid://shopify/Order/' . $orderId . '"){ | |
calculatedOrder{ | |
id | |
} | |
} | |
} | |
'); | |
$calculatedOrderId = $tempOrder['data']['orderEditBegin']['calculatedOrder']['id']; | |
$variantId = 0; | |
$quantity = 1; | |
$modifyOrder = $shopify->GraphQL->post('mutation addVariantToOrder{ | |
orderEditAddVariant(id: "' . $calculatedOrderId . '", variantId: "gid://shopify/ProductVariant/' . $variantId . '", quantity: ' . $quantity . '){ | |
calculatedOrder { | |
id | |
addedLineItems(first:5) { | |
edges { | |
node { | |
id | |
quantity | |
} | |
} | |
} | |
} | |
userErrors { | |
field | |
message | |
} | |
} | |
}'); | |
$lineItem = $modifyOrder['data']['orderEditAddVariant']['calculatedOrder']['addedLineItems']['edges'][0]['node']['id']; | |
$discountLineItem = $shopify->GraphQL->post('mutation addDiscount { | |
orderEditAddLineItemDiscount(id: "' . $calculatedOrderId . '", lineItemId: "' . $lineItem . '", discount: {percentValue: 100, description: "Product offer at checkout"}) { | |
calculatedOrder { | |
id | |
addedLineItems(first:5) { | |
edges { | |
node { | |
id | |
quantity | |
} | |
} | |
} | |
} | |
userErrors { | |
message | |
} | |
} | |
}'); | |
$editComment = 'I edited the order! It was me!'; | |
$commitOrder = $shopify->GraphQL->post('mutation commitEdit { | |
orderEditCommit(id: "' . $calculatedOrderId . '", notifyCustomer: false, staffNote: "' . $editComment . '") { | |
order { | |
id | |
} | |
userErrors { | |
field | |
message | |
} | |
} | |
}'); | |
print_r($tempOrder); | |
print_r($modifyOrder); | |
print_r($commitOrder); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment