{"id":1724,"date":"2021-04-21T13:35:37","date_gmt":"2021-04-21T13:35:37","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-stock-id-of-particular-website-in-magento-2\/"},"modified":"2025-07-16T18:00:59","modified_gmt":"2025-07-16T12:30:59","slug":"get-stock-id-of-particular-website-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-stock-id-of-particular-website-in-magento-2\/","title":{"rendered":"How to Get Stock ID of Particular Website in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 multi-stock inventory makes the control of inventory for single or multiple sources and sales channels possible!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Equipping\u00a0Magento 2\u00a0store with warehouse management as well as inventory management is one of the most crucial tasks for store owners. If you have more than one warehouse under your control, it is necessary to control all data in the inventory and get that data whenever you need it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to work with inventory among multiple warehouses easily, generate inventory-related reports, and manage stock effectively, one often needs to&nbsp;<strong><em>get stock id of particular website in Magento 2<\/em><\/strong>.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check out the below method to do so.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Stock ID of Particular Website in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in your helper file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Module\\Helper;\n\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\InventorySales\\Model\\ResourceModel\\GetAssignedStockIdForWebsite;\n\n\/**\n * Class GetStockIdForWebsite\n *\/\nclass GetStockIdForWebsite extends AbstractHelper\n{\n    \/**\n     * @var GetAssignedStockIdForWebsite\n     *\/\n    private $getAssignedStockIdForWebsite;\n\n    \/**\n     * GetStockIdForWebsite constructor.\n     * @param Context $context\n     * @param GetAssignedStockIdForWebsite $getAssignedStockIdForWebsite\n     *\/\n    public function __construct(Context $context, GetAssignedStockIdForWebsite $getAssignedStockIdForWebsite)\n    {\n        parent::__construct($context);\n        $this->getAssignedStockIdForWebsite = $getAssignedStockIdForWebsite;\n    }\n\n    \/**\n     * @param $websiteCode\n     * @return int|null\n     *\/\n    public function getStockIdForWebsite($websiteCode)\n    {\n        return $this->getAssignedStockIdForWebsite->execute($websiteCode);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, please share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 multi-stock inventory makes the control of inventory for single or multiple sources and sales channels possible! Equipping\u00a0Magento 2\u00a0store with warehouse management as well&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1724","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1724"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1724\/revisions"}],"predecessor-version":[{"id":18110,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1724\/revisions\/18110"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}