Skip to content

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

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
WaterSlide opened this issue Nov 6, 2016 · 16 comments
Closed

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

WaterSlide opened this issue Nov 6, 2016 · 16 comments
Assignees
Labels
bug report Component: Catalog Event: distributed-cd Distributed Contribution Day Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@WaterSlide
Copy link

In versions 2.1.1 and 2.1.2, setting custom options for a product with fix price settings will not allow a negative value. I'm not sure if this is a simple ui problem or if there is a validator issue. Either way, this was always an option in Magento 1.x in which you can set discounts on an item via custom option. Uploading values via CSV works correctly, however making admin view changes for given product will fail validation via negative values.

Preconditions

  1. Magento 2.1.2
  2. PHP 7

Steps to reproduce

  1. Freshly install Magento.
  2. Create product with a custom option.
  3. Attempt to place a negative value in the custom option price input.

Expected result

  1. Item validates and clients using the custom option allows a price reduction.

Actual result

  1. Cannot save item. Validator fails.

capture

@rganin rganin added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog 2.1.x labels Nov 7, 2016
@rganin
Copy link
Contributor

rganin commented Nov 7, 2016

Thank you for reporting. Internal issue created: MAGETWO-60573

@SahakTadevosyan
Copy link

SahakTadevosyan commented Jan 12, 2017

Hi @WaterSlide did you fix this issue?
I have the same issue in Magento 2.1.3

@WaterSlide
Copy link
Author

WaterSlide commented Jan 21, 2017

I am aware that editing the Magento core is a no-no, however I am pressed for time and needed a very quick fix. I'll be learning how to override things the proper way any day now....

A nice gentleman was kind enough to email me what he found:

vendor/magento/module-catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Set false for validate-zero-or-greater

vendor/magento/module-catalog/Model/Product/Option/Validator/DefaultValidator.php

protected function isNegative($value)
{
//return intval($value) > 0;
return false;
}

The code speaks for itself. The isNegative will always return false. I am not sure what other implications there are for doing it this way, however I have tested that a negative value will still offset the price as intended.

@EmilyPepperman
Copy link
Contributor

I have this issue as well! Needs to be solved in core Magento... thank you WaterSlide for the solution for now. :-)

@iamjonjackson
Copy link

I need this also

@miro91
Copy link

miro91 commented May 25, 2017

@WaterSlide I tried your solution but it still give me "Invalid option value" error when I try to set negative price to some custom option.

@zaaaidi
Copy link

zaaaidi commented Jun 12, 2017

@WaterSlide Thanks alot. Its really works for me.

@robgt
Copy link

robgt commented Aug 7, 2017

Any news on a fix for this issue?

1 similar comment
@tejashp77
Copy link

Any news on a fix for this issue?

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Sep 11, 2017
@ic3b0x
Copy link

ic3b0x commented Sep 21, 2017

Thanks @WaterSlide for the quick fix! Having one last cosmetic issue, the frontend still shows a + sign before the -. Anyone knows how to remove it?

screen shot 2017-09-21 at 7 00 23 pm

@magento-engcom-team
Copy link
Contributor

@WaterSlide, thank you for your report.
We've created internal ticket(s) MAGETWO-60573 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.2.x Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 11, 2017
@seanscott49
Copy link

Thanks for the fix. It works on Radio, but Drop Down adds a +- in front of the number. I really hope this gets fixed soon. I have 2 sites to migrate after the holidays that depend on it.

@heidiboh
Copy link

heidiboh commented Dec 4, 2017

I'm running M 2.2.1. This remains an issue. We need to be able to set a negative value for price in the product's "customizable options" section. What is the progress on MAGETWO-60573?... or should I use this solution below?

vendor/magento/module-catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Set false for validate-zero-or-greater

vendor/magento/module-catalog/Model/Product/Option/Validator/DefaultValidator.php

protected function isNegative($value)
{
//return intval($value) > 0;
return false;
}

@luckyduck
Copy link

luckyduck commented Jan 27, 2018

I've created a pull request for this issue, for future releases. In case you run into this, here is a fix for 2.1.x (tested on 2.1.9):

https://github.com/luckyduck/negative-option-value

It also solves the cosmetic frontend issue, where negative option values have a plus sign as prefix (like +-3,50)

@ishakhsuvarov ishakhsuvarov added the Event: distributed-cd Distributed Contribution Day label Mar 23, 2018
@mszydlo mszydlo self-assigned this Mar 24, 2018
magento-engcom-team pushed a commit that referenced this issue Jul 5, 2018
Fixed issues:
  - MAGETWO-90496: Countries from default website set when edit order address
  - MAGETWO-90999: Bundle Product not appears in catalog after import
  - MAGETWO-60573: [GITHUB] Custom option price field disallows negative values #7333
@mattryding
Copy link

I tried to use Luckyduck's module on Magento 2.2.5 but this caused a problem in the Admin backend where under Customisable Options there would be no boxes to enter $ values.

To fix this, I edited:
Ui\DataProvider\Product\Form\Modifier\CustomOptions.php

Modify from line 25 onwards:

class CustomOptions extends Options
{
    protected function getPriceFieldConfig($sortOrder)
    {
        return [
            'arguments' => [
                'data' => [
                    'config' => [
                        'label' => __('Price'),
                        'componentType' => Field::NAME,
                        'component' => 'Magento_Catalog/js/components/custom-options-component',
                        'formElement' => Input::NAME,
                        'dataScope' => static::FIELD_PRICE_NAME,
                        'dataType' => Number::NAME,
                        'addbefore' => $this->getCurrencySymbol(),
                        'addbeforePool' => $this->productOptionsPrice->prefixesToOptionArray(),
                        'sortOrder' => $sortOrder,
                        'validation' => [
                            'validate-zero-or-greater' => false
                        ],
                    ],
                ],
            ],
        ];
    }
}

@magento-engcom-team
Copy link
Contributor

Hi @WaterSlide

This issue is now fixed and it's expected to be delivered with the upcoming 2.2.6 release. Meanwhile, you may use this commit as a reference 8d4124c

Thanks

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Sep 7, 2018
magento-engcom-team added a commit that referenced this issue Jan 14, 2019
…d price in admin view. #15267

 - Merge Pull Request #15267 from dverkade/magento2:2.3-Fix-7333-negative-value-for-custom-option
 - Merged commits:
   1. dc4de31
   2. f7aab57
   3. 9a8e7af
   4. 04caefa
   5. 8b7f1f2
   6. d43a52f
   7. d66329a
   8. 08ea73c
   9. 6baf928
   10. 4927e56
magento-engcom-team pushed a commit that referenced this issue Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Event: distributed-cd Distributed Contribution Day Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests