[W1][MultiObjects] Shopify inventory sync: pass Shpfy Variant to the stock calculation interface (follow-up to microsoft/ALAppExtensions#27413)
Nobody has claimed this yet.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
Description
Why do you need this change?
This is a follow-up to microsoft/ALAppExtensions#27413, which established that because Shopify subtracts committed quantities from the value Business Central sends, an app may need to compensate the exported figure. That request was accepted and resolved by exposing Shpfy Shop Location and adding the Shpfy Extended Stock Calculation interface, so compensation can be calculated per shop location.
That route does not work where a Shopify product uses unit-of-measure variants — for example a drinks item sold both as a single can and as a case of 12.
In Shpfy Inventory API.GetStock, the stock calculation implementation is called with an Item record, and the result is then divided by Qty. per Unit of Measure, resolved from ShopifyVariant."UoM Option Id". Every unit-of-measure variant of an item resolves to the same BC item and item variant, so the interface receives identical input for each variant and can only return one value for all of them.
The compensation required differs per variant. Shopify holds committed quantities per inventory item, and each variant has its own. Correcting the single-can variant means adding back only the singles on open orders; correcting the case variant means adding back only the cases, expressed in base units. Neither is expressible today, so the compensation enabled by #27413 cannot be applied at all in this configuration.
The event route is not an alternative. Shpfy Inventory Events.OnAfterCalculationStock is still internal, so it cannot be subscribed to from a dependent extension, and it carries only LocationFilter, so it could not identify the variant either. The interface is therefore the only viable vehicle, consistent with how #27413 was resolved.
This is not specific to one vertical. Any app that needs per-variant control over exported stock — unit-of-measure variants, pack sizes, allocations, channel-specific holdbacks — hits the same wall.
Describe the request
Following the pattern already established by Shpfy Extended Stock Calculation, add a further interface that also carries the Shopify variant, and have Shpfy Inventory API prefer it when implemented.
Objects affected:
src/Apps/W1/Shopify/App/src/Inventory/Interface/ShpfyVariantStockCalculation.Interface.al(new)- Codeunit 30195
Shpfy Inventory API, call site inGetStock
Proposed interface:
interface "Shpfy Variant Stock Calculation" extends "Shpfy Extended Stock Calculation"
{
procedure GetStock(var Item: Record Item; var ShopLocation: Record "Shpfy Shop Location"; ShopifyVariant: Record "Shpfy Variant"): Decimal;
}
Proposed call site in Shpfy Inventory API.GetStock, extending the existing is / as resolution:
if StockCalculation is "Shpfy Variant Stock Calculation" then
Stock := (StockCalculation as "Shpfy Variant Stock Calculation").GetStock(Item, ShopLocation, ShopifyVariant)
else
if StockCalculation is "Shpfy Extended Stock Calculation" then
Stock := (StockCalculation as "Shpfy Extended Stock Calculation").GetStock(Item, ShopLocation)
else
Stock := StockCalculation.GetStock(Item);
Notes:
- Non-breaking. Existing implementations of
Shpfy Stock CalculationandShpfy Extended Stock Calculationare unaffected. - No new lookup is required.
GetStockalready declaresShopifyVariant: Record "Shpfy Variant"and populates it fromShopInventory."Variant Id"before the calculation runs. ShopifyVariantis passed by value, per the design guidance on passing records. It exposes no sensitive data.- The returned value continues to be divided by
Qty. per Unit of Measureafterwards, which is the desired behaviour: the implementation returns a base-unit figure and the connector converts it. - Verified against
mainandreleases/28.0, insrc/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfyInventoryAPI.Codeunit.alandsrc/Apps/W1/Shopify/App/src/Inventory/Interface/ShpfyExtendedStockCalculation.Interface.al. Nothing involved is markedObsoleteor surrounded byCLEANtags. - Filed here rather than in ALAppExtensions, as BCApps is now the home of the Shopify Connector.
- I am happy to provide the implementation pull request once the issue is approved.
Provide an implementation (optional)
- I will provide the implementation for this extensibility request
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/Apps/W1/Shopify/App/src/Inventory/Interface/ShpfyExtendedStockCalculation.Interface.al and the existing call site in src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfyInventoryAPI.Codeunit.al, especially GetStock. Add the new variant-aware interface and update the calculation resolution so implementations receiving Shpfy Variant are preferred while existing implementations remain supported. Done means the variant is available to the calculation and the existing unit-of-measure conversion still occurs afterward.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100