Facing the Uncaught TypeError: widget.getProductId is not a function
error in Magento 2? Read this blog post to find the solution.
Magento upgrades are amazing..!
They come with plenty of new features and performance enhancements. But, sometimes, they can create issues due to minor bugs or third-party extension incompatibility. One such issue faced by the merchants after upgrading their store to Magento 2.4.2 is the widget.getProductId is not a Function error on the product page.
Many Magento store owners reported this issue, where the product page throws a similar error instead of showing product information. Such an error can directly affect the store’s user experience by preventing visitors from exploring the products and, thus, the sales. Therefore, fixing the issue on a top-priority basis is advisable not to miss profitable sales.
This blog post will provide a simple solution to fix this error.
Solution to widget.getProductId is not a Function Error in Magento 2
On analyzing the widget.getProductId is not a function error in Magento 2 and digging deeper, I noticed it was triggered by the swatch-renderer.js file at the Magento_InventorySwatchesFrontendUi/js/ directory. It can be easily solved by tweaking some elements of the code within that file.
In order to solve the error,
- Open the Magento_InventorySwatchesFrontendUi/js/swatch-renderer.js file.
- Find the following code at line 22:
configurableVariationQty(productVariationsSku[widget.getProductId()], salesChannel, salesChannelCode);
- Replace
widget.getProductId()
withwidget.getProduct()
.
That’s it!
I hope this will help you solve the Magento 2 widget.getproductid is not a function.
Do you still have any queries? Ask in the comments. I’d be happy to help you.
Feel free to share this solution with your friends via social media.
Thanks for reading!