magento 2自定义日历而不是核心日历

时间:2019-04-03 23:19:44

标签: php jquery-ui magento magento2 persian-calendar

我要创建jalaali日历(波斯日历)而不是magento 管理员和首页的核心日历。

为此,我已将以下行添加到模块中的requirejs-config中:

   'map': {
       '*': {
          'mage/calendar' : 'MyNamespace_MyModule/js/persian_calendar',
         'Magento_Ui/js/form/element/date' : 'MyNamespace_MyModule/js/form/element/date_form'

        }
    }

波斯日期和公历日期完全不同,并且它们的年,月和日名称也不同。我想向用户显示波斯语日期,但将日期以公历格式保存到数据库。

用于将公历日期发送到服务器,我已更改 onShiftedValueChange  函数,我在自定义date_form中执行此操作:

onShiftedValueChange: function (shiftedValue) {
        var value,
            formattedValue,
            formattedValueUTC,
            momentValue;

        // this is very simple code that check if selected date is gregorian date or persian date  
        var englishYears = ["2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026",
            "2027", "2028", "2029", "2030", "۲۰۱۸", "۲۰۱۹", "۲۰۲۰", "۲۰۲۱", "۲۰۲۲", "۲۰۲۳", "۲۰۲۴",
            "۲۰۲۵", "۲۰۲۶", "۲۰۲۷", "۲۰۲۸", "۲۰۲۹", "۲۰۳۰"];
        var englishDate = false;
        for (var i = 0; i < 26; i++) {
            if (shiftedValue.indexOf(englishYears[i]) > -1) {
                englishDate = true;
                break;
            }
        }

        if (shiftedValue) {

            // if selected date was persian,I converted it to equivalent gregorian format, for converting dates I used https://github.com/jalaali/moment-jalaali library 
            if (!englishDate) { 
                shiftedValue = jMoment.from(shiftedValue, 'fa', 'DD/MM/YYYY HH:mm').format(this.pickerDateTimeFormat);
            }

            // the rest codes are for magento itself
            momentValue = moment(shiftedValue, this.pickerDateTimeFormat);
            if (this.options.showsTime) {
                formattedValue = moment(momentValue).format(this.timezoneFormat);
                formattedValueUTC = moment.tz(formattedValue, this.storeTimeZone).tz('UTC');
                value = this.outputDateTimeToISO ?
                    formattedValueUTC.toISOString() :
                    formattedValueUTC.format(this.outputDateTimeFormat);
            } else {
                value = momentValue.format(this.outputDateFormat);
            }
        } else {
            value = '';
        }

        if (value !== this.value()) {
            this.value(value);
        }
    }
这些代码等效的

格里历日期已正确发送到服务器,但是 当我检查存储在数据库中的值时,它是完全不同且无效的,例如,我发送了此值: 4/14/2019 5:30 am ,但是magento将其转换为: 0010-08 -10 05:30:00 !!

我认为也许自定义date_form中的格式日期与magento形式php代码中的格式日期不同,导致此问题,因为当我将this.outputDateTimeFormat参数更改为例如:“ YYYY / DD / MM HH:mm” ,存储的值已更改,并且它具有有效的格式值(例如:“ 2023-08-10 05:30:00”),但是它的值与已发送的值仍然不同,并且不相等。

我不知道magento在哪里检查输入日期并将其更改为错误的值。

有人知道magento在哪里检查日期输入并进行更改吗? 要么 有人为此目的有完全不同的想法吗?

0 个答案:

没有答案