Skip to content
Open
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
Expand Up @@ -15,7 +15,7 @@ codeunit 30237 "Shpfy GQL NextOpenFFOrderLines" implements "Shpfy IGraphQL"
/// <returns>Return value of type Text.</returns>
internal procedure GetGraphQL(): Text
begin
exit('{"query":"{fulfillmentOrder(id: \"gid:\/\/shopify\/FulfillmentOrder\/{{FulfillmentOrderId}}\") {lineItems(first: 25, after:\"{{After}}\") {pageInfo {hasNextPage} edges {cursor node {id totalQuantity remainingQuantity lineItem {product {legacyResourceId} variant {legacyResourceId}}}}}}}"}');
exit('{"query":"{fulfillmentOrder(id: \"gid:\/\/shopify\/FulfillmentOrder\/{{FulfillmentOrderId}}\") {lineItems(first: 25, after:\"{{After}}\") {pageInfo {hasNextPage} edges {cursor node {id totalQuantity remainingQuantity lineItem {id product {legacyResourceId} variant {legacyResourceId}}}}}}}"}');
end;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ codeunit 30235 "Shpfy GQL OpenFulfillmOrdLines" implements "Shpfy IGraphQL"
/// <returns>Return value of type Text.</returns>
internal procedure GetGraphQL(): Text
begin
exit('{"query":"{fulfillmentOrder(id: \"gid:\/\/shopify\/FulfillmentOrder\/{{FulfillmentOrderId}}\") {lineItems(first: 25) {pageInfo {hasNextPage} edges {cursor node {id totalQuantity remainingQuantity lineItem {product {legacyResourceId} variant {legacyResourceId}}}}}}}"}');
exit('{"query":"{fulfillmentOrder(id: \"gid:\/\/shopify\/FulfillmentOrder\/{{FulfillmentOrderId}}\") {lineItems(first: 25) {pageInfo {hasNextPage} edges {cursor node {id totalQuantity remainingQuantity lineItem {id product {legacyResourceId} variant {legacyResourceId}}}}}}}"}');
end;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ codeunit 30238 "Shpfy Fulfillment Orders API"
FulfillmentOrderLine."Shopify Order Id" := FulfillmentOrderHeader."Shopify Order Id";
FulfillmentOrderLine."Shopify Location Id" := FulfillmentOrderHeader."Shopify Location Id";
FulfillmentOrderLine."Delivery Method Type" := FulfillmentOrderHeader."Delivery Method Type";
FulfillmentOrderLine."Line Item Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode, 'lineItem.id'));
FulfillmentOrderLine."Shopify Product Id" := JsonHelper.GetValueAsBigInteger(JNode, 'lineItem.product.legacyResourceId');
FulfillmentOrderLine."Shopify Variant Id" := JsonHelper.GetValueAsBigInteger(JNode, 'lineItem.variant.legacyResourceId');
FulfillmentOrderLine."Total Quantity" := JsonHelper.GetValueAsDecimal(JNode, 'totalQuantity');
Expand All @@ -143,6 +144,10 @@ codeunit 30238 "Shpfy Fulfillment Orders API"
Modified := true;
FulfillmentOrderLine."Shopify Location Id" := FulfillmentOrderHeader."Shopify Location Id";
end;
if FulfillmentOrderLine."Line Item Id" <> CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode, 'lineItem.id')) then begin
Modified := true;
FulfillmentOrderLine."Line Item Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode, 'lineItem.id'));
end;
if FulfillmentOrderLine."Delivery Method Type" <> FulfillmentOrderHeader."Delivery Method Type" then begin
Modified := true;
FulfillmentOrderLine."Delivery Method Type" := FulfillmentOrderHeader."Delivery Method Type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ table 30144 "Shpfy FulFillment Order Line"
{
DataClassification = CustomerContent;
}
field(12; "Line Item Id"; BigInteger)
{
Caption = 'Line Item Id';
DataClassification = SystemMetadata;
}
}
keys
{
Expand All @@ -82,5 +87,8 @@ table 30144 "Shpfy FulFillment Order Line"
key(Key3; "Shopify Order Id", "Shopify Variant Id", "Fulfillment Status")
{
}
key(Key4; "Shopify Order Id", "Line Item Id")
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,9 @@ codeunit 30161 "Shpfy Import Order"
begin
FulfillmentOrderLine.Reset();
FulfillmentOrderLine.SetRange("Shopify Order Id", OrderLine."Shopify Order Id");
FulfillmentOrderLine.SetRange("Shopify Variant Id", OrderLine."Shopify Variant Id");
FulfillmentOrderLine.SetRange("Line Item Id", OrderLine."Line Id");
FulfillmentOrderLine.SetFilter("Fulfillment Status", '<>%1', 'CLOSED');
if FulfillmentOrderLine.FindSet() then
if not FulfillmentOrderLine.IsEmpty() then
UpdateLocationIdAndDeliveryMethodOnOrderLines(OrderLine, FulfillmentOrderLine)
else begin
FulfillmentOrderLine.SetRange("Fulfillment Status");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,5 @@ permissionset 30104 "Shpfy - Objects"
page "Shpfy Tax Areas" = X,
page "Shpfy Transaction Gateways" = X,
page "Shpfy Transactions" = X,
page "Shpfy Variants" = X,
query "Shpfy Shipment Location" = X;
page "Shpfy Variants" = X;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ codeunit 30190 "Shpfy Export Shipments"
/// <param name="SalesShipmentHeader">Parameter of type Record "Sales Shipment Header".</param>
/// <param name="AssignedFulfillmentOrderIds">Parameter of type Dictionary of [BigInteger, Code[20]].</param>
internal procedure CreateShopifyFulfillment(var SalesShipmentHeader: Record "Sales Shipment Header"; var AssignedFulfillmentOrderIds: Dictionary of [BigInteger, Code[20]]);
var
ShipmentLocation: Query "Shpfy Shipment Location";
begin
if (SalesShipmentHeader."Shpfy Order Id" <> 0) and (SalesShipmentHeader."Shpfy Fulfillment Id" = 0) then begin
ShipmentLocation.SetRange(No, SalesShipmentHeader."No.");
if ShipmentLocation.Open() then
while ShipmentLocation.Read() do
CreateShopifyFulfillment(SalesShipmentHeader, ShipmentLocation.LocationId, ShipmentLocation.DeliveryMethodType, AssignedFulfillmentOrderIds);
end;
end;

local procedure CreateShopifyFulfillment(var SalesShipmentHeader: Record "Sales Shipment Header"; LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"; var AssignedFulfillmentOrderIds: Dictionary of [BigInteger, Code[20]]);
var
Shop: Record "Shpfy Shop";
ShopifyOrderHeader: Record "Shpfy Order Header";
Expand All @@ -55,37 +43,40 @@ codeunit 30190 "Shpfy Export Shipments"
FulfillmentId: BigInteger;
FulfillmentOrderRequests: List of [Text];
begin
if ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then begin
ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code");
Shop.Get(ShopifyOrderHeader."Shop Code");
FulfillmentOrderRequests := CreateFulfillmentOrderRequest(SalesShipmentHeader, Shop, LocationId, DeliveryMethodType, AssignedFulfillmentOrderIds);
if FulfillmentOrderRequests.Count <> 0 then
foreach FulfillmentOrderRequest in FulfillmentOrderRequests do begin
JResponse := ShopifyCommunicationMgt.ExecuteGraphQL(FulfillmentOrderRequest);
JFulfillment := JsonHelper.GetJsonToken(JResponse, 'data.fulfillmentCreate.fulfillment');
if (JFulfillment.IsObject) then begin
FulfillmentId := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment);
if SalesShipmentHeader."Shpfy Fulfillment Id" <> -1 then // partial fulfillment errors
SalesShipmentHeader."Shpfy Fulfillment Id" := FulfillmentId;
end else begin
SkippedRecord.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoFulfillmentCreatedInShopifyLbl, Shop);
SalesShipmentHeader."Shpfy Fulfillment Id" := -1;
end;
end
else begin
SkippedRecord.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoCorrespondingFulfillmentLinesLbl, Shop);
SalesShipmentHeader."Shpfy Fulfillment Id" := -1;
end;
SalesShipmentHeader.Modify(true);
if (SalesShipmentHeader."Shpfy Order Id" = 0) or (SalesShipmentHeader."Shpfy Fulfillment Id" <> 0) then
exit;

if not ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then
exit;

ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code");
Shop.Get(ShopifyOrderHeader."Shop Code");
FulfillmentOrderRequests := CreateFulfillmentOrderRequest(SalesShipmentHeader, Shop, AssignedFulfillmentOrderIds);
if FulfillmentOrderRequests.Count <> 0 then
foreach FulfillmentOrderRequest in FulfillmentOrderRequests do begin
JResponse := ShopifyCommunicationMgt.ExecuteGraphQL(FulfillmentOrderRequest);
JFulfillment := JsonHelper.GetJsonToken(JResponse, 'data.fulfillmentCreate.fulfillment');
if (JFulfillment.IsObject) then begin
FulfillmentId := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment);
if SalesShipmentHeader."Shpfy Fulfillment Id" <> -1 then // partial fulfillment errors
SalesShipmentHeader."Shpfy Fulfillment Id" := FulfillmentId;
end else begin
SkippedRecord.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoFulfillmentCreatedInShopifyLbl, Shop);
SalesShipmentHeader."Shpfy Fulfillment Id" := -1;
end;
end
else begin
SkippedRecord.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoCorrespondingFulfillmentLinesLbl, Shop);
SalesShipmentHeader."Shpfy Fulfillment Id" := -1;
end;
SalesShipmentHeader.Modify(true);
end;

internal procedure CreateFulfillmentOrderRequest(SalesShipmentHeader: Record "Sales Shipment Header"; Shop: Record "Shpfy Shop"; LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"; var AssignedFulfillmentOrderIds: Dictionary of [BigInteger, Code[20]]) Requests: List of [Text];
internal procedure CreateFulfillmentOrderRequest(SalesShipmentHeader: Record "Sales Shipment Header"; Shop: Record "Shpfy Shop"; var AssignedFulfillmentOrderIds: Dictionary of [BigInteger, Code[20]]) Requests: List of [Text];
var
SalesShipmentLine: Record "Sales Shipment Line";
ShippingAgent: Record "Shipping Agent";
FulfillmentOrderLine: Record "Shpfy FulFillment Order Line";
OrderLine: Record "Shpfy Order Line";
TempFulfillmentOrderLine: Record "Shpfy FulFillment Order Line" temporary;
TrackingCompany: Enum "Shpfy Tracking Companies";
PrevFulfillmentOrderId: BigInteger;
Expand All @@ -107,30 +98,14 @@ codeunit 30190 "Shpfy Export Shipments"
SalesShipmentLine.SetFilter(Quantity, '>%1', 0);
if SalesShipmentLine.FindSet() then begin
repeat
if OrderLine.Get(SalesShipmentHeader."Shpfy Order Id", SalesShipmentLine."Shpfy Order Line Id") then
if (OrderLine."Location Id" = LocationId) and (OrderLine."Delivery Method Type" = DeliveryMethodType) then
if FindFulfillmentOrderLine(SalesShipmentHeader, SalesShipmentLine, FulfillmentOrderLine) then begin
FulfillmentOrderLine."Quantity to Fulfill" += Round(SalesShipmentLine.Quantity, 1, '=');
FulfillmentOrderLine."Remaining Quantity" := FulfillmentOrderLine."Remaining Quantity" - Round(SalesShipmentLine.Quantity, 1, '=');
FulfillmentOrderLine.Modify();

if TempFulfillmentOrderLine.Get(FulfillmentOrderLine."Shopify Fulfillment Order Id", FulfillmentOrderLine."Shopify Fulfillm. Ord. Line Id") then begin
TempFulfillmentOrderLine."Quantity to Fulfill" += Round(SalesShipmentLine.Quantity, 1, '=');
TempFulfillmentOrderLine.Modify();
end else begin
TempFulfillmentOrderLine := FulfillmentOrderLine;
TempFulfillmentOrderLine."Quantity to Fulfill" := Round(SalesShipmentLine.Quantity, 1, '=');
TempFulfillmentOrderLine.Insert();
end;
// Accept pending fulfillment request before creating fulfillment
AcceptPendingFulfillmentRequests(Shop, FulfillmentOrderLine."Shopify Fulfillment Order Id", AssignedFulfillmentOrderIds);
end;
FindFulfillmentOrderLines(SalesShipmentHeader, SalesShipmentLine, Shop, FulfillmentOrderLine, TempFulfillmentOrderLine, AssignedFulfillmentOrderIds);
until SalesShipmentLine.Next() = 0;

TempFulfillmentOrderLine.Reset();
TempFulfillmentOrderLine.SetCurrentKey("Shopify Fulfillment Order Id");
if TempFulfillmentOrderLine.FindSet() then begin
GraphQuery.Append('{"query": "mutation {fulfillmentCreate( fulfillment: {');
if GetNotifyCustomer(Shop, SalesShipmentHeader, LocationId) then
if GetNotifyCustomer(Shop, SalesShipmentHeader, TempFulfillmentOrderLine."Shopify Location Id") then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i read this right, connector populates TempFulfillmentOrderLine with all fulfilment lines that can be send to Shopify.
The next step - it iterates via lines and if line has different Fulfillment Order Id it will create new node with fulfillmentOrderId with fulfillmentOrderLineItems array.
As there is no sorting in the TempFulfillmentOrderLine there is a possibility that there will be multiple nodes with same fulfillmentOrderId but different content in fulfillmentOrderLineItems . Any risk that Shopify won't accept mutation that contains same fulfillmentOrderId ?

Scenario:
Order with Items:
A
B
C

Fulfillment Order1 with items A and C
Fulfillment Order2 with item B

Posted shipment with lines
A
B
C

So now connector will create mutation:
mutation {fulfillmentCreate( fulfillment:
..
{
fulfillmentOrderId = Fulfillment Order1 {fulfillmentOrderLineItems [A],
fulfillmentOrderId = Fulfillment Order2 {fulfillmentOrderLineItems [B],
fulfillmentOrderId = Fulfillment Order1 {fulfillmentOrderLineItems [C],
}

GraphQuery.Append('notifyCustomer: true, ')
else
GraphQuery.Append('notifyCustomer: false, ');
Expand Down Expand Up @@ -217,21 +192,46 @@ codeunit 30190 "Shpfy Export Shipments"
end;
end;

local procedure FindFulfillmentOrderLine(SalesShipmentHeader: Record "Sales Shipment Header"; SalesShipmentLine: Record "Sales Shipment Line"; var FulfillmentOrderLine: Record "Shpfy FulFillment Order Line"): Boolean
local procedure FindFulfillmentOrderLines(SalesShipmentHeader: Record "Sales Shipment Header"; SalesShipmentLine: Record "Sales Shipment Line"; Shop: Record "Shpfy Shop"; var FulfillmentOrderLine: Record "Shpfy FulFillment Order Line"; var TempFulfillmentOrderLine: Record "Shpfy FulFillment Order Line" temporary; var AssignedFulfillmentOrderIds: Dictionary of [BigInteger, Code[20]])
var
OrderLine: Record "Shpfy Order Line";
RemainingQtyToFulfill: Decimal;
QtyToFulfillOnLine: Decimal;
begin
if OrderLine.Get(SalesShipmentHeader."Shpfy Order Id", SalesShipmentLine."Shpfy Order Line Id") then begin
FulfillmentOrderLine.Reset();
FulfillmentOrderLine.SetRange("Shopify Order Id", OrderLine."Shopify Order Id");
FulfillmentOrderLine.SetRange("Shopify Variant Id", OrderLine."Shopify Variant Id");
FulfillmentOrderLine.SetRange("Shopify Location Id", OrderLine."Location Id");
FulfillmentOrderLine.SetRange("Delivery Method Type", OrderLine."Delivery Method Type");
FulfillmentOrderLine.SetFilter("Remaining Quantity", '>=%1', Round(SalesShipmentLine.Quantity, 1, '='));
FulfillmentOrderLine.SetFilter("Fulfillment Status", '<>%1', 'CLOSED');
if FulfillmentOrderLine.FindFirst() then
exit(true);
end;
FulfillmentOrderLine.Reset();
FulfillmentOrderLine.SetRange("Shopify Order Id", SalesShipmentHeader."Shpfy Order Id");
FulfillmentOrderLine.SetRange("Line Item Id", SalesShipmentLine."Shpfy Order Line Id");
FulfillmentOrderLine.SetFilter("Fulfillment Status", '<>%1', 'CLOSED');
FulfillmentOrderLine.SetFilter("Remaining Quantity", '>%1', 0);
if not FulfillmentOrderLine.FindSet() then
exit;

RemainingQtyToFulfill := Round(SalesShipmentLine.Quantity, 1, '=');
repeat
if RemainingQtyToFulfill <= 0 then
break;

if FulfillmentOrderLine."Remaining Quantity" >= RemainingQtyToFulfill then
QtyToFulfillOnLine := RemainingQtyToFulfill
else
QtyToFulfillOnLine := FulfillmentOrderLine."Remaining Quantity";

FulfillmentOrderLine."Quantity to Fulfill" += QtyToFulfillOnLine;
FulfillmentOrderLine."Remaining Quantity" -= QtyToFulfillOnLine;
FulfillmentOrderLine.Modify();

if TempFulfillmentOrderLine.Get(FulfillmentOrderLine."Shopify Fulfillment Order Id", FulfillmentOrderLine."Shopify Fulfillm. Ord. Line Id") then begin
TempFulfillmentOrderLine."Quantity to Fulfill" += QtyToFulfillOnLine;
TempFulfillmentOrderLine.Modify();
end else begin
TempFulfillmentOrderLine := FulfillmentOrderLine;
TempFulfillmentOrderLine."Quantity to Fulfill" := QtyToFulfillOnLine;
TempFulfillmentOrderLine.Insert();
end;

AcceptPendingFulfillmentRequests(Shop, FulfillmentOrderLine."Shopify Fulfillment Order Id", AssignedFulfillmentOrderIds);

RemainingQtyToFulfill -= QtyToFulfillOnLine;
until FulfillmentOrderLine.Next() = 0;
end;

local procedure CanFulfillOrder(FulfillmentOrderLine: Record "Shpfy FulFillment Order Line"; Shop: Record "Shpfy Shop"; var UnfulfillableOrders: List of [BigInteger]): Boolean
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ codeunit 139559 "Shpfy Shipping Helper"
FulfillmentOrderLine."Remaining Quantity" := OrderLine.Quantity;
FulfillmentOrderLine."Shopify Location Id" := OrderLine."Location Id";
FulfillmentOrderLine."Delivery Method Type" := DeliveryMethodType;
FulfillmentOrderLine."Line Item Id" := OrderLine."Line Id";
FulfillmentOrderLine.Insert();
until OrderLine.Next() = 0;

Expand Down
Loading
Loading