-
Notifications
You must be signed in to change notification settings - Fork 664
[Shopify] Sales Channels publishing for new products #27540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aholstrup1
merged 25 commits into
microsoft:main
from
GediminasGaubys:dev/pmi/SalesChannels
Dec 6, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8d88a53
add sales channels import
petemchlk eb80a51
add publishing process on create, modify structure to be able to choo…
petemchlk 51f882e
code refactor
petemchlk 3fb3416
Create import test
petemchlk 93891bb
add tests, refactor code
petemchlk 8156596
add tests
petemchlk 28f339c
remove empty line
petemchlk 477b5d4
udpate gql query, add default field and default channel publishing in…
petemchlk b399ab0
fix tests, add test for trgering publish from create prod
petemchlk 5f01f2c
PR fixes
petemchlk d252953
update object ids, premission sets, gql type enum ids fixed
petemchlk 7877b78
fix summaries
petemchlk fa87320
create get next sales channels
petemchlk 06a17b0
fix function name
petemchlk 4a452af
saleschannels pagination
petemchlk a1994c2
adjust tests to sales channels paging
petemchlk 7a7fe99
refactor
petemchlk b0dae35
fix tooltip
petemchlk 966a398
Merge branch 'main' into dev/pmi/SalesChannels
JesperSchulz 9cbd1f0
PR fixes
petemchlk ee0eb34
Merge branch 'dev/pmi/SalesChannels' of https://github.com/GediminasG…
petemchlk a4caf5c
Update Apps/W1/Shopify/app/src/Products/Tables/ShpfySalesChannel.Tabl…
onbuyuka 673391b
Merge branch 'main' into dev/pmi/SalesChannels
JesperSchulz e924c5a
Fix ID clashes
JesperSchulz 1bdc4a2
Update IDs
JesperSchulz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.