Skip to content

[Forwardport] Improvement: Magento\Sales\Helper\Guest refactoring and bugfix #11

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 27, 2018

Conversation

rostyslav-hymon
Copy link
Owner

Original Pull Request

magento#12893
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)

@rostyslav-hymon rostyslav-hymon merged commit 8232732 into 2.3-develop Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants