-
Notifications
You must be signed in to change notification settings - Fork 254
Add possibility To Delete Stocks in Admin Panel #101
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
Conversation
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 ($stockId=== null) {
$this->messageManager->addErrorMessage(__('Wrong request.'));
$resultRedirect->setPath('*/*');
return $resultRedirect;
it is shorter and better maintainable @see https://phpmd.org/rules/cleancode.html#elseexpression
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.
You can also simplify with
if ($this->getRequest()->isPost() !== true) {
$this->messageManager->addErrorMessage(__('Wrong request.'));
return $this->resultRedirectFactory->create()->setPath('*/*');
}
Then you don't nee the else @see https://phpmd.org/rules/cleancode.html#elseexpression
3971aa7
to
3f7f271
Compare
|
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.
Please, don't use such alignments
just make a space after type before the variable declaration
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.
don't try to make the fancy alignment.
It's hard to read and in any case it would be broken along the code evolution
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.
It's preferable to use explicit Extension Points than Registry.
Because usage of Registry is forbidden for newly created code
as it introduces mutable global state
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.
please fix the formatting
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.
Please provide a description for all public methods
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.
please fix the author PHP Doc Block
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.
please fix formatting
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.
I prefer to use next syntax :
array_map(function(\Magento\Framework\Api\Search\DocumentInterface $item) {
return $item->getId();
}, $searchResult->getItems());
Doing that way you can ensure the type validation of the array returned
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.
wan't -> want
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.
was -> would be
3f7f271
to
f6fb89e
Compare
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.
dependency on Context is not recommended. As Context is a container for other objects.
Use dependencies on the precise components you are dependent on
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.
This code
$this->context->getRequest()->getParam(StockInterface::STOCK_ID)
violates the Law of Demeter https://en.wikipedia.org/wiki/Law_of_Demeter
which is one of the good design guidelince for developing Object Oriented software
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.
it's preferable to use Composition over Inheritance,
so try to not inherit from GenericButton, but just inject it as Constructor Dependency
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.
I see a violation of encapsulation and Law of Demeter here.
Because current code is equivalent to
$this->filter->getComponent()->getContext()->getDataProvider()->getSearchResult()
@naydav is it really recommended way of applying Filtering?
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.
GitHub issue number magento/magento2#10988
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.
in both Delete and MassDelete we have a duplication of this constant, that means that it should be declared in another place.
Because currently, such code violates DRY
f6fb89e
to
9300183
Compare
} catch (CouldNotDeleteException $e) { | ||
$errorMessage = __('[ID: %1] ', $id) . $e->getMessage(); | ||
$this->messageManager->addErrorMessage($errorMessage); | ||
} |
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 about NoSuchEntityException?
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.
I think that it is not necessary because deleteById method throw CouldNotDeleteException and this scenario is served. See Magento\InventoryApi\Api\StockRepositoryInterface
.
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.
@bartekszymanski correct
-- slight refactoring
-- slight refactoring
-- code style fixes
[Sidecar] MQE-2528: Create automated test for: [MSI] "Tables data updated when SKU of Simple product has been changed from Admin"
Description
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist