diff --git a/src/Apps/W1/Shopify/App/src/Base/Pages/ShpfyShopCard.Page.al b/src/Apps/W1/Shopify/App/src/Base/Pages/ShpfyShopCard.Page.al index 5cb2a5d3c1..9d574d9cdd 100644 --- a/src/Apps/W1/Shopify/App/src/Base/Pages/ShpfyShopCard.Page.al +++ b/src/Apps/W1/Shopify/App/src/Base/Pages/ShpfyShopCard.Page.al @@ -395,7 +395,6 @@ page 30101 "Shpfy Shop Card" field("Auto Create Catalog"; Rec."Auto Create Catalog") { ApplicationArea = All; - Visible = Rec."Advanced Shopify Plan"; } field("Company Metafields To Shopify"; Rec."Company Metafields To Shopify") { diff --git a/src/Apps/W1/Shopify/App/src/Base/Tables/ShpfyShop.Table.al b/src/Apps/W1/Shopify/App/src/Base/Tables/ShpfyShop.Table.al index 8b29c15807..98ca1a33a4 100644 --- a/src/Apps/W1/Shopify/App/src/Base/Tables/ShpfyShop.Table.al +++ b/src/Apps/W1/Shopify/App/src/Base/Tables/ShpfyShop.Table.al @@ -757,6 +757,12 @@ table 30102 "Shpfy Shop" Caption = 'Auto Create Catalog'; ToolTip = 'Specifies whether a catalog is automatically created for new companies.'; DataClassification = CustomerContent; + + trigger OnValidate() + begin + if Rec."Auto Create Catalog" and not Rec."Advanced Shopify Plan" then + Error(AutoCreateCatalogPlanErr, Rec.FieldCaption("Auto Create Catalog")); + end; } field(121; "Company Import From Shopify"; Enum "Shpfy Company Import Range") { @@ -942,6 +948,12 @@ table 30102 "Shpfy Shop" { Caption = 'Advanced Shopify Plan'; DataClassification = SystemMetadata; + + trigger OnValidate() + begin + if (not Rec."Advanced Shopify Plan") and Rec."Auto Create Catalog" then + Rec.Validate("Auto Create Catalog", false); + end; } field(208; "Find Mapping by Barcode"; Boolean) { @@ -981,6 +993,7 @@ table 30102 "Shpfy Shop" var CurrencyExchangeRateNotDefinedErr: Label 'The specified currency must have exchange rates configured. If your online shop uses the same currency as Business Central then leave the field empty.'; AutoCreateErrorMsg: Label 'You cannot turn "%1" off if "%2" is set to the value of "%3".', Comment = '%1 = Field Caption of "Auto Create Orders", %2 = Field Caption of "Return and Refund Process", %3 = Field Value of "Return and Refund Process"'; + AutoCreateCatalogPlanErr: Label '%1 can only be enabled for Shopify Plus, Plus Trial, Development, or Advanced plans.', Comment = '%1 = Field Caption of "Auto Create Catalog"'; ExpirationNotificationTxt: Label 'Shopify API version 30 days before expiry notification sent.', Locked = true; BlockedNotificationTxt: Label 'Shopify API version expired notification sent.', Locked = true; CategoryTok: Label 'Shopify Integration', Locked = true; @@ -1143,8 +1156,8 @@ table 30102 "Shpfy Shop" JResponse := CommunicationMgt.ExecuteGraphQL('{"query":"query { shop { name plan { publicDisplayName partnerDevelopment shopifyPlus } weightUnit } }"}'); if JResponse.SelectToken('$.data.shop.plan', JItem) then if JItem.IsObject then - Rec."Advanced Shopify Plan" := JsonHelper.GetValueAsBoolean(JItem, 'shopifyPlus') or - (JsonHelper.GetValueAsText(JItem, 'publicDisplayName') in ['Plus Trial', 'Development', 'Advanced']); + Rec.Validate("Advanced Shopify Plan", JsonHelper.GetValueAsBoolean(JItem, 'shopifyPlus') or + (JsonHelper.GetValueAsText(JItem, 'publicDisplayName') in ['Plus Trial', 'Development', 'Advanced'])); Rec."Weight Unit" := ConvertToWeightUnit(JsonHelper.GetValueAsText(JResponse, 'data.shop.weightUnit')); end; diff --git a/src/Apps/W1/Shopify/Test/Staff/ShpfyStaffTest.Codeunit.al b/src/Apps/W1/Shopify/Test/Staff/ShpfyStaffTest.Codeunit.al index a3c44df414..61a72d2a69 100644 --- a/src/Apps/W1/Shopify/Test/Staff/ShpfyStaffTest.Codeunit.al +++ b/src/Apps/W1/Shopify/Test/Staff/ShpfyStaffTest.Codeunit.al @@ -59,6 +59,51 @@ codeunit 139551 "Shpfy Staff Test" ShpfyShopCard.Close(); end; + [Test] + procedure TestAutoCreateCatalogRequiresAdvancedPlan() + var + LibraryAssert: Codeunit "Library Assert"; + begin + // [Given] A shop on a plan that does not support B2B catalogs + Initialize(); + Shop."Advanced Shopify Plan" := false; + Shop."Auto Create Catalog" := false; + Shop.Modify(false); + + // [When] The user tries to enable Auto Create Catalog + // [Then] A field error is raised mentioning the field + asserterror Shop.Validate("Auto Create Catalog", true); + LibraryAssert.ExpectedError('Auto Create Catalog'); + + // [Given] The shop is upgraded to a plan that supports B2B catalogs + Shop."Advanced Shopify Plan" := true; + Shop.Modify(false); + + // [When] The user enables Auto Create Catalog + Shop.Validate("Auto Create Catalog", true); + + // [Then] The field is enabled successfully + LibraryAssert.IsTrue(Shop."Auto Create Catalog", 'Auto Create Catalog should be enabled on an Advanced plan.'); + end; + + [Test] + procedure TestAdvancedPlanDowngradeDisablesAutoCreateCatalog() + var + LibraryAssert: Codeunit "Library Assert"; + begin + // [Given] A shop on an Advanced plan with Auto Create Catalog enabled + Initialize(); + Shop."Advanced Shopify Plan" := true; + Shop."Auto Create Catalog" := true; + Shop.Modify(false); + + // [When] The shop's plan is downgraded (as happens during a plan sync from Shopify) + Shop.Validate("Advanced Shopify Plan", false); + + // [Then] Auto Create Catalog is silently disabled + LibraryAssert.IsFalse(Shop."Auto Create Catalog", 'Auto Create Catalog should be disabled after the plan is downgraded.'); + end; + [Test] [HandlerFunctions('HttpSubmitHandler')] procedure TestImportStaff()