Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Microsoft.Integration.Shopify;

/// <summary>
/// Codeunit Shpfy GQL AcceptFFRequest (ID 30412).
/// Implements the IGraphQL interface for accepting Shopify fulfillment requests using GraphQL.
/// </summary>
codeunit 30414 "Shpfy GQL AcceptFFRequest" implements "Shpfy IGraphQL"
{
Access = Internal;

/// <summary>
/// GetGraphQL.
/// </summary>
/// <returns>Return value of type Text.</returns>
internal procedure GetGraphQL(): Text
begin
exit('{"query":"mutation { fulfillmentOrderAcceptFulfillmentRequest(id: \"gid://shopify/FulfillmentOrder/{{FulfillmentOrderId}}\") { fulfillmentOrder { id requestStatus } userErrors { field message }}}"}');
end;

/// <summary>
/// GetExpectedCost.
/// </summary>
/// <returns>Return value of type Integer.</returns>
internal procedure GetExpectedCost(): Integer
begin
exit(10);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Microsoft.Integration.Shopify;

/// <summary>
/// Codeunit Shpfy GQL AssignedFFOrders (ID 30410).
/// Implements the IGraphQL interface for retrieving assigned fulfillment orders using GraphQL.
/// </summary>
codeunit 30412 "Shpfy GQL AssignedFFOrders" implements "Shpfy IGraphQL"
{
Access = Internal;

/// <summary>
/// GetGraphQL.
/// </summary>
/// <returns>Return value of type Text.</returns>
internal procedure GetGraphQL(): Text
begin
exit('{"query":"{ assignedFulfillmentOrders(assignmentStatus: FULFILLMENT_REQUESTED, first: 25) { pageInfo { hasNextPage } edges { cursor node { id status requestStatus }}}}"}');
end;

/// <summary>
/// GetExpectedCost.
/// </summary>
/// <returns>Return value of type Integer.</returns>
internal procedure GetExpectedCost(): Integer
begin
exit(12);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ codeunit 30267 "Shpfy GQL FFOrdersFromOrder" implements "Shpfy IGraphQL"
/// <returns>Return value of type Text.</returns>
internal procedure GetGraphQL(): Text
begin
exit('{"query":"{order(id: \"gid:\/\/shopify\/Order\/{{OrderId}}\") { legacyResourceId fulfillmentOrders(first: 25) { pageInfo { hasNextPage } edges { cursor node { id updatedAt status assignedLocation {location {legacyResourceId}} order {legacyResourceId} deliveryMethod {methodType}}}}}}"}');
exit('{"query":"{order(id: \"gid:\/\/shopify\/Order\/{{OrderId}}\") { legacyResourceId fulfillmentOrders(first: 25) { pageInfo { hasNextPage } edges { cursor node { id updatedAt status requestStatus assignedLocation {location {legacyResourceId}} order {legacyResourceId} deliveryMethod {methodType}}}}}}"}');
end;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Microsoft.Integration.Shopify;

/// <summary>
/// Codeunit Shpfy GQL NextAssignedFFOrders (ID 30411).
/// Implements the IGraphQL interface for retrieving the next page of assigned fulfillment orders using GraphQL.
/// </summary>
codeunit 30413 "Shpfy GQL NextAssignedFFOrders" implements "Shpfy IGraphQL"
{
Access = Internal;

/// <summary>
/// GetGraphQL.
/// </summary>
/// <returns>Return value of type Text.</returns>
internal procedure GetGraphQL(): Text
begin
exit('{"query":"{ assignedFulfillmentOrders(assignmentStatus: FULFILLMENT_REQUESTED, first: 25, after: \"{{After}}\") { pageInfo { hasNextPage } edges { cursor node { id status requestStatus }}}}"}');
end;

/// <summary>
/// GetExpectedCost.
/// </summary>
/// <returns>Return value of type Integer.</returns>
internal procedure GetExpectedCost(): Integer
begin
exit(12);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ codeunit 30268 "Shpfy GQL NextFFOrdersFromOrd" implements "Shpfy IGraphQL"
/// <returns>Return value of type Text.</returns>
internal procedure GetGraphQL(): Text
begin
exit('{"query":"{order(id: \"gid:\/\/shopify\/Order\/{{OrderId}}\") { legacyResourceId fulfillmentOrders(first: 25, after:\"{{After}}\") { pageInfo { hasNextPage } edges { cursor node { id updatedAt status assignedLocation {location {legacyResourceId}} order {legacyResourceId} deliveryMethod {methodType}}}}}}"}');
exit('{"query":"{order(id: \"gid:\/\/shopify\/Order\/{{OrderId}}\") { legacyResourceId fulfillmentOrders(first: 25, after:\"{{After}}\") { pageInfo { hasNextPage } edges { cursor node { id updatedAt status requestStatus assignedLocation {location {legacyResourceId}} order {legacyResourceId} deliveryMethod {methodType}}}}}}"}');
end;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,19 @@ enum 30111 "Shpfy GraphQL Type" implements "Shpfy IGraphQL"
Caption = 'Get Location';
Implementation = "Shpfy IGraphQL" = "Shpfy GQL Location";
}
value(136; GetAssignedFulfillmentOrders)
{
Caption = 'Get Assigned Fulfillment Orders';
Implementation = "Shpfy IGraphQL" = "Shpfy GQL AssignedFFOrders";
}
value(137; GetNextAssignedFulfillmentOrders)
{
Caption = 'Get Next Assigned Fulfillment Orders';
Implementation = "Shpfy IGraphQL" = "Shpfy GQL NextAssignedFFOrders";
}
value(138; AcceptFulfillmentRequest)
{
Caption = 'Accept Fulfillment Request';
Implementation = "Shpfy IGraphQL" = "Shpfy GQL AcceptFFRequest";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ codeunit 30238 "Shpfy Fulfillment Orders API"
FulfillmentOrderHeader."Shopify Location Id" := JsonHelper.GetValueAsBigInteger(JNode, 'assignedLocation.location.legacyResourceId');
FulfillmentOrderHeader."Updated At" := JsonHelper.GetValueAsDateTime(JNode, 'updatedAt');
FulfillmentOrderHeader.Status := CopyStr(JsonHelper.GetValueAsText(JNode, 'status'), 1, MaxStrLen(FulfillmentOrderHeader.Status));
FulfillmentOrderHeader."Request Status" := ConvertToRequestStatus(JsonHelper.GetValueAsText(JNode, 'requestStatus'));
FulfillmentOrderHeader."Delivery Method Type" := ConvertToDeliveryMethodType(JsonHelper.GetValueAsText(JNode, 'deliveryMethod.methodType'));
if not FulfillmentOrderHeader.Insert() then
FulfillmentOrderHeader.Modify();
Expand Down Expand Up @@ -202,6 +203,76 @@ codeunit 30238 "Shpfy Fulfillment Orders API"
until not JsonHelper.GetValueAsBoolean(JResponse, 'data.order.fulfillmentOrders.pageInfo.hasNextPage');
end;

internal procedure GetAssignedFulfillmentOrders(Shop: Record "Shpfy Shop"; var FulfillmentOrderIds: Dictionary of [BigInteger, Code[20]])
var
Cursor: Text;
Parameters: Dictionary of [Text, Text];
JResponse: JsonToken;
begin
if not Shop."Fulfillment Service Activated" then
exit;

CommunicationMgt.SetShop(Shop);
GraphQLType := "Shpfy GraphQL Type"::GetAssignedFulfillmentOrders;

repeat
JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters);
if JResponse.IsObject() then
if ExtractAssignedFulfillmentOrderIds(Shop.Code, JResponse.AsObject(), FulfillmentOrderIds, Cursor) then begin
if Parameters.ContainsKey('After') then
Parameters.Set('After', Cursor)
else
Parameters.Add('After', Cursor);
GraphQLType := "Shpfy GraphQL Type"::GetNextAssignedFulfillmentOrders;
end else
break;
until not JsonHelper.GetValueAsBoolean(JResponse, 'data.assignedFulfillmentOrders.pageInfo.hasNextPage');
end;

local procedure ExtractAssignedFulfillmentOrderIds(ShopCode: Code[20]; JResponse: JsonObject; var FulfillmentOrderIds: Dictionary of [BigInteger, Code[20]]; var Cursor: Text): Boolean
var
JEdges: JsonArray;
JNode: JsonObject;
JItem: JsonToken;
Id: BigInteger;
begin
if JsonHelper.GetJsonArray(JResponse, JEdges, 'data.assignedFulfillmentOrders.edges') then begin
foreach JItem in JEdges do begin
Cursor := JsonHelper.GetValueAsText(JItem.AsObject(), 'cursor');
if JsonHelper.GetJsonObject(JItem.AsObject(), JNode, 'node') then begin
Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode, 'id'));
if not FulfillmentOrderIds.ContainsKey(Id) then
FulfillmentOrderIds.Add(Id, ShopCode);
end;
end;
exit(JEdges.Count() > 0);
end;
exit(false);
end;

internal procedure AcceptFulfillmentRequest(Shop: Record "Shpfy Shop"; var FulfillmentOrderHeader: Record "Shpfy FulFillment Order Header"): Boolean
var
Parameters: Dictionary of [Text, Text];
JResponse: JsonToken;
NewRequestStatus: Enum "Shpfy FF Request Status";
begin
CommunicationMgt.SetShop(Shop);
Parameters.Add('FulfillmentOrderId', Format(FulfillmentOrderHeader."Shopify Fulfillment Order Id"));

GraphQLType := "Shpfy GraphQL Type"::AcceptFulfillmentRequest;
JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters);

if JResponse.IsObject() then begin
NewRequestStatus := ConvertToRequestStatus(JsonHelper.GetValueAsText(JResponse, 'data.fulfillmentOrderAcceptFulfillmentRequest.fulfillmentOrder.requestStatus'));
if NewRequestStatus = Enum::"Shpfy FF Request Status"::ACCEPTED then begin
FulfillmentOrderHeader."Request Status" := NewRequestStatus;
FulfillmentOrderHeader.Modify();
exit(true);
end;
end;
exit(false);
end;

local procedure ConvertToDeliveryMethodType(Value: Text): Enum "Shpfy Delivery Method Type"
begin
Value := CommunicationMgt.ConvertToCleanOptionValue(Value);
Expand All @@ -210,4 +281,13 @@ codeunit 30238 "Shpfy Fulfillment Orders API"
else
exit(Enum::"Shpfy Delivery Method Type"::" ");
end;

local procedure ConvertToRequestStatus(Value: Text): Enum "Shpfy FF Request Status"
begin
Value := CommunicationMgt.ConvertToCleanOptionValue(Value);
if Enum::"Shpfy FF Request Status".Names().Contains(Value) then
exit(Enum::"Shpfy FF Request Status".FromInteger(Enum::"Shpfy FF Request Status".Ordinals().Get(Enum::"Shpfy FF Request Status".Names().IndexOf(Value))))
else
exit(Enum::"Shpfy FF Request Status"::" ");
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Microsoft.Integration.Shopify;

/// <summary>
/// Enum Shpfy FF Request Status (ID 30178).
/// </summary>
enum 30178 "Shpfy FF Request Status"
{
Access = Public;
Caption = 'Shopify Fulfillment Request Status';

value(0; " ")
{
Caption = ' ';
}
value(1; Accepted)
{
Caption = 'Accepted';
}
value(2; "Cancellation Accepted")
{
Caption = 'Cancellation Accepted';
}
value(3; "Cancellation Rejected")
{
Caption = 'Cancellation Rejected';
}
value(4; "Cancellation Requested")
{
Caption = 'Cancellation Requested';
}
value(5; Closed)
{
Caption = 'Closed';
}
value(6; Rejected)
{
Caption = 'Rejected';
}
value(7; Submitted)
{
Caption = 'Submitted';
}
value(8; Unsubmitted)
{
Caption = 'Unsubmitted';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ table 30143 "Shpfy FulFillment Order Header"
DataClassification = SystemMetadata;
Editable = false;
}
field(10; "Request Status"; Enum "Shpfy FF Request Status")
{
Caption = 'Request Status';
DataClassification = SystemMetadata;
Editable = false;
}
}
keys
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ permissionset 30104 "Shpfy - Objects"
codeunit "Shpfy Fulfillment API" = X,
codeunit "Shpfy Fulfillment Orders API" = X,
codeunit "Shpfy Gift Cards" = X,
codeunit "Shpfy GQL AcceptFFRequest" = X,
codeunit "Shpfy GQL AddProductImage" = X,
codeunit "Shpfy GQL AllCustomerIds" = X,
codeunit "Shpfy GQL ApiKey" = X,
codeunit "Shpfy GQL AssignedFFOrders" = X,
codeunit "Shpfy GQL BulkOperation" = X,
codeunit "Shpfy GQL BulkOperations" = X,
codeunit "Shpfy GQL BulkOpMutation" = X,
Expand Down Expand Up @@ -209,6 +211,7 @@ permissionset 30104 "Shpfy - Objects"
codeunit "Shpfy GQL Modify Inventory" = X,
codeunit "Shpfy GQL Next Locations" = X,
codeunit "Shpfy GQL NextAllCustomerIds" = X,
codeunit "Shpfy GQL NextAssignedFFOrders" = X,
codeunit "Shpfy GQL NextCatalogMarkets" = X,
codeunit "Shpfy GQL NextCatalogPrices" = X,
codeunit "Shpfy GQL NextCatalogProducts" = X,
Expand Down
Loading
Loading