Skip to content

Modify price-utils.js by mixin

I’m trying to modify price-utils.js to add function that change price numbers to English.

I’ve created price-utils-mixin.js in VendorThemewebjs:

define([
    'jquery',
    'underscore'
   ],
    function ($, _) {
        'use strict';
        return function (target) {

            target.formatPrice = function formatPrice(amount, format, isShowSign) {
                function convertToEnglishNumbers(str) {
                var arabicToEnglishMap = {
                    '٠': '0', '١': '1', '٢': '2', '٣': '3', '٤': '4', '٥': '5', '٦': '6', '٧': '7', '٨': '8', '٩': '9'
                };
                return str.replace(/[٠-٩]/g, function (d) {
                    return arabicToEnglishMap[d];
                });
                }
            };

            return target;
    };
});

Then I’ve created requirejs-config.js in VendorTheme:

var config = {
    'config': {
        'mixins': {
            'Magento_Catalog/js/price-utils': {
                'js/price-utils-mixin': true
            }
        }
    }
};

When I check through network tab in my browser I see my mixin file but the function didn’t work because the numbers didn’t change to English !

Could you please help me in this.