-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Product name not shown in message when trying to add more products to cart then there are in stock #8660
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
Product name not shown in message when trying to add more products to cart then there are in stock #8660
Changes from all commits
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 |
---|---|---|
|
@@ -106,6 +106,10 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ | |
{ | ||
$result = $this->objectFactory->create(); | ||
$result->setHasError(false); | ||
|
||
$product = $this->productFactory->create(); | ||
$product->load($stockItem->getProductId()); | ||
$stockItem->setProduct($product); | ||
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. Also, there is unit test failure:
Is there a way to achieve the same using only defined interfaces? 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. @orlangur 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. I do believe that the code works ;) The problem is that this method is not part of Lame way is just add Better way is achieve the same correct behavior but use only defined contracts and do not rely on existing implementation. Why wrong product instance appear in 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. as your method accepts StockItemInterface as parameter, you should rely just on the contract provided by this interface https://github.com/magento/magento2/blob/develop/app/code/Magento/CatalogInventory/Api/Data/StockItemInterface.php |
||
|
||
$qty = $this->getNumber($qty); | ||
|
||
|
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.
Why not use
ProductRepository
here? Is product name always missing or only in some cases?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.
@orlangur the name is always missing, because there is no product available.
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.
If you need to load Product you have to rely on ProductRepostioryInterface::get method.
loading product using the load method of Product Model you are using deprecated method of Abstract Model https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Model/AbstractModel.php#L526