I'm currently writing multi-vendor extension, I'm looking for sample code on how to override the inventory, so it shows inventory from a custom field, Already tried overriding getQty of the Product class but that doesn't work,

Any ideas would be appreciated,



Magento2 uses the \Magento\CatalogInventory\Api\StockRegistryInterface to get stock information of a product:

$stockItem = $this->stockRegistry->getStockItem($product->getId());

You should create an own implementation of this enterface which could gets it's data from a custom field. Register your implementation with the di.xml file in a module.

  • When implementing an interface, do I need to implement all functions? or somehow only implement part of it and extending a class that implements the rest? Jan 4 '17 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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