Skip to content

#274 Admin Global Search: Search categories #28588

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

FredericMartinez
Copy link
Contributor

Description (*)

Global search in backend can search into products, orders, customers, pages and config sections.
Now we can search categories too.

Fixed Issues (if relevant)

  1. Fixes Admin Global Search: Search categories community-features#274

Manual testing scenarios (*)

  1. Login into backend
  2. Create a test category "Try to find me"
  3. Use global search (in header to right, next to admin account setting)
  4. Enter "to find"
  5. You will see in autocomplete list our new fresh category, link is valid and redirect to the edit form

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jun 5, 2020

Hi @FredericMartinez. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@FredericMartinez
Copy link
Contributor Author

@magento give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @FredericMartinez. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @FredericMartinez, here is your new Magento instance.
Admin access: https://pr-28588.instances.magento-community.engineering/admin_d843
Login: 6e383ff3 Password: 6b137e49e023
Instance will be terminated in up to 3 hours.

@FredericMartinez
Copy link
Contributor Author

It works like expected
28588_1
28588_2

@okorshenko
Copy link
Contributor

@magento run Unit Tests

@Stepa4man
Copy link
Contributor

@magento give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @Stepa4man. Thank you for your request. I'm working on Magento instance for you

@Stepa4man Stepa4man self-assigned this Jun 5, 2020
@Stepa4man
Copy link
Contributor

Hi @FredericMartinez
Thanks for your contribution.

I want to ask you to cover implemented functionality by tests according to DOD

Also please add to all changed (created) php files

    declare(strict_types=1);

You can read more here

Copy link
Contributor

@Stepa4man Stepa4man left a comment

Choose a reason for hiding this comment

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

@FredericMartinez
Please check out my comments.
I know you just implemented it as \Magento\CatalogSearch\Model\Search\Catalog
But it's quite an old class, If you have doubts about how to write code you can read this documentation

{
$this->_adminhtmlData = $adminhtmlData;
$this->categoryRepository = $categoryRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use searchCriteriaBuilderFactory here

$filters[] = $this->filterBuilder
->setField($field)
->setConditionType('like')
->setValue('%' . $this->getQuery() . '%')
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use sprintf here

foreach ($searchResults->getItems() as $category) {
$description = strip_tags($category->getDescription());
$result[] = [
'id' => 'category/1/' . $category->getId(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use sprintf here

Comment on lines 30 to 52
protected $_adminhtmlData = null;

/**
* @var \Magento\Catalog\Api\CategoryListInterface
*/
protected $categoryRepository;

/**
* @var \Magento\Framework\Api\SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;

/**
* @var \Magento\Framework\Api\FilterBuilder
*/
protected $filterBuilder;

/**
* Magento string lib
*
* @var \Magento\Framework\Stdlib\StringUtils
*/
protected $string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use a private access modifier

*
* @var \Magento\Backend\Helper\Data
*/
protected $_adminhtmlData = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't user underscore in property name it's an outdated approach

Comment on lines 57 to 68
* @param \Magento\Backend\Helper\Data $adminhtmlData
* @param \Magento\Catalog\Api\CategoryListInterface $categoryRepository
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
* @param \Magento\Framework\Stdlib\StringUtils $string
*/
public function __construct(
\Magento\Backend\Helper\Data $adminhtmlData,
\Magento\Catalog\Api\CategoryListInterface $categoryRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Framework\Api\FilterBuilder $filterBuilder,
\Magento\Framework\Stdlib\StringUtils $string
Copy link
Contributor

Choose a reason for hiding this comment

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

Please import all classes

protected $string;

/**
* Initialize dependencies.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we need comment here.

* @method array getResults()
* @api
*/
class Category extends \Magento\Framework\DataObject
Copy link
Contributor

Choose a reason for hiding this comment

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

Please import parent class

@okorshenko
Copy link
Contributor

Hi @Stepa4man
That's interesting PR. Let's review it with PO on Monday. I will send you an invitation for next triage session

@FredericMartinez
Copy link
Contributor Author

@Stepa4man Thanks you for your review.

I understand all your comments about style codings
But, my Magento example are: Magento\Backend\Model\Search\Customer

You can find almost a copy/paste from this class with a category filter instead of a customer filter.

Actually, I hesitated to write the class properly, but I assume to have the same old code style.
Indeed, when you will rewrite Magento\Backend\Model\Search\Customer and all the other Admin Global Search classes, you will be able to clean them all at one time, my PR included.

My point was to contributed as it, it works like the old stylish classes and I can get my git patch from this PR in my projects.

Thanks for your time @Stepa4man & @okobchenko
Have a nice week.

@Stepa4man
Copy link
Contributor

Hi @FredericMartinez, I understand your point but you should also understand us.
Yes, we definitely have some legacy code that requires cleaning up. But this is not the reason to deliver a new bad quality code. We have Magento coding standards and DoD and PR can be merged only if it follows these documents.
Thanks.

@Stepa4man Stepa4man added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Jun 10, 2020
@VladimirZaets VladimirZaets added Priority: P3 May be fixed according to the position in the backlog. Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. labels Jun 23, 2020
@engcom-Kilo engcom-Kilo self-assigned this Jul 21, 2020
@engcom-Kilo
Copy link
Contributor

Working on this .

@engcom-Kilo
Copy link
Contributor

Added correction for code.

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-8204 has been created to process this Pull Request

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Preconditions:

Magento 2.4-develop
Sample Data

Manual testing scenario:

  1. Login into backend;
  2. Use global search (in the header to right, next to admin account setting)
  3. Enter "Luma Yoga"

Before: ✖️ We don't see the specified category in the search list

2020-09-22_12-22

After: ✔️ we see in the autocomplete list our new fresh category, a link is valid and redirects to the edit form

2020-09-22_12-19

Peek 2020-09-22 12-33

@engcom-Alfa engcom-Alfa added the QA: Ready to add to Regression Scope Should be analyzed and added to Regression Testing Scope(if applicable) label Sep 22, 2020
@engcom-Alfa engcom-Alfa added QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope and removed QA: Ready to add to Regression Scope Should be analyzed and added to Regression Testing Scope(if applicable) labels Sep 22, 2020
@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@m2-assistant
Copy link

m2-assistant bot commented Oct 2, 2020

Hi @FredericMartinez, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: CatalogSearch Component: Search Priority: P3 May be fixed according to the position in the backlog. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Admin Global Search: Search categories
9 participants