0

Easy question:

How or where do I change the decimal separator in de admin html area?

Is it even possible? It is set to a dot. I want to change it to a comma so the below error message disappears. In frontend area everything is fine.

price decimal separator

2 Answers 2

0

If you want to change the price format only in the admin product price field, you can modify the template file that renders the price field in the admin area. Here are the steps to achieve this:

  1. Create a custom module or use an existing one.

  2. In your module, create a file named catalog_product_prices.xml under the path app/code/[Vendor]/[Module]/view/adminhtml/layout/.

  3. Add the following content to the catalog_product_prices.xml file:

     <?xml version="1.0"?>
        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
     <body>
         <referenceBlock name="product_form.price">
             <arguments>
                 <argument name="config" xsi:type="array">
                     <item name="currency_symbol" xsi:type="string">€</item> <!-- Replace with your currency symbol -->
                     <item name="decimalSymbol" xsi:type="string">,</item> <!-- Change decimal symbol to comma -->
                     <item name="digitalGroupSpacing" xsi:type="string">3</item>
                     <item name="decimalPlaces" xsi:type="number">2</item>
                     <item name="value" xsi:type="string"></item>
                 </argument>
             </arguments>
         </referenceBlock>
     </body>
    
  4. The above XML code will set the currency symbol, decimal symbol, and decimal places for the product price field in the admin area.

  5. Clear the cache and refresh the admin page to see the changes.

After completing these steps, the price field in the admin area will display prices in the format that you specified in the catalog_product_prices.xml file.

1
  • Can't get it working on M 2.4.5-p1
    – Akif
    Mar 17, 2023 at 9:55
0

The solution is to rewrite rule (to the old one) validate-zero-or-greater. [Vendor]/[Module]/view/base/requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_Ui/js/lib/validation/validator': {
                'Vendor_Module/js/lib/validation/validator-mixin': true
            }
        }
    }
};

[Vendor]/[Module]/view/base/web/js/lib/validation/validator-mixin.js

define([
    'jquery',
    'Magento_Ui/js/lib/validation/utils'
], function ($, utils) {
    'use strict';

    return function (validator) {

        // override new rule to old one
        validator.addRule(
            'validate-zero-or-greater',
            function (value, params, additionalParams) {

                if (utils.isEmptyNoTrim(value)) {
                    return true;
                }
                value = utils.parseNumber(value);

                return !isNaN(value) && value >= 0;

            },
            $.mage.__('Please enter a number 0 or greater in this field.')
        );

        return validator;
    };
});

Tested on Magento 2.4.5-p1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.