So far I have created custom attribute my_custom_attribute and I want to pass this attribute inside Magento/CatalogInventory/Model/StockStateProvider.php and call it like $stockItem->getIsInStock() but I want to get it like $stockItem-getMyAttribute(). Can someone explain me how to do it? Can't really understand how to set this data to get my attribute there

Thank you a lot!

1 Answer 1


To get your custom attribute value in Magento/CatalogInventory/Model/StockStateProvider.php model file you just need to do following steps.

  1. Override Model file in custom module Mee/CustomModule/Model/StockStateProvider.php as mentioned in below link https://magenticians.com/override-model-magento-2/
  2. Include your function in the above overdid model file as

    protected function getMyAttribute() { $product = $this->productFactory->create(); return $product->getMyAttribute(); }

  3. Run magento upgrade and deployment commands from your root directory.

now you can call $stockItem-getMyAttribute() in your file

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.