[Shopify] Refresh cached plan before order sync#8212
Open
onbuyuka wants to merge 5 commits into
Open
Conversation
Auto-refresh Shop."Advanced Shopify Plan" via the existing Shop.GetShopSettings() helper before both order-import entry points so that a Shopify plan downgrade doesn't leave the connector requesting the staffMember field that the new plan can no longer grant access to (ACCESS_DENIED on read_users scope). Entry points covered: - Bulk sync: report 30104 "Shpfy Sync Orders from Shopify" (also the scheduled auto-sync path). One refresh call per shop per batch run. - Single-order reimport: ShpfyImportOrder .ReimportExistingOrderConfirmIfConflicting. Tests added to ShpfyOrdersAPITest.Codeunit.al: - TestGetShopSettingsClearsStaleAdvancedShopifyPlanFlag - TestSyncOrdersFromShopifyReportRefreshesAdvancedShopifyPlanFlag Fixes AB#635878 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address PR review feedback: reset PlanRefreshExpected / PlanRefreshCallCount at the start of Initialize() so an assertion failure in one test cannot leak the plan-refresh flag into the next test and corrupt unrelated HTTP calls. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Unhandled API failure can abort entire report
Recommendation:
Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why |
…eunit.al Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
CI lint fails with AA0214 ("record should be modified before saving")
because the analyzer cannot see through GetShopSettings() to detect
the field assignments it performs on the record. This mirrors the
established suppression pattern used elsewhere in the codebase (e.g.,
ShpfyProductCollectionTest, Subscription Billing tables, EDocument
line matching) for the same false-positive scenario.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Commit 8f0d961 (a suggestion accepted via the GitHub UI) placed a LibraryAssert call between two procedure bodies, breaking the file syntax. Moving the intended tightened assertion ("exactly one" plan-refresh query, matching the GetShopSettings test) into its correct location inside the report test, replacing the previous ">= 1" check. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bug 635878: When a merchant downgrades their Shopify plan from Plus / Advanced to a standard plan, the connector keeps requesting the
staffMember { id }field in the order GraphQL query. The lower plan does not grantread_usersscope, so Shopify returnsACCESS_DENIEDand order sync is fully broken until the user manually toggles the Enabled field off and on again on the Shop Card.Shop."Advanced Shopify Plan"(field 207) is the cached flag that gates the staff member field. It was only refreshed when the user toggled Enabled or when a scope change was detected on Shop Card open — never before an order sync.Fix
Auto-refresh the cached plan via the existing
Shop.GetShopSettings()helper (one cheap GraphQL query forshop { plan { ... } weightUnit }) before both order-import entry points:30104 Shpfy Sync Orders from Shopify(also the scheduled auto-sync path). One refresh call per shop per batch run.ShpfyImportOrder.ReimportExistingOrderConfirmIfConflicting(manual reimport action on the Order Header page).The refresh is deliberately not placed in
ShpfyImportOrder.SetShop()because that runs per order; for a 100-order batch it would mean 100 extra GraphQL round-trips.Tests
Two regression tests added to the existing
ShpfyOrdersAPITest.Codeunit.al(139608):TestGetShopSettingsClearsStaleAdvancedShopifyPlanFlag— sets stale"Advanced Shopify Plan" = true, callsGetShopSettings, asserts the flag becomesfalse.TestSyncOrdersFromShopifyReportRefreshesAdvancedShopifyPlanFlag— sets stale flag, runs Report 30104, asserts the persisted Shop record has the flag refreshed tofalse.Existing
OrdersAPIHttpHandlerextended with a one-shotPlanRefreshExpectedflag returning a downgraded-plan JSON for the first request, then falling through to the prior empty-data behavior.Both tests verified locally.
Fixes AB#635878