Can't getStockItem magento 2.3.1Magento 2.3.1 installation ErrorIssue while generating db_schema file for existing module Magento 2.3.1Magento 2.3.1 Incompatible argument typeCan't access admin after update Magento 2.3.1Magento 2.3.1 - Changed PayPal Express ButtonMagento 2.3.1 update issueMagento 2.3.1 server resources requirementsCan't find ElasticSearch 6.0+ option in magento 2.3.1 backend (CE)Magento 2.3.1 compare and product rating disable?magento 2.3.1 elastic search index name

Why adjustbox needs a tweak of raise=-0.3ex with enumitem?

Speaker impedance: rewiring four 8 Ω speakers for use with 8 Ω amp output

Deflecting lasers with lightsabers

Can I say "Gesundheit" if someone is coughing?

Using Forstner bits instead of hole saws

How do people drown while wearing a life jacket?

How to handle many times series?

Partial Fractions: Why does this shortcut method work?

Does the problem of P vs NP come under the category of Operational Research?

Astable 555 circuit not oscillating

Being told my "network" isn't PCI compliant. I don't even have a server! Do I have to comply?

Can you shove a friendly creature?

Why do player start with fighting for the corners in go?

Skipping same old introductions

Why is the Vasa Museum in Stockholm so Popular?

How were x-ray diffraction patterns deciphered before computers?

Why does BezierFunction not follow BezierCurve at npts>4?

Is law enforcement responsible for damages made by a search warrant?

What is a summary of basic Jewish metaphysics or theology?

Search and replace a substring only if another substring is not present

How to avoid a lengthy conversation with someone from the neighborhood I don't share interests with

how to change ^L code in many files in ubuntu?

Gödel's paradox: Why is "a proof that some universal statement is unprovable" not a valid proof that this statement is true?

Has J.J.Jameson ever found out that Peter Parker is Spider-Man?



Can't getStockItem magento 2.3.1


Magento 2.3.1 installation ErrorIssue while generating db_schema file for existing module Magento 2.3.1Magento 2.3.1 Incompatible argument typeCan't access admin after update Magento 2.3.1Magento 2.3.1 - Changed PayPal Express ButtonMagento 2.3.1 update issueMagento 2.3.1 server resources requirementsCan't find ElasticSearch 6.0+ option in magento 2.3.1 backend (CE)Magento 2.3.1 compare and product rating disable?magento 2.3.1 elastic search index name






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Block



namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $_stockItemRepository;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data = []
)
$this->_registry = $registry;
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->_stockItemRepository->get($productId);




Template



$currentProduct = $block->getCurrentProduct();
$id = $currentProduct->getId();
$_productStock = $block->getStockItem($id);
if($_productStock->getIsInStock())
...



But it show a bug:



The stock item with the "140" ID wasn't found. Verify the ID and try again.


I have checked that product in backend in Catalog but it's instock with qty is 465.










share|improve this question
























  • check if that product id is 140

    – Mohit Rane
    Jul 25 at 4:44











  • Yes, Please check my screen: prntscr.com/ojpqa4

    – David Duong
    Jul 25 at 4:48












  • check my answer.

    – Mohit Rane
    Jul 25 at 4:50

















0















Block



namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $_stockItemRepository;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data = []
)
$this->_registry = $registry;
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->_stockItemRepository->get($productId);




Template



$currentProduct = $block->getCurrentProduct();
$id = $currentProduct->getId();
$_productStock = $block->getStockItem($id);
if($_productStock->getIsInStock())
...



But it show a bug:



The stock item with the "140" ID wasn't found. Verify the ID and try again.


I have checked that product in backend in Catalog but it's instock with qty is 465.










share|improve this question
























  • check if that product id is 140

    – Mohit Rane
    Jul 25 at 4:44











  • Yes, Please check my screen: prntscr.com/ojpqa4

    – David Duong
    Jul 25 at 4:48












  • check my answer.

    – Mohit Rane
    Jul 25 at 4:50













0












0








0


1






Block



namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $_stockItemRepository;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data = []
)
$this->_registry = $registry;
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->_stockItemRepository->get($productId);




Template



$currentProduct = $block->getCurrentProduct();
$id = $currentProduct->getId();
$_productStock = $block->getStockItem($id);
if($_productStock->getIsInStock())
...



But it show a bug:



The stock item with the "140" ID wasn't found. Verify the ID and try again.


I have checked that product in backend in Catalog but it's instock with qty is 465.










share|improve this question














Block



namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $_stockItemRepository;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
array $data = []
)
$this->_registry = $registry;
$this->_stockItemRepository = $stockItemRepository;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->_stockItemRepository->get($productId);




Template



$currentProduct = $block->getCurrentProduct();
$id = $currentProduct->getId();
$_productStock = $block->getStockItem($id);
if($_productStock->getIsInStock())
...



But it show a bug:



The stock item with the "140" ID wasn't found. Verify the ID and try again.


I have checked that product in backend in Catalog but it's instock with qty is 465.







stock magento2.3.1 stock-status






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 25 at 4:26









David DuongDavid Duong

778 bronze badges




778 bronze badges















  • check if that product id is 140

    – Mohit Rane
    Jul 25 at 4:44











  • Yes, Please check my screen: prntscr.com/ojpqa4

    – David Duong
    Jul 25 at 4:48












  • check my answer.

    – Mohit Rane
    Jul 25 at 4:50

















  • check if that product id is 140

    – Mohit Rane
    Jul 25 at 4:44











  • Yes, Please check my screen: prntscr.com/ojpqa4

    – David Duong
    Jul 25 at 4:48












  • check my answer.

    – Mohit Rane
    Jul 25 at 4:50
















check if that product id is 140

– Mohit Rane
Jul 25 at 4:44





check if that product id is 140

– Mohit Rane
Jul 25 at 4:44













Yes, Please check my screen: prntscr.com/ojpqa4

– David Duong
Jul 25 at 4:48






Yes, Please check my screen: prntscr.com/ojpqa4

– David Duong
Jul 25 at 4:48














check my answer.

– Mohit Rane
Jul 25 at 4:50





check my answer.

– Mohit Rane
Jul 25 at 4:50










1 Answer
1






active

oldest

votes


















1














Try using this MagentoCatalogInventoryModelStockStockItemRepository




Update your code with following code




namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $stockRegistry;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
array $data = []
)
$this->_registry = $registry;
$this->stockRegistry = $stockRegistry;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->stockRegistry->getStockItem($productId);




Hope it Helps.






share|improve this answer



























  • It work fine. Thank you!

    – David Duong
    Jul 25 at 11:48






  • 1





    glad it worked.

    – Mohit Rane
    Jul 25 at 11:51













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283236%2fcant-getstockitem-magento-2-3-1%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try using this MagentoCatalogInventoryModelStockStockItemRepository




Update your code with following code




namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $stockRegistry;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
array $data = []
)
$this->_registry = $registry;
$this->stockRegistry = $stockRegistry;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->stockRegistry->getStockItem($productId);




Hope it Helps.






share|improve this answer



























  • It work fine. Thank you!

    – David Duong
    Jul 25 at 11:48






  • 1





    glad it worked.

    – Mohit Rane
    Jul 25 at 11:51















1














Try using this MagentoCatalogInventoryModelStockStockItemRepository




Update your code with following code




namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $stockRegistry;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
array $data = []
)
$this->_registry = $registry;
$this->stockRegistry = $stockRegistry;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->stockRegistry->getStockItem($productId);




Hope it Helps.






share|improve this answer



























  • It work fine. Thank you!

    – David Duong
    Jul 25 at 11:48






  • 1





    glad it worked.

    – Mohit Rane
    Jul 25 at 11:51













1












1








1







Try using this MagentoCatalogInventoryModelStockStockItemRepository




Update your code with following code




namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $stockRegistry;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
array $data = []
)
$this->_registry = $registry;
$this->stockRegistry = $stockRegistry;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->stockRegistry->getStockItem($productId);




Hope it Helps.






share|improve this answer















Try using this MagentoCatalogInventoryModelStockStockItemRepository




Update your code with following code




namespace VendorExtensionBlockProduct;

use MagentoFrameworkViewElementTemplate;

class Stickycart extends Template

protected $_registry;

protected $stockRegistry;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
array $data = []
)
$this->_registry = $registry;
$this->stockRegistry = $stockRegistry;
parent::__construct($context, $data);



public function getCurrentProduct()

return $this->_registry->registry('current_product');


public function getStockItem($productId)

return $this->stockRegistry->getStockItem($productId);




Hope it Helps.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 25 at 4:53

























answered Jul 25 at 4:47









Mohit RaneMohit Rane

1,17718 bronze badges




1,17718 bronze badges















  • It work fine. Thank you!

    – David Duong
    Jul 25 at 11:48






  • 1





    glad it worked.

    – Mohit Rane
    Jul 25 at 11:51

















  • It work fine. Thank you!

    – David Duong
    Jul 25 at 11:48






  • 1





    glad it worked.

    – Mohit Rane
    Jul 25 at 11:51
















It work fine. Thank you!

– David Duong
Jul 25 at 11:48





It work fine. Thank you!

– David Duong
Jul 25 at 11:48




1




1





glad it worked.

– Mohit Rane
Jul 25 at 11:51





glad it worked.

– Mohit Rane
Jul 25 at 11:51

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283236%2fcant-getstockitem-magento-2-3-1%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form