-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Shopify] Sales Channels publishing for new products (#27540)
This pull request does not have a related issue as it's part of delivery for development agreed directly with @AndreiPanko Fixes #26819 ### Sales Channels publishing for new products This PR contains new functionality where user can choose Sales Channels which will new products be published to on creation from BC. Solution contains new page and table - Shopify Sales Channels available from Shopify Shop. On page user can import sales channels available for shop and choose to which new products should be published to. If user does not choose any of the channels, then channel "Online Shop" is being used by default. In case user did not import Sales Channels before running create product sales channels are pulled from Shopify on before publishing and default channel is used. Pulled sales channels are updated in BC - in case the channel was removed in Shopify its removed from list in BC. ### Modified/new objects - New GQL query codeunit was created to import the Sales Channels. - New GQL Query Enum Value - New codeunit Shpfy Sales Channel API to handle sales channels import - Removed detracted published = true from Shpfy Product API, added procedures to handle new way of publishing new products to sales channels - Sales Channels page and table - New action on Shopify Shop Card page - Sales Channels Fixes [AB#556526](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/556526), [AB#550319](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/550319) --------- Co-authored-by: Piotr Michalak <[email protected]> Co-authored-by: Jesper Schulz-Wedde <[email protected]> Co-authored-by: Onat Buyukakkus <[email protected]>
- Loading branch information
1 parent
83d72b0
commit 07ec75f
Showing
14 changed files
with
744 additions
and
0 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLGetFulfillments.Codeunit.al
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
26 changes: 26 additions & 0 deletions
26
Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLGetNextSChannels.Codeunit.al
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
/// <summary> | ||
/// Codeunit Shpfy GQL Get Next S. Channels (ID 30375) implements Interface Shpfy IGraphQL. | ||
/// </summary> | ||
codeunit 30384 "Shpfy GQL Get Next S. Channels" implements "Shpfy IGraphQL" | ||
{ | ||
Access = Internal; | ||
|
||
/// <summary> | ||
/// GetGraphQL. | ||
/// </summary> | ||
/// <returns>Return value of type Text.</returns> | ||
internal procedure GetGraphQL(): Text | ||
begin | ||
exit('{"query" : "{publications(first: 25, after:\"{{After}}\", catalogType: APP) { pageInfo{ hasNextPage } edges { cursor node { id catalog { id ... on AppCatalog { apps(first: 1) { edges { node { id handle title } } } } } } } } }"}'); | ||
end; | ||
|
||
/// <summary> | ||
/// GetExpectedCost. | ||
/// </summary> | ||
/// <returns>Return value of type Integer.</returns> | ||
internal procedure GetExpectedCost(): Integer | ||
begin | ||
exit(32); | ||
end; | ||
} |
27 changes: 27 additions & 0 deletions
27
Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLGetSalesChannels.Codeunit.al
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
/// <summary> | ||
/// Codeunit Shpfy GQL Get SalesChannels (ID 30371) implements Interface Shpfy IGraphQL. | ||
/// </summary> | ||
codeunit 30371 "Shpfy GQL Get SalesChannels" implements "Shpfy IGraphQL" | ||
{ | ||
Access = Internal; | ||
|
||
/// <summary> | ||
/// GetGraphQL. | ||
/// </summary> | ||
/// <returns>Return value of type Text.</returns> | ||
internal procedure GetGraphQL(): Text | ||
begin | ||
exit('{"query": "{publications(first: 25, catalogType: APP) { pageInfo{ hasNextPage } edges { cursor node { id catalog { id ... on AppCatalog { apps(first: 1) { edges { node { id handle title } } } } } } } } }"}'); | ||
end; | ||
|
||
/// <summary> | ||
/// GetExpectedCost. | ||
/// </summary> | ||
/// <returns>Return value of type Integer.</returns> | ||
internal procedure GetExpectedCost(): Integer | ||
begin | ||
exit(22); | ||
end; | ||
} |
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
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
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
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
98 changes: 98 additions & 0 deletions
98
Apps/W1/Shopify/app/src/Products/Codeunits/ShpfySalesChannelAPI.Codeunit.al
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
/// <summary> | ||
/// Codeunit Shpfy Sales Channel API (ID 30372). | ||
/// </summary> | ||
codeunit 30372 "Shpfy Sales Channel API" | ||
{ | ||
Access = Internal; | ||
|
||
var | ||
JsonHelper: Codeunit "Shpfy Json Helper"; | ||
CommunicationMgt: Codeunit "Shpfy Communication Mgt."; | ||
|
||
/// <summary> | ||
/// Retrieves the sales channels from Shopify and updates the table with the new sales channels. | ||
/// </summary> | ||
/// <param name="ShopCode">The code of the shop.</param> | ||
internal procedure RetrieveSalesChannelsFromShopify(ShopCode: Code[20]) | ||
var | ||
GraphQLType: Enum "Shpfy GraphQL Type"; | ||
JResponse: JsonToken; | ||
JPublications: JsonArray; | ||
Cursor: Text; | ||
Parameters: Dictionary of [Text, Text]; | ||
CurrentChannels: List of [BigInteger]; | ||
begin | ||
CurrentChannels := CollectChannels(ShopCode); | ||
|
||
CommunicationMgt.SetShop(ShopCode); | ||
GraphQLType := GraphQLType::GetSalesChannels; | ||
|
||
repeat | ||
JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters); | ||
if JsonHelper.GetJsonArray(JResponse, JPublications, 'data.publications.edges') then begin | ||
ExtractSalesChannels(JPublications, ShopCode, CurrentChannels, Cursor); | ||
if Parameters.ContainsKey('After') then | ||
Parameters.Set('After', Cursor) | ||
else | ||
Parameters.Add('After', Cursor); | ||
GraphQLType := GraphQLType::GetNextSalesChannels; | ||
end; | ||
until not JsonHelper.GetValueAsBoolean(JResponse, 'data.publications.pageInfo.hasNextPage'); | ||
|
||
RemoveNotExistingChannels(CurrentChannels); | ||
end; | ||
|
||
local procedure CollectChannels(ShopCode: Code[20]): List of [BigInteger] | ||
var | ||
SalesChannel: Record "Shpfy Sales Channel"; | ||
Channels: List of [BigInteger]; | ||
begin | ||
SalesChannel.SetRange("Shop Code", ShopCode); | ||
if SalesChannel.FindSet() then | ||
repeat | ||
Channels.Add(SalesChannel.Id); | ||
until SalesChannel.Next() = 0; | ||
exit(Channels); | ||
end; | ||
|
||
local procedure RemoveNotExistingChannels(CurrentChannels: List of [BigInteger]) | ||
var | ||
SalesChannel: Record "Shpfy Sales Channel"; | ||
ChannelId: BigInteger; | ||
begin | ||
foreach ChannelId in CurrentChannels do begin | ||
SalesChannel.Get(ChannelId); | ||
SalesChannel.Delete(true); | ||
end; | ||
end; | ||
|
||
local procedure ExtractSalesChannels(JPublications: JsonArray; ShopCode: Code[20]; CurrentChannels: List of [BigInteger]; var Cursor: Text) | ||
var | ||
SalesChannel: Record "Shpfy Sales Channel"; | ||
JPublication: JsonToken; | ||
ChannelId: BigInteger; | ||
JCatalogEdges: JsonArray; | ||
JCatalogEdge: JsonToken; | ||
Handle: Text; | ||
begin | ||
foreach JPublication in JPublications do begin | ||
Cursor := JsonHelper.GetValueAsText(JPublication, 'cursor'); | ||
ChannelId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JPublication, '$.node.id')); | ||
if not SalesChannel.Get(ChannelId) then begin | ||
SalesChannel.Init(); | ||
SalesChannel.Validate(Id, ChannelId); | ||
JCatalogEdges := JsonHelper.GetJsonArray(JPublication, '$.node.catalog.apps.edges'); | ||
JCatalogEdges.Get(0, JCatalogEdge); | ||
SalesChannel.Validate(Name, JsonHelper.GetValueAsText(JCatalogEdge, '$.node.title')); | ||
Handle := JsonHelper.GetValueAsText(JCatalogEdge, '$.node.handle'); | ||
if Handle = 'online_store' then | ||
SalesChannel.Default := true; | ||
SalesChannel."Shop Code" := ShopCode; | ||
SalesChannel.Insert(true); | ||
end else | ||
CurrentChannels.Remove(ChannelId); | ||
end; | ||
end; | ||
} |
51 changes: 51 additions & 0 deletions
51
Apps/W1/Shopify/app/src/Products/Pages/ShpfySalesChannels.Page.al
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
page 30167 "Shpfy Sales Channels" | ||
{ | ||
ApplicationArea = All; | ||
Caption = 'Shopify Sales Channels'; | ||
PageType = List; | ||
SourceTable = "Shpfy Sales Channel"; | ||
InsertAllowed = false; | ||
DeleteAllowed = false; | ||
UsageCategory = None; | ||
|
||
|
||
layout | ||
{ | ||
area(Content) | ||
{ | ||
repeater(General) | ||
{ | ||
field(Id; Rec.Id) { } | ||
field(Name; Rec.Name) { } | ||
field("Use for publication"; Rec."Use for publication") { } | ||
field(Default; Rec.Default) { } | ||
} | ||
} | ||
} | ||
|
||
actions | ||
{ | ||
area(Processing) | ||
{ | ||
action(GetSalesChannels) | ||
{ | ||
ApplicationArea = All; | ||
Caption = 'Get Sales Channels'; | ||
Promoted = true; | ||
PromotedOnly = true; | ||
PromotedCategory = Process; | ||
Image = UpdateDescription; | ||
ToolTip = 'Retrieves the sales channels from Shopify.'; | ||
|
||
trigger OnAction() | ||
var | ||
ShpfySalesChannelAPI: Codeunit "Shpfy Sales Channel API"; | ||
begin | ||
ShpfySalesChannelAPI.RetrieveSalesChannelsFromShopify(CopyStr(Rec.GetFilter("Shop Code"), 1, 20)); | ||
end; | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Apps/W1/Shopify/app/src/Products/Tables/ShpfySalesChannel.Table.al
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
/// <summary> | ||
/// Table Shpfy Sales Channel (ID 30159). | ||
/// </summary> | ||
table 30160 "Shpfy Sales Channel" | ||
{ | ||
Caption = 'Shopify Sales Channel'; | ||
DataClassification = CustomerContent; | ||
|
||
fields | ||
{ | ||
field(1; Id; BigInteger) | ||
{ | ||
Caption = 'Id'; | ||
Editable = false; | ||
ToolTip = 'Specifies the unique identifier of the sales channel.'; | ||
} | ||
field(2; Name; Text[100]) | ||
{ | ||
Caption = 'Name'; | ||
Editable = false; | ||
ToolTip = 'Specifies the name of the sales channel.'; | ||
} | ||
field(3; "Shop Code"; Code[20]) | ||
{ | ||
Caption = 'Shop Code'; | ||
Editable = false; | ||
ToolTip = 'Specifies the code of the shop.'; | ||
} | ||
field(4; "Use for publication"; Boolean) | ||
{ | ||
Caption = 'Use for publication'; | ||
ToolTip = 'Specifies if the sales channel is used for new products publication.'; | ||
} | ||
field(5; Default; Boolean) | ||
{ | ||
Caption = 'Default'; | ||
Editable = false; | ||
ToolTip = 'Specifies if the sales channel is the default one. Used for new products publication if no other channel is selected'; | ||
} | ||
} | ||
keys | ||
{ | ||
key(PK; Id) | ||
{ | ||
Clustered = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.