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

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

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?