A
Alokaiβ€’10mo ago
Darren R

GET error Error when product goes out of stock

We have set up our Magento config so that out-of-stock products are not visible on the website. If we go to a URL of a product that has become out of stock instead of getting a 404 error we get "Cannot GET /product-url-here'. The console log shows GET https://site/product-url 404 (Not Found) How can we display the 404 page here? Any help appreciated.
2 Replies
Darren R
Darren ROPβ€’10mo ago
It looks like the issue is VSF still gets through the route data based on the product url. This returns the sku/type. Because of this, it tries to render the Product page, but this throws an error. I think this is due to not being able to retrieve the product data correctly due to it not being active in Magento. In the product template it actually checks this product data and if we have no sku throws an error.
if (Boolean(product?.value?.sku) === false) {
nuxtError({ statusCode: 404 });
}
if (Boolean(product?.value?.sku) === false) {
nuxtError({ statusCode: 404 });
}
This didn't stop the rest of the fetch functions from trying to run though, which caused my issue (was a 500 error). I've added a return and this is working ok now.
if (Boolean(product?.value?.sku) === false) {
nuxtError({ statusCode: 404 });
return;
}
if (Boolean(product?.value?.sku) === false) {
nuxtError({ statusCode: 404 });
return;
}
It still loads the product page based on the route response, but now doesn't try to run all the fetch functions and renders the 404 template correctly.
rohrig
rohrigβ€’10mo ago
Hi πŸ‘‹ , I'm glad you got it worked out. Thanks for sharing. πŸ˜ƒ
Want results from more Discord servers?
Add your server