-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,7 +139,14 @@ 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(); | ||
throw new NoSuchEntityException(); | ||
} catch (NoSuchEntityException $e) { | ||
// Ignoring error is safe | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of ignoring the error I would |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
$isOutOfStockDisplay = $this->scopeConfig->getValue( | ||
self::XML_PATH_CATALOGINVENTORY_SHOW_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.
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?