Skip to content

Allow negative price for custom option: fixes #7333 in GitHub (internal MAGETWO-60573) #13393

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

Closed

Conversation

luckyduck
Copy link

@luckyduck luckyduck commented Jan 26, 2018

Description

The price for custom options should be allowed to be negative. The contained changes do just that. In addition, a cosmetic problem is solved. Once options are allowed to be negative, available options (in a drop-down) add a plus sign as prefix to the price, resulting in '+-1,50 €" for a negative option price (-1,50 in this example). This is fixed as well.

Fixed Issues (if relevant)

  1. Unable to set negative custom option fixed price in admin view. #7333: Unable to set negative custom option fixed price in admin view

Manual testing scenarios

  1. Add a custom option to any product.
  2. Enter a negative price (for example -3) for a custom option, see Unable to set negative custom option fixed price in admin view. #7333 for details.
  3. Save the product
  4. Visit the product url
  5. Take a look at the Drop-Down (select element). You'll find the option text like "+-3 €" (or dollar)

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 Jan 26, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@luckyduck
Copy link
Author

luckyduck commented Jan 26, 2018

Just signed the CLA (and added the mail address to my github account as well)

@luckyduck luckyduck changed the title Cosmetic fix for #7333 in GitHub or internal ticket id MAGETWO-60573 Allow negative price for custom option: fixes #7333 in GitHub (internal MAGETWO-60573) Jan 27, 2018
@@ -84,7 +84,7 @@ public function testIsValidTitle($title, $type, $priceType, $price, $product, $m
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
$valueMock->expects($this->any())->method('getType')->will($this->returnValue($type));
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
$valueMock->expects($this->never())->method('getPrice')->will($this->returnValue($price));
Copy link
Contributor

Choose a reason for hiding this comment

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

If the method should never be called, the will is not necessary (and will probably confuse the reader). 

{
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
$valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue($type));
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
$valueMock->expects($this->never())->method('getPrice')->will($this->returnValue($price));
Copy link
Contributor

Choose a reason for hiding this comment

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

The same here.

$this->assertFalse($this->validator->isValid($valueMock));
$this->assertEquals($messages, $this->validator->getMessages());
$this->assertTrue($this->validator->isValid($valueMock));
$this->assertNotEquals($messages, $this->validator->getMessages());
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose making the check more specific, i.e., to check for the expected messages instead.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you so much for your feedback! Will make the proposed changes and improve the tests.

…nvalid price types fail. Also makes sure price is not relevant for validation (assert that getPrice is not called)
@luckyduck
Copy link
Author

Updated tests, to reflect the new situation:

  • price is not relevant, make sure getPrice is not called during validation
  • make sure valid price types are recognized as valid and invalid types cause error messages

@dmanners
Copy link
Contributor

Hi @luckyduck could you take a look at the merge conflict for me please, then I can process this PR.

@dmanners dmanners self-assigned this May 24, 2018
@luckyduck
Copy link
Author

Oh, of course. Can you give me a hint, how best to do this?

@dmanners
Copy link
Contributor

I would recommend updating your main 2.2-develop branch from our repository and then updating your branch from this.

First you need to add a new remote.

git remote add upstream [email protected]:magento/magento2.git
git fetch -ap upstream

Then when you are checked out on your feature branch you can rebase on the upstream/2.2-develop branch rather than the origin/2.2-develop branch.

git rebase -i upstream/2.2-develop

It will then ask you which commits you would like and it will also ask you to fix any conflicts that you come across.

@dmanners
Copy link
Contributor

Hi @luckyduck thank you for this PR. I am currently doing a couple of things.

  1. Checking with the core team about the history of not allowing negative prices to make sure we do not miss something,
  2. Working out the differences between this PR and [Bugfix] #7333 Unable to set negative custom option fixed price in admin view. #15267 and Add ability to set custom product option with negative price #14342 to see as to which one is the preferred fix.

I will update you via this PR once I have some more information. Thank you for your patience.

@dmanners
Copy link
Contributor

Hi @luckyduck thank you for your pull request. I am closing this pull request as it has been covered by #15267.

@dmanners dmanners closed this Jul 11, 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.

4 participants