Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
17 changes: 15 additions & 2 deletions src/Apps/W1/Shopify/App/src/Base/Tables/ShpfyShop.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down Expand Up @@ -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
Comment thread
onbuyuka marked this conversation as resolved.
Rec.Validate("Auto Create Catalog", false);
end;
}
field(208; "Find Mapping by Barcode"; Boolean)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Comment thread
onbuyuka marked this conversation as resolved.
(JsonHelper.GetValueAsText(JItem, 'publicDisplayName') in ['Plus Trial', 'Development', 'Advanced']));
Rec."Weight Unit" := ConvertToWeightUnit(JsonHelper.GetValueAsText(JResponse, 'data.shop.weightUnit'));
end;

Expand Down
45 changes: 45 additions & 0 deletions src/Apps/W1/Shopify/Test/Staff/ShpfyStaffTest.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Comment thread
onbuyuka marked this conversation as resolved.
// [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()
Expand Down
Loading