Skip to content
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

Fix bug 27490: Can't change customer group when placing an admin order #27501

Closed
wants to merge 13 commits into from

Conversation

tna274
Copy link
Contributor

@tna274 tna274 commented Mar 30, 2020

Description (*)

Fix bug 27490: Can't change customer group when placing an admin order

Related Pull Requests

Fixed Issues (if relevant)

  1. Can't change customer group when placing an admin order #27490: Fix bug 27490: Can't change customer group when placing an admin order

Manual testing scenarios (*)

  1. In Admin System > Configurations > Customers > Customer Configurations > Create New Account Options > Enable Automatic Assignment to Customer Group >> Select YES
  2. In Admin Sales > Orders.
  3. Select Create New Order
  4. Select Create New Customer
  5. Under Account Information, change the group.

Questions or comments

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 Mar 30, 2020

Hi @tna274. 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

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

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.

Hi @tna274
Thanks for your contribution.

Please change your code according to Magento technical guideline

Also please consider refactoring this class.
Instead of introducing new code complexity try to separate implementation for adminhtml and frontend introducing 2 observers and declare them at respective levels via events.xml
To avoid code duplication please use decomposition.

@tna274
Copy link
Contributor Author

tna274 commented Apr 3, 2020

Hi @Stepa4man
I have updated my pull request

@ghost ghost added Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Priority: P3 May be fixed according to the position in the backlog. labels Jul 20, 2020
@engcom-Charlie
Copy link
Contributor

Hi, @tna274 can you please look through failed tests and merge conflicts?

@engcom-Kilo engcom-Kilo self-assigned this Jul 30, 2020
@engcom-Kilo
Copy link
Contributor

@magento run all tests

@engcom-Kilo
Copy link
Contributor

Working with MFTF test.

@engcom-Kilo
Copy link
Contributor

@magento run Magento Health Index

@engcom-Kilo
Copy link
Contributor

@magento run Static Tests

@engcom-Kilo
Copy link
Contributor

Added MFTF test.

@engcom-Kilo
Copy link
Contributor

@magento run Functional Tests B2B

@engcom-Kilo
Copy link
Contributor

@magento run all tests

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.

Hi @tna274
Thanks for your contribution.

Please take a look at my comments.

*/
protected function assignCustomerGroupConditions($groupId)
{
return $groupId !== null ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need it here? Why don't you just write return $groupId !== null?

Comment on lines +71 to +79
if ($groupId !== null
&& !(
$this->state->getAreaCode() == Area::AREA_ADMINHTML
&& $groupId == $this->groupManagement->getNotLoggedInGroup()->getId()
)) {
return true;
}

return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put those long difficult conditions to separate private methods with proper naming and shorten this function to just return statement:
return $groupId !== null && !($this->isAdminArea() && $this->isNotLoggedInGroup($groupId));
At least like this.

You can think even more to make this code more readable.

/**
* @var \Magento\Quote\Observer\Backend\Quote\Address\CollectTotalsObserver
*/
protected $model;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please replace all protected properties with private.

protected $model;

/**
* @var MockObject
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the proper type annotation to all class properties

*/
protected function setUp()
{
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
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 use ObjectManager helper, use new statement instead.

$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->storeId = 1;
$this->customerMock = $this->getMockForAbstractClass(
\Magento\Customer\Api\Data\CustomerInterface::class,
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 class names.

Comment on lines +73 to +74
$this->state->getAreaCode() == Area::AREA_ADMINHTML
&& $groupId == $this->groupManagement->getNotLoggedInGroup()->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 strict comparison operator

@@ -0,0 +1,488 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

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

Please declare strict types for every php file

@sidolov
Copy link
Contributor

sidolov commented Nov 11, 2020

@tna274 I am closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for the collaboration!

@sidolov sidolov closed this Nov 11, 2020
@m2-assistant
Copy link

m2-assistant bot commented Nov 11, 2020

Hi @tna274, 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
Component: Quote Priority: P3 May be fixed according to the position in the backlog. Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants