Mark implicitly created composite stock items as automatically maintained - #41175
Open
brosenberger wants to merge 1 commit into
Open
Mark implicitly created composite stock items as automatically maintained#41175brosenberger wants to merge 1 commit into
brosenberger wants to merge 1 commit into
Conversation
…atically maintained A composite product's stock status is derived from its children, so the legacy stock item created implicitly on product save records no merchant decision. It was left with stock_status_changed_auto = 0, which is indistinguishable from a merchant having taken the product off sale. ChangeParentStockStatus lets a parent go out of stock unconditionally but only lets it come back when that flag is set, so a composite created before its children are linked - the ordinary structure-feed import order - is latched out of stock permanently. Attaching the children later does not clear it and neither does stocking them; the flag is stored, not derived, so reindexing cannot help. Fix the input rather than the predicate: isNeedToUpdateParent() is unchanged and still protects a merchant's manual out-of-stock decision. Only a row that records no decision at all is now marked as automatically maintained. The change sits in the existing non-qty branch of StockItemRepository::save(), which already isolates exactly the composite product types, so no new type check is introduced. This generalises a rule upstream already applies in InventoryConfigurableProduct\Model\StockStatusManagement::update(), which derives the flag for a newly created stock item but only for configurables and only in single-source mode, and computes 0 for the born-out-of-stock case. Covered by integration tests for configurable, bundle and grouped, plus unit coverage of the new branch. Two of the integration tests pass before and after the change, pinning that a parent created with its children still recovers and that a merchant's manual out-of-stock decision survives.
|
Hi @brosenberger. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
brosenberger
pushed a commit
to brosenberger/module-composite-stock-status
that referenced
this pull request
Aug 31, 2026
Splits the Upstream section by defect. The latch half now points at magento/magento2#41174 and the core fix in magento/magento2#41175; the multi-source half keeps magento/inventory#3466 and #3467. Notes what happens if the core fix lands: KeepCompositeStockAutomatic becomes redundant on the fixed versions, but only for products created after the upgrade - catalogues already carrying latched parents still need one revive run.
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.
Description (*)
A composite product's stock status is derived from its children, so the legacy stock item created implicitly on product save records no merchant decision. It is left with
stock_status_changed_auto = 0, which is indistinguishable from a merchant having taken the product off sale.ChangeParentStockStatus::isNeedToUpdateParent()lets a parent go out of stock unconditionally but only lets it come back when that flag is set, so a composite created before its children are linked — the ordinary structure-feed import order — is latched out of stock permanently. Attaching the children later does not clear it, and neither does stocking them; the flag is stored, not derived, so reindexing cannot help.This fixes the input, not the predicate.
isNeedToUpdateParent()is unchanged in all three modules and still protects a merchant's manual out-of-stock decision. Only a row that records no decision at all is now marked as automatically maintained. The change sits in the existing non-qty branch ofStockItemRepository::save(), which already isolates exactly the composite types —StockConfigurationInterface::isQty()is false for preciselyconfigurable,bundleandgrouped, since onlysimple,virtualanddownloadabledeclareisQty="true". No new type check is introduced.The asymmetry being corrected is visible in the method itself. The qty branch maps the "changed automatically" marker onto the column; the composite branch never touched the column at all:
This also generalises a rule the platform already applies:
Magento\InventoryConfigurableProduct\Model\StockStatusManagement::update()derives the flag for a newly created stock item, but only for configurables, only in single source mode, and it computes0for the born-out-of-stock case.Related Pull Requests
magento/inventory#3467 — related test coverage in the Inventory repository. The multi-source half of this area is not fixed here; see magento/inventory#3466 for why it needs a design decision rather than a bug fix.
Fixed Issues (if relevant)
Manual testing scenarios (*)
2.4-develop, single source mode.POST /rest/V1/products— create a grouped (or configurable, or bundle) parent with nostock_itemextension attribute and no children linked yet.(0, 0). After:(0, 1).(0, 0). The parent is out of stock on the storefront and no amount of reindexing changes it.(1, 1). The parent follows its children.Boundary worth knowing: the parent must be created before its children are linked. If a single call creates the parent already carrying its links or options,
ChangeParentStockStatusruns inside that same save, the parent is born(0, 1)and recovers normally. That is why this defect looks intermittent between integrations.Questions or comments
isNeedToUpdateParent()is duplicated verbatim inConfigurableProduct,BundleandGroupedProduct. This PR deliberately leaves all three untouched; happy to consolidate them in a follow-up if maintainers prefer.Contribution checklist (*)