From b4b8323e18c1dd46f9887c4b37c4e0cc700d6724 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 3 Oct 2024 18:30:28 +0200 Subject: [PATCH 01/24] add import customer metafields import --- .../Codeunits/ShpfyCustomerAPI.Codeunit.al | 5 +++ .../Customers/Pages/ShpfyCustomers.Page.al | 20 ++++++++++++ .../Codeunits/ShpfyGQLCustomer.Codeunit.al | 2 +- .../ShpfyGQLCustomerMetafieldIds.Codeunit.al | 27 ++++++++++++++++ .../GraphQL/Enums/ShpfyGraphQLType.Enum.al | 5 +++ .../ShpfyMetafieldOwnerCustomer.Codeunit.al | 32 +++++++++++++++++-- .../Metafields/Pages/ShpfyMetafields.Page.al | 9 ++++-- 7 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerAPI.Codeunit.al index fe21f1f938..448c3b7f4b 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerAPI.Codeunit.al @@ -356,12 +356,14 @@ codeunit 30114 "Shpfy Customer API" internal procedure UpdateShopifyCustomerFields(var ShopifyCustomer: Record "Shpfy Customer"; JCustomer: JsonObject) Result: Boolean var CustomerAddress: Record "Shpfy Customer Address"; + MetafieldAPI: Codeunit "Shpfy Metafield API"; NodeId: BigInteger; UpdatedAt: DateTime; JAddresses: JsonArray; JTags: JsonArray; JAddress: JsonObject; JItem: JsonToken; + JMetafields: JsonArray; Ids: List of [BigInteger]; OutStream: OutStream; StateString: Text; @@ -462,6 +464,9 @@ codeunit 30114 "Shpfy Customer API" CustomerAddress.Modify(false); end; end; + + if JsonHelper.GetJsonArray(JCustomer, JMetafields, 'metafields.edges') then + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Customer", ShopifyCustomer.Id); end; end; diff --git a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al index 69f037fc5e..77b8ada4b4 100644 --- a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al +++ b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al @@ -187,7 +187,27 @@ page 30107 "Shpfy Customers" BackgroundSyncs.CustomerSync(Shop.Code); end; end; + } + action(Metafields) + { + ApplicationArea = All; + Caption = 'Metafields'; + Image = PriceAdjustment; + Promoted = true; + PromotedCategory = Process; + PromotedIsBig = true; + PromotedOnly = true; + ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + trigger OnAction() + var + Metafields: Page "Shpfy Metafields"; + Shop: Record "Shpfy Shop"; + begin + Shop.SetRange("Shop Id", Rec."Shop Id"); + Shop.FindFirst(); + Metafields.RunForResource(Database::"Shpfy Customer", Rec.Id, Shop.Code); + end; } } } diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomer.Codeunit.al index 01f216dbbe..cacc1bd2ca 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomer.Codeunit.al @@ -13,7 +13,7 @@ codeunit 30127 "Shpfy GQL Customer" implements "Shpfy IGraphQL" /// Return value of type Text. internal procedure GetGraphQL(): Text begin - exit('{"query":"{customer(id: \"gid://shopify/Customer/{{CustomerId}}\") {legacyResourceId firstName lastName email phone taxExempt taxExemptions verifiedEmail state note createdAt updatedAt tags emailMarketingConsent {consentUpdatedAt marketingState} addresses {id company firstName lastName address1 address2 zip city countryCodeV2 country provinceCode province phone} defaultAddress {id} metafields(namespace: \"Microsoft.Dynamics365.BusinessCentral\" first: 10) {edges {node {id namespace ownerType legacyResourceId key value}}}}}"}'); + exit('{"query":"{customer(id: \"gid://shopify/Customer/{{CustomerId}}\") {legacyResourceId firstName lastName email phone taxExempt taxExemptions verifiedEmail state note createdAt updatedAt tags emailMarketingConsent {consentUpdatedAt marketingState} addresses {id company firstName lastName address1 address2 zip city countryCodeV2 country provinceCode province phone} defaultAddress {id} metafields(first: 50) {edges {node {id namespace ownerType legacyResourceId key value type}}}}}"}'); end; /// diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al new file mode 100644 index 0000000000..1298d1ccfe --- /dev/null +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al @@ -0,0 +1,27 @@ +namespace Microsoft.Integration.Shopify; +/// +/// Codeunit Shpfy GQL Customer Metafield Ids (ID 30168) implements Interface Shpfy IGraphQL. +/// +codeunit 30168 "Shpfy GQL CustomerMetafieldIds" implements "Shpfy IGraphQL" +{ + Access = Internal; + + /// + /// GetGraphQL. + /// + /// Return value of type Text. + procedure GetGraphQL(): Text + begin + exit('{"query":"{customer(id: \"gid://shopify/Customer/{{CustomerId}}\") { metafields(first: 50) {edges {node {legacyResourceId updatedAt}}}}}"}'); + end; + + /// + /// GetExpectedCost. + /// + /// Return value of type Integer. + procedure GetExpectedCost(): Integer + begin + exit(10); + end; + +} diff --git a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al index dab96ed8ab..c660fc63a5 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al @@ -490,4 +490,9 @@ enum 30111 "Shpfy GraphQL Type" implements "Shpfy IGraphQL" Caption = 'Get Product Image'; Implementation = "Shpfy IGraphQL" = "Shpfy GQL GetProductImage"; } + value(98; CustomerMetafieldIds) + { + Caption = 'Customer Metafield Ids'; + Implementation = "Shpfy IGraphQL" = "Shpfy GQL CustomerMetafieldIds"; + } } diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al index 98646f1731..73e3c81149 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al @@ -7,13 +7,39 @@ codeunit 30333 "Shpfy Metafield Owner Customer" implements "Shpfy IMetafield Own exit(Database::"Shpfy Customer"); end; - procedure RetrieveMetafieldIdsFromShopify(OwnerId: BigInteger): Dictionary of [BigInteger, DateTime] + procedure RetrieveMetafieldIdsFromShopify(OwnerId: BigInteger) MetafieldIds: Dictionary of [BigInteger, DateTime] + var + CommunicationMgt: Codeunit "Shpfy Communication Mgt."; + JsonHelper: Codeunit "Shpfy Json Helper"; + Parameters: Dictionary of [Text, Text]; + GraphQLType: Enum "Shpfy GraphQL Type"; + JResponse: JsonToken; + JMetafields: JsonArray; + JNode: JsonObject; + JItem: JsonToken; + Id: BigInteger; + UpdatedAt: DateTime; begin - Error('Not implemented'); + Parameters.Add('CustomerId', Format(OwnerId)); + GraphQLType := GraphQLType::CustomerMetafieldIds; + JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters); + if JsonHelper.GetJsonArray(JResponse, JMetafields, 'data.product.metafields.edges') then + foreach JItem in JMetafields do + if JsonHelper.GetJsonObject(JItem.AsObject(), JNode, 'node') then begin + Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode, 'legacyResourceId')); + UpdatedAt := JsonHelper.GetValueAsDateTime(JNode, 'updatedAt'); + MetafieldIds.Add(Id, UpdatedAt); + end; end; procedure GetShopCode(OwnerId: BigInteger): Code[20] + var + Customer: Record "Shpfy Customer"; + Shop: Record "Shpfy Shop"; begin - exit('Not implemented'); + Customer.Get(OwnerId); + Shop.SetRange("Shop Id", Customer."Shop Id"); + Shop.FindFirst(); + exit(Shop.Code); end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al index 2029380a48..3dd1db64f5 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al +++ b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al @@ -90,10 +90,15 @@ page 30163 "Shpfy Metafields" internal procedure RunForResource(ParentTableId: Integer; OwnerId: BigInteger; ShopCode: Code[20]) var Metafield: Record "Shpfy Metafield"; + OwnerType: Enum "Shpfy Metafield Owner Type"; begin Shop.Get(ShopCode); - IsPageEditable := (Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products"); - + case Metafield.GetOwnerType(ParentTableId) of + OwnerType::Product, OwnerType::ProductVariant: + IsPageEditable := (Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products"); + OwnerType::Customer: + IsPageEditable := Shop."Can Update Shopify Customer"; + end; Metafield.SetRange("Parent Table No.", ParentTableId); Metafield.SetRange("Owner Id", OwnerId); From 641b9b6572243768bec8492f489a9e2e325cfaf4 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 4 Oct 2024 09:20:36 +0200 Subject: [PATCH 02/24] handle metafields removalwhen removed in Shopify --- .../Metafields/Codeunits/ShpfyMetafieldAPI.Codeunit.al | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/ShpfyMetafieldAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/ShpfyMetafieldAPI.Codeunit.al index bd3ba3ad8d..24d5015a4b 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/ShpfyMetafieldAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/ShpfyMetafieldAPI.Codeunit.al @@ -156,7 +156,7 @@ codeunit 30316 "Shpfy Metafield API" MetafieldIds: List of [BigInteger]; MetafieldId: BigInteger; begin - CollectMetafieldIds(OwnerId, MetafieldIds); + CollectMetafieldIds(ParentTableNo, OwnerId, MetafieldIds); foreach JItem in JMetafields do begin JsonHelper.GetJsonObject(JItem.AsObject(), JNode, 'node'); @@ -211,12 +211,12 @@ codeunit 30316 "Shpfy Metafield API" exit(true); end; - local procedure CollectMetafieldIds(ProductId: BigInteger; MetafieldIds: List of [BigInteger]) + local procedure CollectMetafieldIds(ParentTableId: Integer; OwnerId: BigInteger; MetafieldIds: List of [BigInteger]) var Metafield: Record "Shpfy Metafield"; begin - MetaField.SetRange("Parent Table No.", Database::"Shpfy Product"); - Metafield.SetRange("Owner Id", ProductId); + MetaField.SetRange("Parent Table No.", ParentTableId); + Metafield.SetRange("Owner Id", OwnerId); if Metafield.FindSet() then repeat MetafieldIds.Add(Metafield.Id); From 2e391ee5665d8f758db9e2c64ba978393396eb44 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 4 Oct 2024 13:15:24 +0200 Subject: [PATCH 03/24] remove old metafield related not working code, add code to update Customer metafields in shopify --- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 66 +++---------------- 1 file changed, 10 insertions(+), 56 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index 363fe23448..0908840888 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -42,42 +42,6 @@ codeunit 30116 "Shpfy Customer Export" CreateCustomers: Boolean; CountyCodeTooLongLbl: Label 'Can not export customer %1 %2. The length of the string is %3, but it must be less than or equal to %4 characters. Value: %5, field: %6', Comment = '%1 - Customer No., %2 - Customer Name, %3 - Length, %4 - Max Length, %5 - Value, %6 - Field Name'; - /// - /// Add Or Update Metadata. - /// - /// Parameter of type Record "Shopify Customer". - /// Parameter of type FieldRef. - internal procedure AddOrUpdateMetadata(ShopifyCustomer: Record "Shpfy Customer"; MetadataFieldRef: FieldRef) - var - Metafield: Record "Shpfy Metafield"; - Name: Text; - begin - Metafield.SetRange("Parent Table No.", Database::"Shpfy Customer"); - Metafield.SetRange("Owner Id", ShopifyCustomer.Id); - Metafield.SetRange(Namespace, 'Microsoft.Dynamics365.BusinessCentral'); - Name := CleanName(MetadataFieldRef); - Metafield.SetRange(Name, Name); - if Metafield.FindFirst() then begin - if Metafield.Value <> Format(MetadataFieldRef.Value) then; - end else begin - Clear(Metafield); - Metafield.Namespace := 'Microsoft.Dynamics365.BusinessCentral'; - Metafield.Validate("Parent Table No.", Database::"Shpfy Customer"); - Metafield."Owner Id" := ShopifyCustomer.Id; - Metafield.Type := Metafield.Type::string; - Metafield.Value := Format(MetadataFieldRef.Value); - end; - end; - - /// - /// Clean Name. - /// - /// Parameter of type FieldRef. - /// Return value of type Text. - local procedure CleanName(FieldRef: FieldRef): Text - begin - exit(DelChr(FieldRef.Record().Name, '=', ' %.-+') + '.' + DelChr(FieldRef.Name, '=', ' %-+')); - end; /// /// Create Shopify Customer. @@ -101,7 +65,8 @@ codeunit 30116 "Shpfy Customer Export" ShopifyCustomer.Insert(); CustomerAddress.Insert(); end; - MetadataFields(Customer, ShopifyCustomer); + + UpdateMetafields(ShopifyCustomer.Id); end; /// @@ -224,25 +189,6 @@ codeunit 30116 "Shpfy Customer Export" exit(true); end; - /// - /// Metadata Fields. - /// - /// Parameter of type Record Customer. - /// Parameter of type Record "Shopify Customer". - local procedure MetadataFields(Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer") - var - RecordRef: RecordRef; - begin - RecordRef.GetTable(Customer); - AddOrUpdateMetadata(ShopifyCustomer, RecordRef.Field(Customer.FieldNo("No."))); - AddOrUpdateMetadata(ShopifyCustomer, RecordRef.Field(Customer.FieldNo("VAT Bus. Posting Group"))); - AddOrUpdateMetadata(ShopifyCustomer, RecordRef.Field(Customer.FieldNo("VAT Registration No."))); - AddOrUpdateMetadata(ShopifyCustomer, RecordRef.Field(Customer.FieldNo(SystemId))); - AddOrUpdateMetadata(ShopifyCustomer, RecordRef.Field(Customer.FieldNo("Customer Disc. Group"))); - AddOrUpdateMetadata(ShopifyCustomer, RecordRef.Field(Customer.FieldNo("Customer Price Group"))); - AddOrUpdateMetadata(ShopifyCustomer, RecordRef.Field(Customer.FieldNo("Customer Posting Group"))); - end; - /// /// Set Shop. /// @@ -313,10 +259,18 @@ codeunit 30116 "Shpfy Customer Export" ShopifyCustomer.Modify(); CustomerAddress.Modify(); end; + UpdateMetafields(ShopifyCustomer.Id); end; internal procedure SetCreateCustomers(NewCustomers: Boolean) begin CreateCustomers := NewCustomers; end; + + local procedure UpdateMetafields(CustomerId: BigInteger) + var + MetafieldAPI: Codeunit "Shpfy Metafield API"; + begin + MetafieldAPI.CreateOrUpdateMetafieldsInShopify(Database::"Shpfy Customer", CustomerId); + end; } \ No newline at end of file From ddf0b6746c1f5c889bdbcd7f7d62fc3ef2e9c5de Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 4 Oct 2024 16:51:08 +0200 Subject: [PATCH 04/24] add company metafield import --- .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 4 +++ .../Companies/Pages/ShpfyCompanies.Page.al | 18 +++++++++++++ .../Codeunits/ShpfyGQLCompany.Codeunit.al | 4 +-- .../ShpfyGQLCompanyMetafieldIds.Codeunit.al | 26 +++++++++++++++++++ .../ShpfyGQLCustomerMetafieldIds.Codeunit.al | 2 +- .../GraphQL/Enums/ShpfyGraphQLType.Enum.al | 5 ++++ .../ShpfyMetafieldOwnerCompany.Codeunit.al | 24 +++++++++++++++++ .../Enums/ShpfyMetafieldOwnerType.Enum.al | 6 +++++ .../Metafields/Pages/ShpfyMetafields.Page.al | 2 ++ 9 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al create mode 100644 Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 6d5a83e720..ede700bdb6 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -293,8 +293,10 @@ codeunit 30286 "Shpfy Company API" internal procedure UpdateShopifyCompanyFields(var ShopifyCompany: Record "Shpfy Company"; JCompany: JsonObject) Result: Boolean var CompanyLocation: Record "Shpfy Company Location"; + MetafieldAPI: Codeunit "Shpfy Metafield API"; UpdatedAt: DateTime; JLocations: JsonArray; + JMetafields: JsonArray; JItem: JsonToken; OutStream: OutStream; PhoneNo: Text; @@ -343,5 +345,7 @@ codeunit 30286 "Shpfy Company API" CompanyLocation."Tax Registration Id" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.taxRegistrationId', MaxStrLen(CompanyLocation."Tax Registration Id")), 1, MaxStrLen(CompanyLocation."Tax Registration Id")); CompanyLocation.Modify(); end; + if JsonHelper.GetJsonArray(JCompany, JMetafields, 'metafields.edges') then + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Company", ShopifyCompany.Id); end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al index 39fd16175a..9b4b9d1722 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al @@ -171,6 +171,24 @@ page 30156 "Shpfy Companies" end; } + action(Metafields) + { + ApplicationArea = All; + Caption = 'Metafields'; + Image = PriceAdjustment; + Promoted = true; + PromotedCategory = Process; + PromotedIsBig = true; + PromotedOnly = true; + ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + + trigger OnAction() + var + Metafields: Page "Shpfy Metafields"; + begin + Metafields.RunForResource(Database::"Shpfy Company", Rec.Id, Rec."Shop Code"); + end; + } } } } diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al index e6a5806e2a..595dbe2cda 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al @@ -13,7 +13,7 @@ codeunit 30302 "Shpfy GQL Company" implements "Shpfy IGraphQL" /// Return value of type Text. internal procedure GetGraphQL(): Text begin - exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:1, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} taxRegistrationId}}}}}"}'); + exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:1, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} taxRegistrationId }}} metafields(first: 50) {edges {node {id namespace ownerType legacyResourceId key value type}}}}}"}'); end; /// @@ -22,6 +22,6 @@ codeunit 30302 "Shpfy GQL Company" implements "Shpfy IGraphQL" /// Return value of type Integer. internal procedure GetExpectedCost(): Integer begin - exit(7); + exit(10); end; } diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al new file mode 100644 index 0000000000..9b2d6a7aec --- /dev/null +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al @@ -0,0 +1,26 @@ +namespace Microsoft.Integration.Shopify; + +/// +/// Codeunit Shpfy GQL CompanyMetafieldIds (ID 30215) implements Interface Shpfy IGraphQL. +/// +codeunit 30215 "Shpfy GQL CompanyMetafieldIds" implements "Shpfy IGraphQL" +{ + /// + /// GetGraphQL. + /// + /// Return value of type Text. + procedure GetGraphQL(): Text + begin + exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {metafields(first: 50) {edges {node {id namespace ownerType legacyResourceId }}}}}"}'); + end; + + /// + /// GetExpectedCost. + /// + /// Return value of type Integer. + procedure GetExpectedCost(): Integer + begin + exit(50); + end; + +} diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al index 1298d1ccfe..5bf6902ed1 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al @@ -21,7 +21,7 @@ codeunit 30168 "Shpfy GQL CustomerMetafieldIds" implements "Shpfy IGraphQL" /// Return value of type Integer. procedure GetExpectedCost(): Integer begin - exit(10); + exit(50); end; } diff --git a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al index c660fc63a5..12e2c24c0d 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al @@ -495,4 +495,9 @@ enum 30111 "Shpfy GraphQL Type" implements "Shpfy IGraphQL" Caption = 'Customer Metafield Ids'; Implementation = "Shpfy IGraphQL" = "Shpfy GQL CustomerMetafieldIds"; } + value(99; CompanyMetafieldIds) + { + Caption = 'Company Metafield Ids'; + Implementation = "Shpfy IGraphQL" = "Shpfy GQL CompanyMetafieldIds"; + } } diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al new file mode 100644 index 0000000000..97e9950e8c --- /dev/null +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al @@ -0,0 +1,24 @@ +namespace Microsoft.Integration.Shopify; + +codeunit 30313 "Shpfy Metafield Owner Company" implements "Shpfy IMetafield Owner Type" +{ + + procedure GetTableId(): Integer + begin + exit(Database::"Shpfy Company"); + end; + + procedure RetrieveMetafieldIdsFromShopify(OwnerId: BigInteger): Dictionary of [BigInteger, DateTime] + begin + //not implemented yet + end; + + procedure GetShopCode(OwnerId: BigInteger): Code[20] + var + Company: Record "Shpfy Company"; + begin + Company.Get(OwnerId); + exit(Company."Shop Code"); + end; + +} diff --git a/Apps/W1/Shopify/app/src/Metafields/Enums/ShpfyMetafieldOwnerType.Enum.al b/Apps/W1/Shopify/app/src/Metafields/Enums/ShpfyMetafieldOwnerType.Enum.al index 71d42d21c1..7fbf1c334d 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Enums/ShpfyMetafieldOwnerType.Enum.al +++ b/Apps/W1/Shopify/app/src/Metafields/Enums/ShpfyMetafieldOwnerType.Enum.al @@ -21,4 +21,10 @@ enum 30156 "Shpfy Metafield Owner Type" implements "Shpfy IMetafield Owner Type" Caption = 'Variant'; Implementation = "Shpfy IMetafield Owner Type" = "Shpfy Metafield Owner Variant"; } + + value(3; Company) + { + Caption = 'Company'; + Implementation = "Shpfy IMetafield Owner Type" = "Shpfy Metafield Owner Company"; + } } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al index 3dd1db64f5..15815ca2d6 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al +++ b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al @@ -98,6 +98,8 @@ page 30163 "Shpfy Metafields" IsPageEditable := (Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products"); OwnerType::Customer: IsPageEditable := Shop."Can Update Shopify Customer"; + OwnerType::Company: + IsPageEditable := Shop."Can Update Shopify Companies"; end; Metafield.SetRange("Parent Table No.", ParentTableId); Metafield.SetRange("Owner Id", OwnerId); From 753ab0cfd6e41669c0e0a3ccdbaca902d04771cc Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 4 Oct 2024 17:36:03 +0200 Subject: [PATCH 05/24] Add metafield export support --- .../Codeunits/ShpfyCompanyExport.Codeunit.al | 9 +++++++ .../ShpfyMetafieldOwnerCompany.Codeunit.al | 24 +++++++++++++++++-- .../Metafields/Tables/ShpfyMetafield.Table.al | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al index cf65199341..761d48979c 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -193,6 +193,15 @@ codeunit 30284 "Shpfy Company Export" ShopifyCompany.Modify(); CompanyLocation.Modify(); end; + + UpdateMetafields(ShopifyCompany.Id); + end; + + local procedure UpdateMetafields(ComppanyId: BigInteger) + var + MetafieldAPI: Codeunit "Shpfy Metafield API"; + begin + MetafieldAPI.CreateOrUpdateMetafieldsInShopify(Database::"Shpfy Company", ComppanyId); end; internal procedure SetCreateCompanies(NewCustomers: Boolean) diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al index 97e9950e8c..d6a5210818 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al @@ -8,9 +8,29 @@ codeunit 30313 "Shpfy Metafield Owner Company" implements "Shpfy IMetafield Owne exit(Database::"Shpfy Company"); end; - procedure RetrieveMetafieldIdsFromShopify(OwnerId: BigInteger): Dictionary of [BigInteger, DateTime] + procedure RetrieveMetafieldIdsFromShopify(OwnerId: BigInteger) MetafieldIds: Dictionary of [BigInteger, DateTime] + var + CommunicationMgt: Codeunit "Shpfy Communication Mgt."; + JsonHelper: Codeunit "Shpfy Json Helper"; + Parameters: Dictionary of [Text, Text]; + GraphQLType: Enum "Shpfy GraphQL Type"; + JResponse: JsonToken; + JMetafields: JsonArray; + JNode: JsonObject; + JItem: JsonToken; + Id: BigInteger; + UpdatedAt: DateTime; begin - //not implemented yet + Parameters.Add('CompanyId', Format(OwnerId)); + GraphQLType := GraphQLType::CompanyMetafieldIds; + JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters); + if JsonHelper.GetJsonArray(JResponse, JMetafields, 'data.company.metafields.edges') then + foreach JItem in JMetafields do + if JsonHelper.GetJsonObject(JItem.AsObject(), JNode, 'node') then begin + Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode, 'legacyResourceId')); + UpdatedAt := JsonHelper.GetValueAsDateTime(JNode, 'updatedAt'); + MetafieldIds.Add(Id, UpdatedAt); + end; end; procedure GetShopCode(OwnerId: BigInteger): Code[20] diff --git a/Apps/W1/Shopify/app/src/Metafields/Tables/ShpfyMetafield.Table.al b/Apps/W1/Shopify/app/src/Metafields/Tables/ShpfyMetafield.Table.al index 6e7955daa8..9827ff408c 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Tables/ShpfyMetafield.Table.al +++ b/Apps/W1/Shopify/app/src/Metafields/Tables/ShpfyMetafield.Table.al @@ -173,6 +173,8 @@ table 30101 "Shpfy Metafield" exit("Owner Type"::Product); Database::"Shpfy Variant": exit("Owner Type"::ProductVariant); + Database::"Shpfy Company": + exit("Owner Type"::Company); end; end; From 321fd5ecb0de1b7f774321a4ff76f04ff7448d3e Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 4 Oct 2024 17:51:15 +0200 Subject: [PATCH 06/24] small refactors --- .../app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al | 1 + .../W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index 0908840888..a370bf2db3 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -259,6 +259,7 @@ codeunit 30116 "Shpfy Customer Export" ShopifyCustomer.Modify(); CustomerAddress.Modify(); end; + UpdateMetafields(ShopifyCustomer.Id); end; diff --git a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al index 15815ca2d6..5b98fa7fcc 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al +++ b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al @@ -93,6 +93,7 @@ page 30163 "Shpfy Metafields" OwnerType: Enum "Shpfy Metafield Owner Type"; begin Shop.Get(ShopCode); + case Metafield.GetOwnerType(ParentTableId) of OwnerType::Product, OwnerType::ProductVariant: IsPageEditable := (Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products"); @@ -101,6 +102,7 @@ page 30163 "Shpfy Metafields" OwnerType::Company: IsPageEditable := Shop."Can Update Shopify Companies"; end; + Metafield.SetRange("Parent Table No.", ParentTableId); Metafield.SetRange("Owner Id", OwnerId); From 56a224df2c4aea4a55d2a75010aa3ef96cb145bd Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 7 Oct 2024 10:55:58 +0200 Subject: [PATCH 07/24] add metafields action to customer/company card --- .../Companies/Pages/ShpfyCompanyCard.Page.al | 18 ++++++++++++++++ .../Customers/Pages/ShpfyCustomerCard.Page.al | 21 +++++++++++++++++++ .../Customers/Pages/ShpfyCustomers.Page.al | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al index 8980b7073f..b78c638a98 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al @@ -163,6 +163,24 @@ page 30157 "Shpfy Company Card" RunPageLink = "Company SystemId" = field(SystemId); ToolTip = 'View a list of Shopify catalogs for the company.'; } + action(Metafields) + { + ApplicationArea = All; + Caption = 'Metafields'; + Image = PriceAdjustment; + Promoted = true; + PromotedCategory = Category4; + PromotedIsBig = true; + PromotedOnly = true; + ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + + trigger OnAction() + var + Metafields: Page "Shpfy Metafields"; + begin + Metafields.RunForResource(Database::"Shpfy Company", Rec.Id, Rec."Shop Code"); + end; + } } } diff --git a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al index 7a2258b0e9..e62ae55f31 100644 --- a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al +++ b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al @@ -186,6 +186,27 @@ page 30106 "Shpfy Customer Card" RunPageLink = "Customer Id" = Field(Id); ToolTip = 'View a list of Shopify orders for the customer.'; } + action(Metafields) + { + ApplicationArea = All; + Caption = 'Metafields'; + Image = PriceAdjustment; + Promoted = true; + PromotedCategory = Category4; + PromotedIsBig = true; + PromotedOnly = true; + ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + + trigger OnAction() + var + Shop: Record "Shpfy Shop"; + Metafields: Page "Shpfy Metafields"; + begin + Shop.SetRange("Shop Id", Rec."Shop Id"); + Shop.FindFirst(); + Metafields.RunForResource(Database::"Shpfy Customer", Rec.Id, Shop.Code); + end; + } } } diff --git a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al index 77b8ada4b4..08bfcbbff2 100644 --- a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al +++ b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al @@ -201,8 +201,8 @@ page 30107 "Shpfy Customers" trigger OnAction() var - Metafields: Page "Shpfy Metafields"; Shop: Record "Shpfy Shop"; + Metafields: Page "Shpfy Metafields"; begin Shop.SetRange("Shop Id", Rec."Shop Id"); Shop.FindFirst(); From 878d2ed1077d41f53f66e8928414dd3c3b1850cb Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 11 Oct 2024 09:28:36 +0200 Subject: [PATCH 08/24] create test cu --- .../ShpfyCustomerMetafieldsTest.Codeunit.al | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al new file mode 100644 index 0000000000..548e2d7948 --- /dev/null +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -0,0 +1,27 @@ +codeunit 139581 "Shpfy Customer Metafields Test" +{ + Subtype = Test; + TestPermissions = Disabled; + + var + LibraryAssert: Codeunit "Library Assert"; + + [Test] + procedure UnitTestExportMetafieldsToShopify() + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + CustomerAddress: Record "Shpfy Customer Address"; + Shop: Record "Shpfy Shop"; + InitializeTest: Codeunit "Shpfy Initialize Test"; + Result: boolean; + begin + // [SCENARIO] Export Customer metafields to Shopify. + // [GIVEN] Customer Id With metafields created in BC. + + // [WHEN] Invoke MetafieldAPI.CreateOrUpdateMetafieldsInShopify(Database::"Shpfy Customer", CustomerId); + + // [THEN] + end; + +} From ce084058e9042264b1420c02cb9cff261dd4cf9f Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 14 Oct 2024 08:46:25 +0200 Subject: [PATCH 09/24] create test codeunit --- .../ShpfyCustomerMetafieldsTest.Codeunit.al | 84 ++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index 548e2d7948..b46764ffea 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -1,10 +1,60 @@ -codeunit 139581 "Shpfy Customer Metafields Test" +codeunit 139616 "Shpfy Customer Metafields Test" { Subtype = Test; TestPermissions = Disabled; var + Shop: Record "Shpfy Shop"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; LibraryAssert: Codeunit "Library Assert"; + Any: Codeunit Any; + + IsInitialized: Boolean; + + trigger OnRun() + begin + IsInitialized := false; + end; + + [Test] + procedure UnitTestGetMetafieldOwnerTypeFromCustomerMetafield() + var + ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyMetafieldOwnerType: Enum "Shpfy Metafield Owner Type"; + begin + // [SCENARIO] Get Metafield Owner Type from Customer Metafield. + + // [GIVEN] Shopify Metafield created for Customer. + CreateShopifyMetafield(ShpfyMetafield, Database::"Shpfy Customer", Any.IntegerInRange(10000, 99999)); + + // [WHEN] Invoke Metafield.GetOwnerType(); + ShpfyMetafieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Customer"); + + // [THEN] ShpfyMetafieldOwnerType = Enum::"Shpfy Metafield Owner Type"::Customer; + LibraryAssert.AreEqual(ShpfyMetafieldOwnerType, Enum::"Shpfy Metafield Owner Type"::Customer, 'Metafield Owner Type is different than Customer'); + end; + + [Test] + procedure UnitTestGetMetafieldOwnerValuesFromMetafieldOwnerCustomer() + var + ShpfyMetafield: Record "Shpfy Metafield"; + Shop: Record "Shpfy Shop"; + ShpfyCustomer: Record "Shpfy Customer"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + ShpfyMetafieldOwnerType: Enum "Shpfy Metafield Owner Type"; + IMetagieldOwnerType: Interface "Shpfy IMetafield Owner Type"; + begin + // [SCENARIO] Get Metafield Owner Values from Metafield Owner Company codeunit + Initialize(); + + // [GIVEN] Shopify Metafield created for Customer. + // [GIVEN] Shopify Metafield created for Company. + ShpfyMetafield.Init(); + ShpfyMetafield."Owner Id" := Any.IntegerInRange(10000, 99999); + + + + end; [Test] procedure UnitTestExportMetafieldsToShopify() @@ -13,15 +63,43 @@ codeunit 139581 "Shpfy Customer Metafields Test" ShopifyCustomer: Record "Shpfy Customer"; CustomerAddress: Record "Shpfy Customer Address"; Shop: Record "Shpfy Shop"; + ShpfyMetafield: Record "Shpfy Metafield"; InitializeTest: Codeunit "Shpfy Initialize Test"; - Result: boolean; + Result: Boolean; begin // [SCENARIO] Export Customer metafields to Shopify. - // [GIVEN] Customer Id With metafields created in BC. + Initialize(); + + // [GIVEN] Shopify Customer + CreateShopifyCustomer(ShopifyCustomer, Shop."Shop Id"); + // [GIVEN] Customer + + // [WHEN] Invoke MetafieldAPI.CreateOrUpdateMetafieldsInShopify(Database::"Shpfy Customer", CustomerId); // [THEN] end; + local procedure Initialize() + begin + if IsInitialized then + exit; + Shop := ShpfyInitializeTest.CreateShop(); + end; + + local procedure CreateShopifyCustomer(var ShopifyCustomer: Record "Shpfy Customer"; ShopId: BigInteger) + begin + ShopifyCustomer.Init(); + + end; + + local procedure CreateShopifyMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer) + begin + ShpfyMetafield.Init(); + ShpfyMetafield."Owner Id" := OwnerId; + ShpfyMetafield.Validate("Parent Table No.", ParentTableId); + ShpfyMetafield.Insert(true); + end; + } From 38d4e035399710f7a214c5855c3ada021ba5a1d3 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 14 Oct 2024 09:45:37 +0200 Subject: [PATCH 10/24] add test --- .../ShpfyCustomerMetafieldsTest.Codeunit.al | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index b46764ffea..ae52bc6bf8 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -38,22 +38,47 @@ codeunit 139616 "Shpfy Customer Metafields Test" procedure UnitTestGetMetafieldOwnerValuesFromMetafieldOwnerCustomer() var ShpfyMetafield: Record "Shpfy Metafield"; - Shop: Record "Shpfy Shop"; - ShpfyCustomer: Record "Shpfy Customer"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - ShpfyMetafieldOwnerType: Enum "Shpfy Metafield Owner Type"; IMetagieldOwnerType: Interface "Shpfy IMetafield Owner Type"; + TableId: Integer; begin // [SCENARIO] Get Metafield Owner Values from Metafield Owner Company codeunit Initialize(); // [GIVEN] Shopify Metafield created for Customer. - // [GIVEN] Shopify Metafield created for Company. - ShpfyMetafield.Init(); - ShpfyMetafield."Owner Id" := Any.IntegerInRange(10000, 99999); + CreateMetafield(ShpfyMetafield, Any.IntegerInRange(100000, 99999), Database::"Shpfy Customer"); + // [GIVEN] IMetafieldOwnerType + IMetagieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Customer"); + + // [WHEN] Invoke IMetafieldOwnerType.GetTableId + TableId := IMetagieldOwnerType.GetTableId(); + // [THEN] TableId = Database::"Shpfy Customer"; + LibraryAssert.AreEqual(TableId, Database::"Shpfy Customer", 'Table Id is different than Customer'); + end; + [Test] + procedure UnitTestGetShopCodeFromMetafieldOwnerCustomer() + var + ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyCustomer: Record "Shpfy Customer"; + IMetagieldOwnerType: Interface "Shpfy IMetafield Owner Type"; + ShopCode: Code[20]; + begin + // [SCENARIO] Get Shop Code from Metafield Owner Customer codeunit + Initialize(); + // [GIVEN] Shopify Customer + CreateShopifyCustomer(ShpfyCustomer, Shop."Shop Id"); + // [GIVEN] Shopify Metafield created for Customer. + CreateMetafield(ShpfyMetafield, Any.IntegerInRange(100000, 99999), Database::"Shpfy Customer"); + // [GIVEN] IMetafieldOwnerType + IMetagieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Customer"); + + // [WHEN] Invoke IMetafieldOwnerType.GetShopCode + ShopCode := IMetagieldOwnerType.GetShopCode(ShpfyMetafield."Owner Id"); + + // [THEN] ShopCode = Shop.Code; + LibraryAssert.AreEqual(ShopCode, Shop.Code, 'Shop Code is different than Shop'); end; [Test] @@ -72,7 +97,9 @@ codeunit 139616 "Shpfy Customer Metafields Test" // [GIVEN] Shopify Customer CreateShopifyCustomer(ShopifyCustomer, Shop."Shop Id"); - // [GIVEN] Customer + // [GIVEN] Customer metafields + + @@ -86,12 +113,15 @@ codeunit 139616 "Shpfy Customer Metafields Test" if IsInitialized then exit; Shop := ShpfyInitializeTest.CreateShop(); + Any.SetDefaultSeed(); end; local procedure CreateShopifyCustomer(var ShopifyCustomer: Record "Shpfy Customer"; ShopId: BigInteger) begin ShopifyCustomer.Init(); - + ShopifyCustomer.Id := Any.IntegerInRange(100000, 999999); + ShopifyCustomer."Shop Id" := ShopId; + ShopifyCustomer.Insert(true); end; local procedure CreateShopifyMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer) @@ -102,4 +132,12 @@ codeunit 139616 "Shpfy Customer Metafields Test" ShpfyMetafield.Insert(true); end; + local procedure CreateMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer) + begin + ShpfyMetafield.Init(); + ShpfyMetafield."Owner Id" := OwnerId; + ShpfyMetafield."Parent Table No." := OwnerId; + ShpfyMetafield.Insert(true); + end; + } From 9e97378ec2a1f2ed62522b26d99ef884d72faebd Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 14 Oct 2024 14:39:54 +0200 Subject: [PATCH 11/24] add comany tests, create helper codeunit --- .../ShpfyCompanyMetafieldsTest.Codeunit.al | 191 ++++++++++++++++++ .../ShpfyCustomerMetafieldsTest.Codeunit.al | 162 +++++++++------ .../ShpfyMetafieldsHelper.Codeunit.al | 40 ++++ 3 files changed, 336 insertions(+), 57 deletions(-) create mode 100644 Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al create mode 100644 Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al new file mode 100644 index 0000000000..5f07d89d2b --- /dev/null +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al @@ -0,0 +1,191 @@ +codeunit 139617 "Shpfy Company Metafields Test" +{ + Subtype = Test; + TestPermissions = Disabled; + + var + Shop: Record "Shpfy Shop"; + ShpfyCompany: Record "Shpfy Company"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibraryAssert: Codeunit "Library Assert"; + Any: Codeunit Any; + IsInitialized: Boolean; + + trigger OnRun() + begin + IsInitialized := false; + end; + + [Test] + procedure UnitTestGetMetafieldOwnerTypeFromCompanyMetafield() + var + ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + ShpfyMetafieldOwnerType: Enum "Shpfy Metafield Owner Type"; + begin + // [SCENARIO] Get Metafield Owner Type from Company Metafield. + + // [GIVEN] Shopify Metafield created for Company. + ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, Database::"Shpfy Company", Any.IntegerInRange(10000, 99999)); + + // [WHEN] Invoke Metafield.GetOwnerType(); + ShpfyMetafieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Company"); + + // [THEN] ShpfyMetafieldOwnerType = Enum::"Shpfy Metafield Owner Type"::Company; + LibraryAssert.AreEqual(ShpfyMetafieldOwnerType, Enum::"Shpfy Metafield Owner Type"::Company, 'Metafield Owner Type is different than Company'); + end; + + [Test] + procedure UnitTestGetMetafieldOwnerTableId() + var + ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + IMetafieldOwnerType: Interface "Shpfy IMetafield Owner Type"; + TableId: Integer; + begin + // [SCENARIO] Get Metafield Owner Values from Metafield Owner Company codeunit + Initialize(); + + // [GIVEN] Shopify Metafield created for Company. + ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, Any.IntegerInRange(100000, 99999), Database::"Shpfy Company"); + // [GIVEN] IMetafieldOwnerType + IMetafieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Company"); + + // [WHEN] Invoke IMetafieldOwnerType.GetTableId + TableId := IMetafieldOwnerType.GetTableId(); + + // [THEN] TableId = Database::"Shpfy Company"; + LibraryAssert.AreEqual(TableId, Database::"Shpfy Company", 'Table Id is different than Company'); + end; + + [Test] + procedure UnitTestImportCompanyMetafieldFromShopify() + var + ShpfyMetafield: Record "Shpfy Metafield"; + MetafieldAPI: Codeunit "Shpfy Metafield API"; + MetafieldId: BigInteger; + Namespace: Text; + MetafieldKey: Text; + MetafieldValue: Text; + JMetafields: JsonArray; + begin + // [SCENARIO] Import Metafield from Shopify to Business Central + Initialize(); + + // [GIVEN] Response Json with metafield + JMetafields := CreateCompanyMetafieldsResponse(MetafieldId, Namespace, MetafieldKey, MetafieldValue); + + // [WHEN] Invoke MetafieldAPI.UpdateMetafieldsFromShopify + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Company", ShpfyCompany.Id); + + // [THEN] Metafield with MetafieldId, Namespace, MetafieldKey, MetafieldValue is imported to Business Central + ShpfyMetafield.Reset(); + ShpfyMetafield.SetRange("Owner Id", ShpfyCompany.Id); + ShpfyMetafield.SetRange("Parent Table No.", Database::"Shpfy Company"); + + LibraryAssert.IsTrue(ShpfyMetafield.FindFirst(), 'Metafield is not imported to Business Central'); + + LibraryAssert.AreEqual(ShpfyMetafield.Id, MetafieldId, 'Metafield Id is different than imported'); + LibraryAssert.AreEqual(ShpfyMetafield.Namespace, Namespace, 'Namespace is different than imported'); + LibraryAssert.AreEqual(ShpfyMetafield.Name, MetafieldKey, 'Metafield Key is different than imported'); + LibraryAssert.AreEqual(ShpfyMetafield.Value, MetafieldValue, 'Metafield Value is different than imported'); + end; + + [Test] + procedure UnitTestUpdateRemovedCompanyMetafieldFromShopify() + var + ShpfyMetafield: Record "Shpfy Metafield"; + MetafieldAPI: Codeunit "Shpfy Metafield API"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + MetafieldId: BigInteger; + JMetafields: JsonArray; + begin + // [SCENARIO] Update Removed Metafield from Shopify to Business Central + Initialize(); + + // [GIVEN] Shopify Metafield created for Company. + MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShpfyCompany.Id, Database::"Shpfy Company"); + + // [WHEN] Invoke MetafieldAPI.UpdateMetafieldsFromShopify with empty JMetafields + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Company", ShpfyCompany.Id); + + // [THEN] Metafield is removed from Business Central + ShpfyMetafield.Reset(); + ShpfyMetafield.SetRange(Id, MetafieldId); + ShpfyMetafield.SetRange("Owner Id", ShpfyCompany.Id); + ShpfyMetafield.SetRange("Parent Table No.", Database::"Shpfy Company"); + LibraryAssert.IsTrue(ShpfyMetafield.IsEmpty(), 'Metafield is not removed from Business Central'); + end; + + [Test] + procedure UnitTestUpdateCompanyMetafieldFromShopify() + var + ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + MetafieldAPI: Codeunit "Shpfy Metafield API"; + MetafieldId: BigInteger; + Namespace: Text; + MetafieldKey: Text; + MetafieldValue: Text; + JMetafields: JsonArray; + begin + // [SCENARIO] Update Metafield from Shopify to Business Central + Initialize(); + + // [GIVEN] Shopify Metafield with values created for Company. + Namespace := Any.AlphabeticText(10); + MetafieldKey := Any.AlphabeticText(10); + MetafieldValue := Any.AlphabeticText(10); + MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShpfyCompany.Id, Database::"Shpfy Company", Namespace, MetafieldKey, MetafieldValue); + // [GIVEN] Response Json with metafield updated value + JMetafields := ShpfyMetafieldsHelper.CreateMetafieldsResult(MetafieldId, Namespace, 'COMPANY', MetafieldKey, Any.AlphabeticText(10)); + + // [WHEN] Invoke MetafieldAPI.UpdateMetafieldsFromShopify + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Company", ShpfyCompany.Id); + + // [THEN] Metafield with MetafieldId, Namespace, MetafieldKey, MetafieldValue is updated in Business Central + ShpfyMetafield.Reset(); + ShpfyMetafield.SetRange(Id, MetafieldId); + ShpfyMetafield.SetRange("Owner Id", ShpfyCompany.Id); + ShpfyMetafield.SetRange("Parent Table No.", Database::"Shpfy Company"); + LibraryAssert.IsTrue(ShpfyMetafield.FindFirst(), 'Metafield is not updated in Business Central'); + LibraryAssert.AreEqual(ShpfyMetafield.Id, MetafieldId, 'Metafield Id is different than updated'); + LibraryAssert.AreEqual(ShpfyMetafield.Namespace, Namespace, 'Namespace is different than updated'); + LibraryAssert.AreEqual(ShpfyMetafield.Name, MetafieldKey, 'Metafield Key is different than updated'); + LibraryAssert.AreNotEqual(ShpfyMetafield.Value, MetafieldValue, 'Metafield Value is different than updated'); + end; + + local procedure Initialize() + begin + Any.SetDefaultSeed(); + + if IsInitialized then + exit; + Shop := ShpfyInitializeTest.CreateShop(); + CreateShopifyCompany(ShpfyCompany, Shop."Shop Id", Shop.Code); + + Commit(); + + IsInitialized := true; + end; + + local procedure CreateCompanyMetafieldsResponse(var MetafieldId: BigInteger; var Namespace: Text; var MetafieldKey: Text; var MetafieldValue: Text): JsonArray + var + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + begin + MetafieldId := Any.IntegerInRange(100000, 999999); + Namespace := Any.AlphabeticText(10); + MetafieldKey := Any.AlphabeticText(10); + MetafieldValue := Any.AlphabeticText(10); + exit(ShpfyMetafieldsHelper.CreateMetafieldsResult(MetafieldId, Namespace, 'COMPANY', MetafieldKey, MetafieldValue)); + end; + + local procedure CreateShopifyCompany(var ShopifyCompany: Record "Shpfy Company"; ShopId: BigInteger; ShopCode: Code[20]) + begin + ShopifyCompany.Init(); + ShopifyCompany."Shop Id" := ShopId; + ShopifyCompany."Shop Code" := ShopCode; + ShopifyCompany.Name := Any.AlphabeticText(10); + ShopifyCompany.Insert(false); + end; +} diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index ae52bc6bf8..c058de19b3 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -5,10 +5,10 @@ codeunit 139616 "Shpfy Customer Metafields Test" var Shop: Record "Shpfy Shop"; + ShpfyCustomer: Record "Shpfy Customer"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; LibraryAssert: Codeunit "Library Assert"; Any: Codeunit Any; - IsInitialized: Boolean; trigger OnRun() @@ -20,12 +20,13 @@ codeunit 139616 "Shpfy Customer Metafields Test" procedure UnitTestGetMetafieldOwnerTypeFromCustomerMetafield() var ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; ShpfyMetafieldOwnerType: Enum "Shpfy Metafield Owner Type"; begin // [SCENARIO] Get Metafield Owner Type from Customer Metafield. // [GIVEN] Shopify Metafield created for Customer. - CreateShopifyMetafield(ShpfyMetafield, Database::"Shpfy Customer", Any.IntegerInRange(10000, 99999)); + ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, Database::"Shpfy Customer", Any.IntegerInRange(10000, 99999)); // [WHEN] Invoke Metafield.GetOwnerType(); ShpfyMetafieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Customer"); @@ -35,109 +36,156 @@ codeunit 139616 "Shpfy Customer Metafields Test" end; [Test] - procedure UnitTestGetMetafieldOwnerValuesFromMetafieldOwnerCustomer() + procedure UnitTestGetMetafieldOwnerTableId() var ShpfyMetafield: Record "Shpfy Metafield"; - IMetagieldOwnerType: Interface "Shpfy IMetafield Owner Type"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + IMetafieldOwnerType: Interface "Shpfy IMetafield Owner Type"; TableId: Integer; begin - // [SCENARIO] Get Metafield Owner Values from Metafield Owner Company codeunit + // [SCENARIO] Get Metafield Owner Values from Metafield Owner Customer codeunit Initialize(); // [GIVEN] Shopify Metafield created for Customer. - CreateMetafield(ShpfyMetafield, Any.IntegerInRange(100000, 99999), Database::"Shpfy Customer"); + ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, Any.IntegerInRange(100000, 99999), Database::"Shpfy Customer"); // [GIVEN] IMetafieldOwnerType - IMetagieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Customer"); + IMetafieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Customer"); // [WHEN] Invoke IMetafieldOwnerType.GetTableId - TableId := IMetagieldOwnerType.GetTableId(); + TableId := IMetafieldOwnerType.GetTableId(); // [THEN] TableId = Database::"Shpfy Customer"; LibraryAssert.AreEqual(TableId, Database::"Shpfy Customer", 'Table Id is different than Customer'); end; [Test] - procedure UnitTestGetShopCodeFromMetafieldOwnerCustomer() + procedure UnitTestImportCustomerMetafieldFromShopify() var ShpfyMetafield: Record "Shpfy Metafield"; - ShpfyCustomer: Record "Shpfy Customer"; - IMetagieldOwnerType: Interface "Shpfy IMetafield Owner Type"; - ShopCode: Code[20]; + MetafieldAPI: Codeunit "Shpfy Metafield API"; + MetafieldId: BigInteger; + Namespace: Text; + MetafieldKey: Text; + MetafieldValue: Text; + JMetafields: JsonArray; begin - // [SCENARIO] Get Shop Code from Metafield Owner Customer codeunit + // [SCENARIO] Import Metafield from Shopify to Business Central Initialize(); - // [GIVEN] Shopify Customer - CreateShopifyCustomer(ShpfyCustomer, Shop."Shop Id"); - // [GIVEN] Shopify Metafield created for Customer. - CreateMetafield(ShpfyMetafield, Any.IntegerInRange(100000, 99999), Database::"Shpfy Customer"); - // [GIVEN] IMetafieldOwnerType - IMetagieldOwnerType := ShpfyMetafield.GetOwnerType(Database::"Shpfy Customer"); + // [GIVEN] Response Json with metafield + JMetafields := CreateCustomerMetafieldsResponse(MetafieldId, Namespace, MetafieldKey, MetafieldValue); + + // [WHEN] Invoke MetafieldAPI.UpdateMetafieldsFromShopify + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Customer", ShpfyCustomer.Id); - // [WHEN] Invoke IMetafieldOwnerType.GetShopCode - ShopCode := IMetagieldOwnerType.GetShopCode(ShpfyMetafield."Owner Id"); + // [THEN] Metafield with MetafieldId, Namespace, MetafieldKey, MetafieldValue is imported to Business Central + ShpfyMetafield.Reset(); + ShpfyMetafield.SetRange("Owner Id", ShpfyCustomer.Id); + ShpfyMetafield.SetRange("Parent Table No.", Database::"Shpfy Customer"); - // [THEN] ShopCode = Shop.Code; - LibraryAssert.AreEqual(ShopCode, Shop.Code, 'Shop Code is different than Shop'); + LibraryAssert.IsTrue(ShpfyMetafield.FindFirst(), 'Metafield is not imported to Business Central'); + + LibraryAssert.AreEqual(ShpfyMetafield.Id, MetafieldId, 'Metafield Id is different than imported'); + LibraryAssert.AreEqual(ShpfyMetafield.Namespace, Namespace, 'Namespace is different than imported'); + LibraryAssert.AreEqual(ShpfyMetafield.Name, MetafieldKey, 'Metafield Key is different than imported'); + LibraryAssert.AreEqual(ShpfyMetafield.Value, MetafieldValue, 'Metafield Value is different than imported'); end; [Test] - procedure UnitTestExportMetafieldsToShopify() + procedure UnitTestUpdateRemovedCustomerMetafieldFromShopify() var - Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; - CustomerAddress: Record "Shpfy Customer Address"; - Shop: Record "Shpfy Shop"; ShpfyMetafield: Record "Shpfy Metafield"; - InitializeTest: Codeunit "Shpfy Initialize Test"; - Result: Boolean; + MetafieldAPI: Codeunit "Shpfy Metafield API"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + MetafieldId: BigInteger; + JMetafields: JsonArray; begin - // [SCENARIO] Export Customer metafields to Shopify. + // [SCENARIO] Update Removed Metafield from Shopify to Business Central Initialize(); - // [GIVEN] Shopify Customer - CreateShopifyCustomer(ShopifyCustomer, Shop."Shop Id"); - // [GIVEN] Customer metafields - - + // [GIVEN] Shopify Metafield created for Customer. + MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShpfyCustomer.Id, Database::"Shpfy Customer"); + // [WHEN] Invoke MetafieldAPI.UpdateMetafieldsFromShopify with empty JMetafields + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Customer", ShpfyCustomer.Id); + // [THEN] Metafield is removed from Business Central + ShpfyMetafield.Reset(); + ShpfyMetafield.SetRange(Id, MetafieldId); + ShpfyMetafield.SetRange("Owner Id", ShpfyCustomer.Id); + ShpfyMetafield.SetRange("Parent Table No.", Database::"Shpfy Customer"); + LibraryAssert.IsTrue(ShpfyMetafield.IsEmpty(), 'Metafield is not removed from Business Central'); + end; - // [WHEN] Invoke MetafieldAPI.CreateOrUpdateMetafieldsInShopify(Database::"Shpfy Customer", CustomerId); + [Test] + procedure UnitTestUpdateCustomerMetafieldFromShopify() + var + ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + MetafieldAPI: Codeunit "Shpfy Metafield API"; + MetafieldId: BigInteger; + Namespace: Text; + MetafieldKey: Text; + MetafieldValue: Text; + JMetafields: JsonArray; + begin + // [SCENARIO] Update Metafield from Shopify to Business Central + Initialize(); - // [THEN] + // [GIVEN] Shopify Metafield with values created for Customer. + Namespace := Any.AlphabeticText(10); + MetafieldKey := Any.AlphabeticText(10); + MetafieldValue := Any.AlphabeticText(10); + MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShpfyCustomer.Id, Database::"Shpfy Customer", Namespace, MetafieldKey, MetafieldValue); + // [GIVEN] Response Json with metafield updated value + JMetafields := ShpfyMetafieldsHelper.CreateMetafieldsResult(MetafieldId, Namespace, 'CUSTOMER', MetafieldKey, Any.AlphabeticText(10)); + + // [WHEN] Invoke MetafieldAPI.UpdateMetafieldsFromShopify + MetafieldAPI.UpdateMetafieldsFromShopify(JMetafields, Database::"Shpfy Customer", ShpfyCustomer.Id); + + // [THEN] Metafield with MetafieldId, Namespace, MetafieldKey, MetafieldValue is updated in Business Central + ShpfyMetafield.Reset(); + ShpfyMetafield.SetRange(Id, MetafieldId); + ShpfyMetafield.SetRange("Owner Id", ShpfyCustomer.Id); + ShpfyMetafield.SetRange("Parent Table No.", Database::"Shpfy Customer"); + LibraryAssert.IsTrue(ShpfyMetafield.FindFirst(), 'Metafield is not updated in Business Central'); + LibraryAssert.AreEqual(ShpfyMetafield.Id, MetafieldId, 'Metafield Id is different than updated'); + LibraryAssert.AreEqual(ShpfyMetafield.Namespace, Namespace, 'Namespace is different than updated'); + LibraryAssert.AreEqual(ShpfyMetafield.Name, MetafieldKey, 'Metafield Key is different than updated'); + LibraryAssert.AreNotEqual(ShpfyMetafield.Value, MetafieldValue, 'Metafield Value is different than updated'); end; local procedure Initialize() begin + Any.SetDefaultSeed(); + if IsInitialized then exit; Shop := ShpfyInitializeTest.CreateShop(); - Any.SetDefaultSeed(); - end; + CreateShopifyCustomer(ShpfyCustomer, Shop."Shop Id"); - local procedure CreateShopifyCustomer(var ShopifyCustomer: Record "Shpfy Customer"; ShopId: BigInteger) - begin - ShopifyCustomer.Init(); - ShopifyCustomer.Id := Any.IntegerInRange(100000, 999999); - ShopifyCustomer."Shop Id" := ShopId; - ShopifyCustomer.Insert(true); + Commit(); + + IsInitialized := true; end; - local procedure CreateShopifyMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer) + local procedure CreateCustomerMetafieldsResponse(var MetafieldId: BigInteger; var Namespace: Text; var MetafieldKey: Text; var MetafieldValue: Text): JsonArray + var + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; begin - ShpfyMetafield.Init(); - ShpfyMetafield."Owner Id" := OwnerId; - ShpfyMetafield.Validate("Parent Table No.", ParentTableId); - ShpfyMetafield.Insert(true); + MetafieldId := Any.IntegerInRange(100000, 999999); + Namespace := Any.AlphabeticText(10); + MetafieldKey := Any.AlphabeticText(10); + MetafieldValue := Any.AlphabeticText(10); + exit(ShpfyMetafieldsHelper.CreateMetafieldsResult(MetafieldId, Namespace, 'CUSTOMER', MetafieldKey, MetafieldValue)); end; - local procedure CreateMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer) + local procedure CreateShopifyCustomer(var ShopifyCustomer: Record "Shpfy Customer"; ShopId: BigInteger) begin - ShpfyMetafield.Init(); - ShpfyMetafield."Owner Id" := OwnerId; - ShpfyMetafield."Parent Table No." := OwnerId; - ShpfyMetafield.Insert(true); + Any.SetDefaultSeed(); + ShopifyCustomer.Init(); + ShopifyCustomer.Id := Any.IntegerInRange(100000, 999999); + ShopifyCustomer."Shop Id" := ShopId; + ShopifyCustomer.Insert(false); end; - } diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al new file mode 100644 index 0000000000..25d22abdad --- /dev/null +++ b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al @@ -0,0 +1,40 @@ +codeunit 139614 "Shpfy Metafields Helper" +{ + procedure CreateMetafieldsResult(ResourceID: BigInteger; Namespace: Text; OwnerType: Text; MetafieldKey: Text; MetafieldValue: Text): JsonArray + var + JNode: JsonObject; + JObject: JsonObject; + JMetafields: JsonArray; + begin + JNode.Add('id', StrSubstNo('gid://shopify/Metafield/%2', ResourceID)); + JNode.Add('namespace', Namespace); + JNode.Add('ownerType', OwnerType); + JNode.Add('legacyResourceId', ResourceID); + JNode.Add('key', MetafieldKey); + JNode.Add('value', MetafieldValue); + JNode.Add('type', 'string'); + JObject.Add('node', JNode); + JMetafields.Add(JObject); + exit(JMetafields); + end; + + + + + procedure CreateMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer): BigInteger + begin + exit(CreateMetafield(ShpfyMetafield, OwnerId, ParentTableId, '', '', '')); + end; + + procedure CreateMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer; Namespace: Text; Name: Text; Value: Text): BigInteger + begin + ShpfyMetafield.Init(); + ShpfyMetafield."Owner Id" := OwnerId; + ShpfyMetafield."Parent Table No." := ParentTableId; + ShpfyMetafield.Namespace := Namespace; + ShpfyMetafield.Name := Name; + ShpfyMetafield.Insert(true); + exit(ShpfyMetafield.Id); + end; + +} From cc728224618c4abbd57a7a91cce4b2eaa9c6a388 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 21 Oct 2024 09:32:43 +0200 Subject: [PATCH 12/24] remove empty spaces --- .../Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al | 3 --- 1 file changed, 3 deletions(-) diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al index 25d22abdad..93d7b90ef4 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al @@ -18,9 +18,6 @@ codeunit 139614 "Shpfy Metafields Helper" exit(JMetafields); end; - - - procedure CreateMetafield(var ShpfyMetafield: Record "Shpfy Metafield"; OwnerId: BigInteger; ParentTableId: Integer): BigInteger begin exit(CreateMetafield(ShpfyMetafield, OwnerId, ParentTableId, '', '', '')); From abf978e072202529027dd8c6f04d1ffdb4767415 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 21 Oct 2024 16:25:27 +0200 Subject: [PATCH 13/24] pr fix, add page editable function to metafield owner interface --- .../ShpfyGQLCompanyMetafieldIds.Codeunit.al | 2 ++ .../ShpfyMetafieldOwnerCompany.Codeunit.al | 5 +++++ .../ShpfyMetafieldOwnerCustomer.Codeunit.al | 5 +++++ .../ShpfyMetafieldOwnerProduct.Codeunit.al | 5 +++++ .../ShpfyMetafieldOwnerVariant.Codeunit.al | 5 +++++ .../Interfaces/ShpfyIMetafieldOwnerType.Interface.al | 7 +++++++ .../app/src/Metafields/Pages/ShpfyMetafields.Page.al | 12 +++--------- 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al index 9b2d6a7aec..fd2bbc0c1a 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al @@ -5,6 +5,8 @@ namespace Microsoft.Integration.Shopify; /// codeunit 30215 "Shpfy GQL CompanyMetafieldIds" implements "Shpfy IGraphQL" { + Access = Internal; + /// /// GetGraphQL. /// diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al index d6a5210818..47bd8b6c18 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al @@ -41,4 +41,9 @@ codeunit 30313 "Shpfy Metafield Owner Company" implements "Shpfy IMetafield Owne exit(Company."Shop Code"); end; + procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + begin + exit(Shop."Can Update Shopify Companies"); + end; + } diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al index 73e3c81149..14c4472217 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al @@ -42,4 +42,9 @@ codeunit 30333 "Shpfy Metafield Owner Customer" implements "Shpfy IMetafield Own Shop.FindFirst(); exit(Shop.Code); end; + + procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + begin + exit(Shop."Can Update Shopify Customer"); + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al index 3998b83f29..97d15c2fa4 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al @@ -39,4 +39,9 @@ codeunit 30334 "Shpfy Metafield Owner Product" implements "Shpfy IMetafield Owne Product.Get(OwnerId); exit(Product."Shop Code"); end; + + procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + begin + exit((Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products")); + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al index 3a9ff1e4b0..68981534aa 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al @@ -39,4 +39,9 @@ codeunit 30335 "Shpfy Metafield Owner Variant" implements "Shpfy IMetafield Owne Variant.Get(OwnerId); exit(Variant."Shop Code"); end; + + procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + begin + exit((Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products")); + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al b/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al index f11f3540f7..a59f9406aa 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al +++ b/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al @@ -26,4 +26,11 @@ interface "Shpfy IMetafield Owner Type" /// Id of the owner resource. /// Shop code. procedure GetShopCode(OwnerId: BigInteger): Code[20] + + /// + /// Retrieves the boolean value indicating whether the metafields page is editable. + /// + /// Shop record. + /// Boolean. + procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al index b82c9ae7f3..f4cefb1c2f 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al +++ b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al @@ -91,18 +91,12 @@ page 30163 "Shpfy Metafields" internal procedure RunForResource(ParentTableId: Integer; OwnerId: BigInteger; ShopCode: Code[20]) var Metafield: Record "Shpfy Metafield"; - OwnerType: Enum "Shpfy Metafield Owner Type"; + IMetafieldOwnerType: Interface "Shpfy IMetafield Owner Type"; begin Shop.Get(ShopCode); - case Metafield.GetOwnerType(ParentTableId) of - OwnerType::Product, OwnerType::ProductVariant: - IsPageEditable := (Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products"); - OwnerType::Customer: - IsPageEditable := Shop."Can Update Shopify Customer"; - OwnerType::Company: - IsPageEditable := Shop."Can Update Shopify Companies"; - end; + IMetafieldOwnerType := Metafield.GetOwnerType(ParentTableId); + IsPageEditable := IMetafieldOwnerType.GetMetafieldsPageEditable(Shop); Metafield.SetRange("Parent Table No.", ParentTableId); Metafield.SetRange("Owner Id", OwnerId); From 33dee95ac13cbf60dab4ab62025c90a8a1a9665b Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 21 Oct 2024 16:49:14 +0200 Subject: [PATCH 14/24] change procedure name and summary --- .../IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al | 2 +- .../IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al | 2 +- .../IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al | 2 +- .../IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al | 2 +- .../Interfaces/ShpfyIMetafieldOwnerType.Interface.al | 4 ++-- .../Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al index 47bd8b6c18..d9cdf1303b 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al @@ -41,7 +41,7 @@ codeunit 30313 "Shpfy Metafield Owner Company" implements "Shpfy IMetafield Owne exit(Company."Shop Code"); end; - procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean begin exit(Shop."Can Update Shopify Companies"); end; diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al index 14c4472217..0f4713b44d 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al @@ -43,7 +43,7 @@ codeunit 30333 "Shpfy Metafield Owner Customer" implements "Shpfy IMetafield Own exit(Shop.Code); end; - procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean begin exit(Shop."Can Update Shopify Customer"); end; diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al index 97d15c2fa4..998a98036d 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerProduct.Codeunit.al @@ -40,7 +40,7 @@ codeunit 30334 "Shpfy Metafield Owner Product" implements "Shpfy IMetafield Owne exit(Product."Shop Code"); end; - procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean begin exit((Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products")); end; diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al index 68981534aa..66b98ebf03 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerVariant.Codeunit.al @@ -40,7 +40,7 @@ codeunit 30335 "Shpfy Metafield Owner Variant" implements "Shpfy IMetafield Owne exit(Variant."Shop Code"); end; - procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean begin exit((Shop."Sync Item" = Shop."Sync Item"::"To Shopify") and (Shop."Can Update Shopify Products")); end; diff --git a/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al b/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al index a59f9406aa..56ab97b4e1 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al +++ b/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al @@ -28,9 +28,9 @@ interface "Shpfy IMetafield Owner Type" procedure GetShopCode(OwnerId: BigInteger): Code[20] /// - /// Retrieves the boolean value indicating whether the metafields page is editable. + /// Indicates if metafields can be edited. /// /// Shop record. /// Boolean. - procedure GetMetafieldsPageEditable(Shop: Record "Shpfy Shop"): Boolean + procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al index f4cefb1c2f..dcf63aba86 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al +++ b/Apps/W1/Shopify/app/src/Metafields/Pages/ShpfyMetafields.Page.al @@ -96,7 +96,7 @@ page 30163 "Shpfy Metafields" Shop.Get(ShopCode); IMetafieldOwnerType := Metafield.GetOwnerType(ParentTableId); - IsPageEditable := IMetafieldOwnerType.GetMetafieldsPageEditable(Shop); + IsPageEditable := IMetafieldOwnerType.CanEditMetafields(Shop); Metafield.SetRange("Parent Table No.", ParentTableId); Metafield.SetRange("Owner Id", OwnerId); From cfb030206cc0780e9f97e8e295a74f59b0c09c31 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 22 Oct 2024 07:50:24 +0200 Subject: [PATCH 15/24] renumber objects --- .../Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al index 93d7b90ef4..efbf302592 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139614 "Shpfy Metafields Helper" +codeunit 139618 "Shpfy Metafields Helper" { procedure CreateMetafieldsResult(ResourceID: BigInteger; Namespace: Text; OwnerType: Text; MetafieldKey: Text; MetafieldValue: Text): JsonArray var From b86173dcd23b26922dacee47ed962cb1dd73952b Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 22 Oct 2024 16:29:38 +0200 Subject: [PATCH 16/24] sending metafields test in progress --- .../ShpfyCompanyMetafieldsTest.Codeunit.al | 4 + .../ShpfyCustomerMetafieldsSubs.Codeunit.al | 92 +++++++++++++++++++ .../ShpfyCustomerMetafieldsTest.Codeunit.al | 62 +++++++++++++ .../ShpfyMetafieldsHelper.Codeunit.al | 1 + 4 files changed, 159 insertions(+) create mode 100644 Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al index 5f07d89d2b..ac666ae7ec 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al @@ -155,6 +155,10 @@ codeunit 139617 "Shpfy Company Metafields Test" LibraryAssert.AreNotEqual(ShpfyMetafield.Value, MetafieldValue, 'Metafield Value is different than updated'); end; + // [Test] + // procedure UnitTestUpdateCompanyMetafieldsInShopify() + // va + local procedure Initialize() begin Any.SetDefaultSeed(); diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al new file mode 100644 index 0000000000..807903aaea --- /dev/null +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al @@ -0,0 +1,92 @@ +codeunit 139581 "Shpfy Customer Metafields Subs" +{ + EventSubscriberInstance = Manual; + + var + ShopifyCustomerId: BigInteger; + GQLQueryTxt: Text; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnClientSend', '', true, false)] + local procedure OnClientSend(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + begin + MakeResponse(HttpRequestMessage, HttpResponseMessage); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnGetContent', '', true, false)] + local procedure OnGetContent(HttpResponseMessage: HttpResponseMessage; var Response: Text) + begin + HttpResponseMessage.Content.ReadAs(Response); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Customer Events", OnBeforeFindMapping, '', true, false)] + local procedure OnBeforeFindMapping(var Handled: Boolean; var ShopifyCustomer: Record "Shpfy Customer") + begin + ShopifyCustomer.Id := ShopifyCustomerId; + Handled := true; + end; + + local procedure MakeResponse(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + var + Uri: Text; + GraphQlQuery: Text; + GetCustomersGQLMsg: Label '{"query":"{customers(first:100){pageInfo{endCursor hasNextPage} nodes{ legacyResourceId }}}"}', Locked = true; + ModifyCustomerGQLStartTok: Label '{"query":"mutation {customerUpdate(input: {id: \"gid://shopify/Customer/', Locked = true; + GetCustomerMetafieldsGQLStartTok: Label '{"query":"{customer(id: \"gid://shopify/Customer/', Locked = true; + GetCustomerMetafieldsGQLEndTok: Label '\") { metafields(first: 50) {edges {node {legacyResourceId updatedAt}}}}}"}', Locked = true; + CreateMetafieldsGQLStartTok: Label '{"query": "mutation { metafieldsSet(metafields: ', Locked = true; + GraphQLCmdTxt: Label '/graphql.json', Locked = true; + begin + case HttpRequestMessage.Method of + 'POST': + begin + Uri := HttpRequestMessage.GetRequestUri(); + if Uri.EndsWith(GraphQLCmdTxt) then + if HttpRequestMessage.Content.ReadAs(GraphQlQuery) then + case true of + GraphQlQuery.Contains(GetCustomersGQLMsg): + HttpResponseMessage := GetCustomersResult(); + GraphQlQuery.StartsWith(ModifyCustomerGQLStartTok): + HttpResponseMessage := GetEmptyResponse(); + GraphQlQuery.StartsWith(GetCustomerMetafieldsGQLStartTok) and GraphQlQuery.EndsWith(GetCustomerMetafieldsGQLEndTok): + HttpResponseMessage := GetEmptyResponse(); + GraphQlQuery.StartsWith(CreateMetafieldsGQLStartTok): + begin + HttpResponseMessage := GetEmptyResponse(); + GQLQueryTxt := GraphQlQuery; + end; + end; + end; + end; + end; + + local procedure GetCustomersResult(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{ "data": { "customers": { "pageInfo": { "hasNextPage": false }, "edges": [] } }, "extensions": { "cost": { "requestedQueryCost": 12, "actualQueryCost": 2, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1998, "restoreRate": 100 } } } }'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + local procedure GetEmptyResponse(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{}'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + internal procedure SetShopifyCustomerId(Id: BigInteger) + begin + ShopifyCustomerId := Id; + end; + + internal procedure GetGQLQuery(): Text + begin + exit(GQLQueryTxt); + end; + +} diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index c058de19b3..6d71522b7d 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -155,6 +155,68 @@ codeunit 139616 "Shpfy Customer Metafields Test" LibraryAssert.AreNotEqual(ShpfyMetafield.Value, MetafieldValue, 'Metafield Value is different than updated'); end; + [Test] + procedure UnitTestUpdateCustomerMetafieldInShopfiy() + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; + ShpfyMetafield: Record "Shpfy Metafield"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + MetafieldAPI: Codeunit "Shpfy Metafield API"; + CustomerMetafieldsSubs: Codeunit "Shpfy Customer Metafields Subs"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + MetafieldId: BigInteger; + Namespace: Text; + MetafieldKey: Text; + MetafieldValue: Text; + JMetafields: JsonArray; + ActualQuery: Text; + begin + // [SCENARIO] Update Metafield from Business Central to Shopify + Initialize(); + + //[GIVEN] Shop with Can update Shopify Customer = true + Shop."Can Update Shopify Customer" := true; + Shop.Modify(false); + + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify Customer + ShopifyCustomer.Init(); + ShopifyCustomer.Id := Any.IntegerInRange(100000, 999999); + ShopifyCustomer."Shop Id" := Shop."Shop Id"; + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer."First Name" := Any.AlphabeticText(100); + ShopifyCustomer."Last Name" := Any.AlphabeticText(100); + ShopifyCustomer.Email := Customer."E-Mail"; + ShopifyCustomer.Insert(false); + + // [GIVEN] Shopify Customer Address + CustomerInitTest.CreateShopifyCustomerAddress(ShopifyCustomer); + + // [GIVEN] Shopify Metafield with values created for Customer. + Namespace := Any.AlphabeticText(10); + MetafieldKey := Any.AlphabeticText(10); + MetafieldValue := Any.AlphabeticText(10); + MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShopifyCustomer.Id, Database::"Shpfy Customer", Namespace, MetafieldKey, MetafieldValue); + + // [WHEN] Invoke ShopifyCustomerExport + BindSubscription(CustomerMetafieldsSubs); + CustomerMetafieldsSubs.SetShopifyCustomerId(ShopifyCustomer.Id); + ShpfyCustomerExport.SetShop(Shop); + Customer.SetRange("No.", Customer."No."); + ShpfyCustomerExport.Run(Customer); + ActualQuery := CustomerMetafieldsSubs.GetGQLQuery(); + UnbindSubscription(CustomerMetafieldsSubs); + + // [THEN] Query for udpating metafields in shopify is sended + LibraryAssert.IsTrue(ActualQuery.Contains(StrSubstNo('key: \"%1\"', MetafieldKey)), 'Query does not contain Metafield Key'); + LibraryAssert.IsTrue(ActualQuery.Contains(StrSubstNo('value: \"%1\"', MetafieldValue)), 'Query does not contain Metafield Value'); + LibraryAssert.IsTrue(ActualQuery.Contains(StrSubstNo('namespace: \"%1\"', Namespace)), 'Query does not contain Namespace'); + LibraryAssert.IsTrue(ActualQuery.Contains(StrSubstNo('ownerId: \"gid://shopify/Customer/%1\"', ShopifyCustomer.Id)), 'Query does not contain Owner Id'); + end; + local procedure Initialize() begin Any.SetDefaultSeed(); diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al index efbf302592..f2755f1c47 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al @@ -30,6 +30,7 @@ codeunit 139618 "Shpfy Metafields Helper" ShpfyMetafield."Parent Table No." := ParentTableId; ShpfyMetafield.Namespace := Namespace; ShpfyMetafield.Name := Name; + ShpfyMetafield.Value := Value; ShpfyMetafield.Insert(true); exit(ShpfyMetafield.Id); end; From 7ae95756d34d921356389a1029a4a144e4ef5228 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 22 Oct 2024 16:50:18 +0200 Subject: [PATCH 17/24] refactor export metafields test --- .../ShpfyCustomerMetafieldsTest.Codeunit.al | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index 6d71522b7d..ec9d138a5f 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -160,17 +160,13 @@ codeunit 139616 "Shpfy Customer Metafields Test" var Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; - ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; ShpfyMetafield: Record "Shpfy Metafield"; ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; - MetafieldAPI: Codeunit "Shpfy Metafield API"; - CustomerMetafieldsSubs: Codeunit "Shpfy Customer Metafields Subs"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; MetafieldId: BigInteger; Namespace: Text; MetafieldKey: Text; MetafieldValue: Text; - JMetafields: JsonArray; ActualQuery: Text; begin // [SCENARIO] Update Metafield from Business Central to Shopify @@ -183,14 +179,7 @@ codeunit 139616 "Shpfy Customer Metafields Test" // [GIVEN] Customer Customer := ShpfyInitializeTest.GetDummyCustomer(); // [GIVEN] Shopify Customer - ShopifyCustomer.Init(); - ShopifyCustomer.Id := Any.IntegerInRange(100000, 999999); - ShopifyCustomer."Shop Id" := Shop."Shop Id"; - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer."First Name" := Any.AlphabeticText(100); - ShopifyCustomer."Last Name" := Any.AlphabeticText(100); - ShopifyCustomer.Email := Customer."E-Mail"; - ShopifyCustomer.Insert(false); + CreateShopifyCustomer(Customer, ShopifyCustomer); // [GIVEN] Shopify Customer Address CustomerInitTest.CreateShopifyCustomerAddress(ShopifyCustomer); @@ -202,15 +191,9 @@ codeunit 139616 "Shpfy Customer Metafields Test" MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShopifyCustomer.Id, Database::"Shpfy Customer", Namespace, MetafieldKey, MetafieldValue); // [WHEN] Invoke ShopifyCustomerExport - BindSubscription(CustomerMetafieldsSubs); - CustomerMetafieldsSubs.SetShopifyCustomerId(ShopifyCustomer.Id); - ShpfyCustomerExport.SetShop(Shop); - Customer.SetRange("No.", Customer."No."); - ShpfyCustomerExport.Run(Customer); - ActualQuery := CustomerMetafieldsSubs.GetGQLQuery(); - UnbindSubscription(CustomerMetafieldsSubs); + InvokeShopifyCustomerExport(Customer, ShopifyCustomer, ActualQuery); - // [THEN] Query for udpating metafields in shopify is sended + // [THEN] Correct Query for updating metafields in shopify is sent LibraryAssert.IsTrue(ActualQuery.Contains(StrSubstNo('key: \"%1\"', MetafieldKey)), 'Query does not contain Metafield Key'); LibraryAssert.IsTrue(ActualQuery.Contains(StrSubstNo('value: \"%1\"', MetafieldValue)), 'Query does not contain Metafield Value'); LibraryAssert.IsTrue(ActualQuery.Contains(StrSubstNo('namespace: \"%1\"', Namespace)), 'Query does not contain Namespace'); @@ -250,4 +233,30 @@ codeunit 139616 "Shpfy Customer Metafields Test" ShopifyCustomer."Shop Id" := ShopId; ShopifyCustomer.Insert(false); end; + + local procedure CreateShopifyCustomer(var Customer: Record Customer; var ShopifyCustomer: Record "Shpfy Customer") + begin + ShopifyCustomer.Init(); + ShopifyCustomer.Id := Any.IntegerInRange(100000, 999999); + ShopifyCustomer."Shop Id" := Shop."Shop Id"; + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer."First Name" := Any.AlphabeticText(100); + ShopifyCustomer."Last Name" := Any.AlphabeticText(100); + ShopifyCustomer.Email := Customer."E-Mail"; + ShopifyCustomer.Insert(false); + end; + + local procedure InvokeShopifyCustomerExport(var Customer: Record Customer; var ShopifyCustomer: Record "Shpfy Customer"; var ActualQuery: Text) + var + ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; + CustomerMetafieldsSubs: Codeunit "Shpfy Customer Metafields Subs"; + begin + BindSubscription(CustomerMetafieldsSubs); + CustomerMetafieldsSubs.SetShopifyCustomerId(ShopifyCustomer.Id); + ShpfyCustomerExport.SetShop(Shop); + Customer.SetRange("No.", Customer."No."); + ShpfyCustomerExport.Run(Customer); + ActualQuery := CustomerMetafieldsSubs.GetGQLQuery(); + UnbindSubscription(CustomerMetafieldsSubs); + end; } From 6175567f50cb0316ed93a044aff4c4d6f94d058b Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 22 Oct 2024 19:33:31 +0200 Subject: [PATCH 18/24] add company export metafields test --- .../ShpfyCompanyMetafieldsSubs.Codeunit.al | 69 +++++++++++++++++ .../ShpfyCompanyMetafieldsTest.Codeunit.al | 76 +++++++++++++++++-- .../ShpfyCustomerMetafieldsTest.Codeunit.al | 6 +- .../ShpfyMetafieldsHelper.Codeunit.al | 2 +- 4 files changed, 142 insertions(+), 11 deletions(-) create mode 100644 Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al new file mode 100644 index 0000000000..17d5b249fc --- /dev/null +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al @@ -0,0 +1,69 @@ +codeunit 139583 "Shpfy Company Metafields Subs" +{ + EventSubscriberInstance = Manual; + + var + GQLQueryTxt: Text; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnClientSend', '', true, false)] + local procedure OnClientSend(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + begin + MakeResponse(HttpRequestMessage, HttpResponseMessage); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnGetContent', '', true, false)] + local procedure OnGetContent(HttpResponseMessage: HttpResponseMessage; var Response: Text) + begin + HttpResponseMessage.Content.ReadAs(Response); + end; + + local procedure MakeResponse(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + var + Uri: Text; + GraphQlQuery: Text; + ModifyCompanyLocationGQLStartTok: Label '{"query":"mutation {companyLocationAssignAddress(locationId: \"gid://shopify/CompanyLocation/', Locked = true; + ModifyCompanyGQLStartTok: Label '{"query":"mutation {companyUpdate(companyId: \"gid://shopify/Company/', Locked = true; + GetCompanyMetafieldsGQLStartTok: Label '{"query":"{company(id: \"gid://shopify/Company/', Locked = true; + GetCompanyMetafieldsGQLEndTok: Label '\") {metafields(first: 50) {edges {node {id namespace ownerType legacyResourceId }}}}}"}', Locked = true; + CreateMetafieldsGQLStartTok: Label '{"query": "mutation { metafieldsSet(metafields: ', Locked = true; + GraphQLCmdTxt: Label '/graphql.json', Locked = true; + begin + case HttpRequestMessage.Method of + 'POST': + begin + Uri := HttpRequestMessage.GetRequestUri(); + if Uri.EndsWith(GraphQLCmdTxt) then + if HttpRequestMessage.Content.ReadAs(GraphQlQuery) then + case true of + GraphQlQuery.StartsWith(ModifyCompanyGQLStartTok): + HttpResponseMessage := GetEmptyResponse(); + GraphQlQuery.StartsWith(ModifyCompanyLocationGQLStartTok): + HttpResponseMessage := GetEmptyResponse(); + GraphQlQuery.StartsWith(GetCompanyMetafieldsGQLStartTok) and GraphQlQuery.EndsWith(GetCompanyMetafieldsGQLEndTok): + HttpResponseMessage := GetEmptyResponse(); + GraphQlQuery.StartsWith(CreateMetafieldsGQLStartTok): + begin + HttpResponseMessage := GetEmptyResponse(); + GQLQueryTxt := GraphQlQuery; + end; + end; + end; + end; + end; + + local procedure GetEmptyResponse(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{}'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + internal procedure GetGQLQuery(): Text + begin + exit(GQLQueryTxt); + end; + +} diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al index ac666ae7ec..d3d99a1aa7 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al @@ -155,9 +155,50 @@ codeunit 139617 "Shpfy Company Metafields Test" LibraryAssert.AreNotEqual(ShpfyMetafield.Value, MetafieldValue, 'Metafield Value is different than updated'); end; - // [Test] - // procedure UnitTestUpdateCompanyMetafieldsInShopify() - // va + [Test] + procedure UnitTestExportCompanyMetafieldToShopify() + var + Customer: Record Customer; + ShpfyMetafield: Record "Shpfy Metafield"; + ShopifyCompany: Record "Shpfy Company"; + ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; + MetafieldId: BigInteger; + Namespace: Text; + MetafieldKey: Text; + MetafieldValue: Text; + ActualQueryTxt: Text; + begin + // [SCENARIO] Export Metafield from Business Central to Shopify + Initialize(); + + // [GIVEN] Shop Can Update Shopify Companies = true + Shop."Can Update Shopify Companies" := true; + Shop.Modify(false); + + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + + // [GIVEN] Shopify Company , crea for Customer + CreateShopifyCompany(ShopifyCompany, Shop."Shop Id", Shop.Code, Customer.SystemId); + + // [GIVEN] Shopify Company Location + CreateShopifyCompanyLocation(ShopifyCompany); + + // [GIVEN] Shopify Metafield with values created for Company. + Namespace := Any.AlphabeticText(10); + MetafieldKey := Any.AlphabeticText(10); + MetafieldValue := Any.AlphabeticText(10); + MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShopifyCompany.Id, Database::"Shpfy Company", Namespace, MetafieldKey, MetafieldValue); + + // [WHEN] Invoke ExportCompany codeunit for company + InvokeExportCompany(Customer, ActualQueryTxt); + + // [THEN] Correct GraphQL query is created and sent to Shopify + LibraryAssert.IsTrue(ActualQueryTxt.Contains(StrSubstNo('key: \"%1\"', MetafieldKey)), 'Query does not contain Metafield Key'); + LibraryAssert.IsTrue(ActualQueryTxt.Contains(StrSubstNo('value: \"%1\"', MetafieldValue)), 'Query does not contain Metafield Value'); + LibraryAssert.IsTrue(ActualQueryTxt.Contains(StrSubstNo('namespace: \"%1\"', Namespace)), 'Query does not contain Namespace'); + LibraryAssert.IsTrue(ActualQueryTxt.Contains(StrSubstNo('ownerId: \"gid://shopify/Company/%1\"', ShopifyCompany.Id)), 'Query does not contain Owner Id'); + end; local procedure Initialize() begin @@ -166,7 +207,7 @@ codeunit 139617 "Shpfy Company Metafields Test" if IsInitialized then exit; Shop := ShpfyInitializeTest.CreateShop(); - CreateShopifyCompany(ShpfyCompany, Shop."Shop Id", Shop.Code); + CreateShopifyCompany(ShpfyCompany, Shop."Shop Id", Shop.Code, CreateGuid()); Commit(); @@ -184,12 +225,37 @@ codeunit 139617 "Shpfy Company Metafields Test" exit(ShpfyMetafieldsHelper.CreateMetafieldsResult(MetafieldId, Namespace, 'COMPANY', MetafieldKey, MetafieldValue)); end; - local procedure CreateShopifyCompany(var ShopifyCompany: Record "Shpfy Company"; ShopId: BigInteger; ShopCode: Code[20]) + local procedure CreateShopifyCompany(var ShopifyCompany: Record "Shpfy Company"; ShopId: BigInteger; ShopCode: Code[20]; CustomerSystemId: Guid) begin ShopifyCompany.Init(); + ShopifyCompany.Id := Any.IntegerInRange(100000, 999999); ShopifyCompany."Shop Id" := ShopId; ShopifyCompany."Shop Code" := ShopCode; ShopifyCompany.Name := Any.AlphabeticText(10); + ShopifyCompany."Customer SystemId" := CustomerSystemId; ShopifyCompany.Insert(false); end; + + local procedure CreateShopifyCompanyLocation(ShopifyCompany: Record "Shpfy Company") + var + ShpfyCompanyLocation: Record "Shpfy Company Location"; + begin + ShpfyCompanyLocation.Init(); + ShpfyCompanyLocation.Id := Any.IntegerInRange(100000, 999999); + ShpfyCompanyLocation."Company SystemId" := ShopifyCompany.SystemId; + ShpfyCompanyLocation.Insert(false); + end; + + local procedure InvokeExportCompany(var Customer: Record Customer; var ActualQueryTxt: Text) + var + CompanyMetafieldsSubs: Codeunit "Shpfy Company Metafields Subs"; + CompanyExport: Codeunit "Shpfy Company Export"; + begin + BindSubscription(CompanyMetafieldsSubs); + Customer.SetRange("No.", Customer."No."); + CompanyExport.SetShop(Shop.Code); + CompanyExport.Run(Customer); + ActualQueryTxt := CompanyMetafieldsSubs.GetGQLQuery(); + UnbindSubscription(CompanyMetafieldsSubs); + end; } diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index ec9d138a5f..9152414d38 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -163,7 +163,6 @@ codeunit 139616 "Shpfy Customer Metafields Test" ShpfyMetafield: Record "Shpfy Metafield"; ShpfyMetafieldsHelper: Codeunit "Shpfy Metafields Helper"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; - MetafieldId: BigInteger; Namespace: Text; MetafieldKey: Text; MetafieldValue: Text; @@ -175,20 +174,17 @@ codeunit 139616 "Shpfy Customer Metafields Test" //[GIVEN] Shop with Can update Shopify Customer = true Shop."Can Update Shopify Customer" := true; Shop.Modify(false); - // [GIVEN] Customer Customer := ShpfyInitializeTest.GetDummyCustomer(); // [GIVEN] Shopify Customer CreateShopifyCustomer(Customer, ShopifyCustomer); - // [GIVEN] Shopify Customer Address CustomerInitTest.CreateShopifyCustomerAddress(ShopifyCustomer); - // [GIVEN] Shopify Metafield with values created for Customer. Namespace := Any.AlphabeticText(10); MetafieldKey := Any.AlphabeticText(10); MetafieldValue := Any.AlphabeticText(10); - MetafieldId := ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShopifyCustomer.Id, Database::"Shpfy Customer", Namespace, MetafieldKey, MetafieldValue); + ShpfyMetafieldsHelper.CreateMetafield(ShpfyMetafield, ShopifyCustomer.Id, Database::"Shpfy Customer", Namespace, MetafieldKey, MetafieldValue); // [WHEN] Invoke ShopifyCustomerExport InvokeShopifyCustomerExport(Customer, ShopifyCustomer, ActualQuery); diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al index f2755f1c47..1e558047ff 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al @@ -27,7 +27,7 @@ codeunit 139618 "Shpfy Metafields Helper" begin ShpfyMetafield.Init(); ShpfyMetafield."Owner Id" := OwnerId; - ShpfyMetafield."Parent Table No." := ParentTableId; + ShpfyMetafield.Validate("Parent Table No.", ParentTableId); ShpfyMetafield.Namespace := Namespace; ShpfyMetafield.Name := Name; ShpfyMetafield.Value := Value; From bdbdac24a111eefe2c04d81cd4f739106fddfac2 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 25 Oct 2024 10:09:03 +0200 Subject: [PATCH 19/24] renumber ids --- Apps/W1/Shopify/app/app.json | 2 +- .../GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al | 4 ++-- .../Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al | 4 ++-- .../W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al | 4 ++-- .../test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al | 2 +- .../test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al | 2 +- .../test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al | 2 +- .../test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al | 2 +- .../Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Apps/W1/Shopify/app/app.json b/Apps/W1/Shopify/app/app.json index 88d5415c82..aa85c47434 100644 --- a/Apps/W1/Shopify/app/app.json +++ b/Apps/W1/Shopify/app/app.json @@ -17,7 +17,7 @@ "idRanges": [ { "from": 30100, - "to": 30370 + "to": 30380 } ], "internalsVisibleTo": [ diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al index fd2bbc0c1a..88dc348e25 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompanyMetafieldIds.Codeunit.al @@ -1,9 +1,9 @@ namespace Microsoft.Integration.Shopify; /// -/// Codeunit Shpfy GQL CompanyMetafieldIds (ID 30215) implements Interface Shpfy IGraphQL. +/// Codeunit Shpfy GQL CompanyMetafieldIds (ID 30373) implements Interface Shpfy IGraphQL. /// -codeunit 30215 "Shpfy GQL CompanyMetafieldIds" implements "Shpfy IGraphQL" +codeunit 30373 "Shpfy GQL CompanyMetafieldIds" implements "Shpfy IGraphQL" { Access = Internal; diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al index 5bf6902ed1..2dc821806a 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCustomerMetafieldIds.Codeunit.al @@ -1,8 +1,8 @@ namespace Microsoft.Integration.Shopify; /// -/// Codeunit Shpfy GQL Customer Metafield Ids (ID 30168) implements Interface Shpfy IGraphQL. +/// Codeunit Shpfy GQL Customer Metafield Ids (ID 30374) implements Interface Shpfy IGraphQL. /// -codeunit 30168 "Shpfy GQL CustomerMetafieldIds" implements "Shpfy IGraphQL" +codeunit 30374 "Shpfy GQL CustomerMetafieldIds" implements "Shpfy IGraphQL" { Access = Internal; diff --git a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al index 12e2c24c0d..29e3cc1f99 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al @@ -490,12 +490,12 @@ enum 30111 "Shpfy GraphQL Type" implements "Shpfy IGraphQL" Caption = 'Get Product Image'; Implementation = "Shpfy IGraphQL" = "Shpfy GQL GetProductImage"; } - value(98; CustomerMetafieldIds) + value(103; CustomerMetafieldIds) { Caption = 'Customer Metafield Ids'; Implementation = "Shpfy IGraphQL" = "Shpfy GQL CustomerMetafieldIds"; } - value(99; CompanyMetafieldIds) + value(104; CompanyMetafieldIds) { Caption = 'Company Metafield Ids'; Implementation = "Shpfy IGraphQL" = "Shpfy GQL CompanyMetafieldIds"; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al index 17d5b249fc..95156a2917 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139583 "Shpfy Company Metafields Subs" +codeunit 139621 "Shpfy Company Metafields Subs" { EventSubscriberInstance = Manual; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al index d3d99a1aa7..fe5b3dc075 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139617 "Shpfy Company Metafields Test" +codeunit 139622 "Shpfy Company Metafields Test" { Subtype = Test; TestPermissions = Disabled; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al index 807903aaea..dfc57bdada 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139581 "Shpfy Customer Metafields Subs" +codeunit 139623 "Shpfy Customer Metafields Subs" { EventSubscriberInstance = Manual; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index 9152414d38..8d6d49617c 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139616 "Shpfy Customer Metafields Test" +codeunit 139623 "Shpfy Customer Metafields Test" { Subtype = Test; TestPermissions = Disabled; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al index 1e558047ff..08ddc9e12b 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139618 "Shpfy Metafields Helper" +codeunit 139624 "Shpfy Metafields Helper" { procedure CreateMetafieldsResult(ResourceID: BigInteger; Namespace: Text; OwnerType: Text; MetafieldKey: Text; MetafieldValue: Text): JsonArray var From f316da3cdce732c6c886d734e9094667739d0fe2 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 25 Oct 2024 10:56:40 +0200 Subject: [PATCH 20/24] updated return var documentation --- .../Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al b/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al index 56ab97b4e1..eb2e7708bd 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al +++ b/Apps/W1/Shopify/app/src/Metafields/Interfaces/ShpfyIMetafieldOwnerType.Interface.al @@ -31,6 +31,6 @@ interface "Shpfy IMetafield Owner Type" /// Indicates if metafields can be edited. /// /// Shop record. - /// Boolean. + /// Boolean value which is true if metafields for the owner can be edited. procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean } \ No newline at end of file From 92c49c345e9c54ce6f37db04d6be1e3c1e357722 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 28 Oct 2024 13:41:49 +0100 Subject: [PATCH 21/24] fix object id --- .../test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al index dfc57bdada..ea1cc00a85 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139623 "Shpfy Customer Metafields Subs" +codeunit 139625 "Shpfy Customer Metafields Subs" { EventSubscriberInstance = Manual; From 8484fd21a0fca15a135961922cf1efc092be72c0 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 30 Oct 2024 15:24:38 +0100 Subject: [PATCH 22/24] fix tooltips --- Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al | 2 +- .../W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al | 2 +- .../Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al | 2 +- Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al index 9b4b9d1722..8f93f6885f 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al @@ -180,7 +180,7 @@ page 30156 "Shpfy Companies" PromotedCategory = Process; PromotedIsBig = true; PromotedOnly = true; - ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + ToolTip = 'Add metafields to a company. This can be used for adding custom data fields to companies in Shopify.'; trigger OnAction() var diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al index b78c638a98..f0605a99ee 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al @@ -172,7 +172,7 @@ page 30157 "Shpfy Company Card" PromotedCategory = Category4; PromotedIsBig = true; PromotedOnly = true; - ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + ToolTip = 'Add metafields to a company. This can be used for adding custom data fields to compoanies in Shopify.'; trigger OnAction() var diff --git a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al index e62ae55f31..5a01f9bf01 100644 --- a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al +++ b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomerCard.Page.al @@ -195,7 +195,7 @@ page 30106 "Shpfy Customer Card" PromotedCategory = Category4; PromotedIsBig = true; PromotedOnly = true; - ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + ToolTip = 'Add metafields to a customer. This can be used for adding custom data fields to customers in Shopify.'; trigger OnAction() var diff --git a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al index 08bfcbbff2..075a52361d 100644 --- a/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al +++ b/Apps/W1/Shopify/app/src/Customers/Pages/ShpfyCustomers.Page.al @@ -197,7 +197,7 @@ page 30107 "Shpfy Customers" PromotedCategory = Process; PromotedIsBig = true; PromotedOnly = true; - ToolTip = 'Add metafields to a product. This can be used for adding custom data fields to products in Shopify.'; + ToolTip = 'Add metafields to a customer. This can be used for adding custom data fields to customers in Shopify.'; trigger OnAction() var From 0594f9a71b78a19048f8cb448f01f8638a5eb8a0 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 31 Oct 2024 12:58:01 +0100 Subject: [PATCH 23/24] make metafields only edaitable when not imported before export --- .../IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al | 2 +- .../IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al index d9cdf1303b..baf86ef600 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al @@ -43,7 +43,7 @@ codeunit 30313 "Shpfy Metafield Owner Company" implements "Shpfy IMetafield Owne procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean begin - exit(Shop."Can Update Shopify Companies"); + exit((Shop."Can Update Shopify Companies") and (Shop."Company Import From Shopify" <> Enum::"Shpfy Company Import Range"::AllCompanies)); end; } diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al index 0f4713b44d..779fd82d80 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCustomer.Codeunit.al @@ -23,7 +23,7 @@ codeunit 30333 "Shpfy Metafield Owner Customer" implements "Shpfy IMetafield Own Parameters.Add('CustomerId', Format(OwnerId)); GraphQLType := GraphQLType::CustomerMetafieldIds; JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters); - if JsonHelper.GetJsonArray(JResponse, JMetafields, 'data.product.metafields.edges') then + if JsonHelper.GetJsonArray(JResponse, JMetafields, 'data.customer.metafields.edges') then foreach JItem in JMetafields do if JsonHelper.GetJsonObject(JItem.AsObject(), JNode, 'node') then begin Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode, 'legacyResourceId')); @@ -45,6 +45,6 @@ codeunit 30333 "Shpfy Metafield Owner Customer" implements "Shpfy IMetafield Own procedure CanEditMetafields(Shop: Record "Shpfy Shop"): Boolean begin - exit(Shop."Can Update Shopify Customer"); + exit((Shop."Can Update Shopify Customer") and (Shop."Customer Import From Shopify" <> Enum::"Shpfy Customer Import Range"::AllCustomers)); end; } \ No newline at end of file From 36ca70d1a9a130306b6afa408bc72cb10fc23b59 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 31 Oct 2024 13:43:53 +0100 Subject: [PATCH 24/24] object id fixes --- .../IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al | 2 +- .../test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al | 2 +- .../test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al | 2 +- .../test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al | 2 +- .../test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al | 2 +- .../Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al | 2 +- Apps/W1/Shopify/test/app.json | 4 ++++ 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al index baf86ef600..44ef1d693a 100644 --- a/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Metafields/Codeunits/IOwnerType/ShpfyMetafieldOwnerCompany.Codeunit.al @@ -1,6 +1,6 @@ namespace Microsoft.Integration.Shopify; -codeunit 30313 "Shpfy Metafield Owner Company" implements "Shpfy IMetafield Owner Type" +codeunit 30366 "Shpfy Metafield Owner Company" implements "Shpfy IMetafield Owner Type" { procedure GetTableId(): Integer diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al index 95156a2917..e32831dd81 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsSubs.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139621 "Shpfy Company Metafields Subs" +codeunit 139541 "Shpfy Company Metafields Subs" { EventSubscriberInstance = Manual; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al index fe5b3dc075..576648bdc1 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCompanyMetafieldsTest.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139622 "Shpfy Company Metafields Test" +codeunit 139543 "Shpfy Company Metafields Test" { Subtype = Test; TestPermissions = Disabled; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al index ea1cc00a85..877f3c0ec4 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsSubs.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139625 "Shpfy Customer Metafields Subs" +codeunit 139547 "Shpfy Customer Metafields Subs" { EventSubscriberInstance = Manual; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al index 8d6d49617c..6d096b602d 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyCustomerMetafieldsTest.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139623 "Shpfy Customer Metafields Test" +codeunit 139548 "Shpfy Customer Metafields Test" { Subtype = Test; TestPermissions = Disabled; diff --git a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al index 08ddc9e12b..963311de64 100644 --- a/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al +++ b/Apps/W1/Shopify/test/Metafields/ShpfyMetafieldsHelper.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139624 "Shpfy Metafields Helper" +codeunit 139549 "Shpfy Metafields Helper" { procedure CreateMetafieldsResult(ResourceID: BigInteger; Namespace: Text; OwnerType: Text; MetafieldKey: Text; MetafieldValue: Text): JsonArray var diff --git a/Apps/W1/Shopify/test/app.json b/Apps/W1/Shopify/test/app.json index ba1deea22a..b12dfca8c5 100644 --- a/Apps/W1/Shopify/test/app.json +++ b/Apps/W1/Shopify/test/app.json @@ -56,6 +56,10 @@ "from": 139560, "to": 139574 }, + { + "from": 139541, + "to": 139549 + }, { "from": 139576, "to": 139589