Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved with NoSuchEntityException catch for item in stock #3

Merged
merged 2 commits into from
Jan 22, 2021
Merged

Improved with NoSuchEntityException catch for item in stock #3

merged 2 commits into from
Jan 22, 2021

Conversation

winniepukki
Copy link
Contributor

No description provided.

@winniepukki
Copy link
Contributor Author

Referencing the original issue

Comment on lines 144 to 149
try {
$isInStock = $this->stockItemRepository->get($id)->getIsInStock();
throw new NoSuchEntityException();
} catch (NoSuchEntityException $e) {
// Ignoring error is safe
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on here? So you throw the error manually to achieve what? This seem to me to work OK even without doing that throw new NoSuchEntityException();.

@@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey!
If stockItemRepository fails to get stock status by product id is it really means that this product is out of stock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AleksandrsKondratjevs Technically yes. If we are unable to get the product, how can we verify the stock?

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ignoring the error I would return null; but it is a preference. Merging.

@alfredsgenkins alfredsgenkins merged commit aa666ad into scandipwa:master Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants