We have a lot of products that aren't real products on their own, they are move customised versions of another product.

So in terms of stock values for these SKUs we really want to link them to the main product they're based on.

So I've looked at adding an 'alt_sku' attribute to the product, I was then hoping in the afterGetQty plugin to check if the product has this attribute, if it does load that alt product and get the Qty from that.

But this plugin never retrieves the product Qty value or doesn't fire when I expected, Does anyone know what the best method to extend with a plugin that would catch most areas where Magento tries to find out a products stock Qty? We're not using MSI just basic stock qty.

1 Answer 1


Your best bet may be to implement a plugin on \Magento\CatalogInventory\Api\Data\StockItemInterface\StockStateProviderInterface. This interface is only implemented once in \Magento\CatalogInventory\Model\StockStateProvider, and includes a getStockQty function that accepts a StockItemInterface instance as a parameter.

I would probably try implementing a before plugin and passing a StockItemInterface implementation of the correct sku so that all calculations proceed as you'd expect for that sku, but you could also do an after plugin as you've suggested. At any rate, this is probably a good place to start. There are some other getStockQty functions defined in Magento 2, but they look to be deprecated in favor of MSI by and large.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.