-
Notifications
You must be signed in to change notification settings - Fork 6
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
Improved with NoSuchEntityException catch for item in stock #3
Conversation
Referencing the original issue |
src/Model/Resolver/EntityUrl.php
Outdated
try { | ||
$isInStock = $this->stockItemRepository->get($id)->getIsInStock(); | ||
throw new NoSuchEntityException(); | ||
} catch (NoSuchEntityException $e) { | ||
// Ignoring error is safe | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
No description provided.