Skip to content

Improvement: Magento\Sales\Helper\Guest refactoring and bugfix #12893

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

Merged
merged 2 commits into from
Mar 24, 2018
Merged

Improvement: Magento\Sales\Helper\Guest refactoring and bugfix #12893

merged 2 commits into from
Mar 24, 2018

Conversation

coderimus
Copy link
Contributor

@coderimus coderimus commented Dec 27, 2017

Dear Magento2,

This PR consists of several improvements and bug fixes. The main goal of it is to increase performance and logic side of the Magento\Sales\Helper\Guest. Please, review Description section for more information.

Looking forward to your reply,
Alex

Description

The main improvements here are in the Magento\Sales\Helper\Guest::getOrderRecord($incrementId)

  1. Added store_id as filter to search criteria to improve logic/performance and due to this fact the Magento\Sales\Helper\Guest::validateOrderStoreId($orderStoreId) can be removed.

  2. Replaced

        if ($records->getTotalCount() < 1) {
            throw new InputException(__($this->inputExceptionMessage));
        }
        $items = $records->getItems();
        return array_shift($items);

with

        $items = $records->getItems();
        if (empty($items)) {
            throw new InputException(__($this->inputExceptionMessage));
        }

        return array_shift($items);

This allows Magento to reduce the number of database queries because every time when the getTotalCount() is called it initiates the getSize() method which checks the $this->_totalRecords value but in this case it equals to null every new call because every new call begins after page load.

  1. Moved $this->hasPostDataEmptyFields($post) to ternary operator because this is good to have all conditions according to order in one place.

  2. Fixed typo compareSoredBillingDataWithInput to compareStoredBillingDataWithInput

  3. Removed underscore private $_storeManager; to private $storeManager; (PSR-2: Property names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility.)

Fixed Issues (if relevant)

No relevant issue.

Manual testing scenarios

Those changes didn't change business logic. Only code improvement and, as a result, no manual testing scenarios.

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 on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Dec 27, 2017

CLA assistant check
All committers have signed the CLA.

@orlangur orlangur self-assigned this Dec 28, 2017
@coderimus
Copy link
Contributor Author

Hello @orlangur !

Thank you for your attention to my PR and self-assigned. Could you please update me with a possible date when you will have time to check it?

Looking forward to your reply,
Alex

@orlangur orlangur added this to the January 2018 milestone Jan 5, 2018
@coderimus
Copy link
Contributor Author

Hi @orlangur ,
Just want to send you a friendly reminder about this PR :) I see that you have a lot of work and you always review latest changes but when you will have a time, pls, check it.

Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

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

Hi @coderimus,

  1. Moved $this->hasPostDataEmptyFields($post) to ternary operator because this is good to have all conditions according to order in one place.

This changed logic a bit actually loading from cookie when it didn't load from cookie before but I didn't find any negative consequences of this.

No objections from implementation side, LGTM, small note on

Those changes didn't change business logic. Only code improvement and, as a result, no manual testing scenarios.

actually, we need to perform manual testing to assure the changes didn't change the logic unless we determined it is covered with some automated tests.

@magento-engcom-team
Copy link
Contributor

Hi @orlangur, thank you for the review.
MAGETWO-86399 has been created to process this Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants