Skip to content

Commit

Permalink
Merge pull request #3 from winniepukki/improve-isInStock-value-catch
Browse files Browse the repository at this point in the history
Improved with NoSuchEntityException catch for item in stock
  • Loading branch information
alfredsgenkins authored Jan 22, 2021
2 parents b8352f9 + 2c92571 commit aa666ad
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Model/Resolver/EntityUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ public function resolve(
$collection = $this->productCollectionFactory->create()
->addAttributeToFilter('status', ['eq' => Status::STATUS_ENABLED]);
$product = $collection->addIdFilter($id)->getFirstItem();
$isInStock = $this->stockItemRepository->get($id)->getIsInStock();
$isInStock = false;

try {
$isInStock = $this->stockItemRepository->get($id)->getIsInStock();
} catch (NoSuchEntityException $e) {
// Ignoring error is safe
}

$isOutOfStockDisplay = $this->scopeConfig->getValue(
self::XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK,
Expand Down

0 comments on commit aa666ad

Please sign in to comment.