I have been using custom app to create draft order with custom pricing and custom checkout link which is custom invoice, I’m Using Graphql api draft order mutation with line item predefine value priceover ride but its giving error to response which says this error line item priceoverride field not defind.
Can any one help us to define Priceoverride of actual product variant to put custom pricing calculation. It would be very helpful
Hey @Anil_Kumar,
Can you share an example of the draft order mutation you are making that is returning the error?
Hello,
Thanks for the reply here’s below the PHP code I have been using for this.
public function createDraftOrder(Request $request)
{
$cartData = $request->input('cart_data');
$orderInput = [];
$lineItems = [];
foreach ($cartData as $item) {
$lineItem = [];
$linePrice = [];
$customAttributes = [];
$customAttribute = [];
//$lineItem['title'] = $item['title'];
$lineItem['variantId'] = 'gid://shopify/ProductVariant/' . $item['variant_id'];
$lineItem['quantity'] = (int)$item['quantity'];
$lineItem['generatePriceOverride'] = true;
//$formattedSelectionPrice = number_format($item['selectionPrice'] / 100, 2);
$formattedOriginalPrice = number_format($item['originalUnitPrice'] / 100, 2);
if($item['selectionPrice'] == 0)
{
$linePrices = ['amount' => $formattedOriginalPrice, 'currencyCode' => $item['shopCurrency']];
}
else
{
$linePrices = ['amount' => $item['selectionPrice'], 'currencyCode' => $item['shopCurrency']];
}
//$lineItem['originalUnitPriceWithCurrency'] = $linePrices;
$lineItem['priceOverride'] = $linePrices;
//priceOverride
$properties = $item['properties'];
$customAttributes = collect($properties[0])->map(function ($value, $key) {
return ["key" => $key, "value" => $value];
})->values()->toArray();
$lineItem['customAttributes'] = $customAttributes;
$lineItem['requiresShipping'] = true;
$lineItems[] = $lineItem;
}
$orderInput['lineItems'] = $lineItems;
// $orderInput['allowDiscountCodesInCheckout'] = true;
$query = <<<GQL
mutation draftOrderCreate(\$input: DraftOrderInput!) {
draftOrderCreate(input: \$input) {
draftOrder {
id
name
invoiceUrl
status
}
userErrors {
field
message
}
}
}
GQL;
$variables = [
'input' => $orderInput
];
$response = $this->shopifyService->query($query,$variables);
return $response;
$convert_array_obj = (array)$response;
$checkout_url = $convert_array_obj['data']['draftOrderCreate']['draftOrder']['invoiceUrl'];
return response()->json(['success' => true,'checkout_url' => $checkout_url]);
}
error message: {
“error”: “Invalid response from Shopify API: {"errors":[{"message":"Variable $input of type DraftOrderInput! was provided invalid value for lineItems.0.generatePriceOverride (Field is not defined on DraftOrderLineItemInput), lineItems.0.priceOverride (Field is not defined on DraftOrderLineItemInput)","locations":[{"line":1,"column":27}],"extensions":{"value":{"lineItems":[{"title":"Plan Printing - A1 / 190gsm Satin photographic / Black & White","quantity":1,"generatePriceOverride":true,"priceOverride":{"amount":"36","currencyCode":"GBP"},"customAttributes":[{"key":"Upload File To Be Printed 1","value":"https://cdn.shopify.com/s/files/1/0916/7139/6616/uploads/23a688ef9339b098f577d261b00dab2f.pdf"},{"key":"Upload Print cost","value":"\u00a336.00"},{"key":"Shipping method","value":"Folded"},{"key":"Shipping charge","value":"\u00a35.00"}],"requiresShipping":true}]},"problems":[{"path":["lineItems",0,"generatePriceOverride"],"explanation":"Field is not defined on DraftOrderLineItemInput"},{"path":["lineItems",0,"priceOverride"],"explanation":"Field is not defined on DraftOrderLineItemInput"}]}}]}”
}
Thanks for sharing that example!
Looking at your code, the mutation looks correct. What I’m not seeing is any version specified. Currently when a version isn’t declared, we will serve the oldest supported version (2024-07 now) but the price override isn’t available until 2025-01 and higher.
I suspect that this is the issue. Can you test with a recent version to see if that resolves it?
Hello,
Thanks for the reply can you please share any example of code where I have to declare the version for this. I hope you can help.
Thanks.
Hello, @KyleG-Shopify
Thanks for your Support my priceoverride issue have been fixed.
Thanks for your guidance again.