cancel
Showing results for 
Search instead for 
Did you mean: 

UK date for 'delivery date'

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

UK date for 'delivery date'

Hi,

 

 

I have added a new field called "delivery_date" on checkout page, and added a column (Datetime) on sales_order table.

I have made it work to save the delivery date, however the datepicker is picking up the US date in mm/dd/yyyy format.

I would like to change the format to UK date dd/mm/yyyy.

 

on LayoutProcessorPlugin.php

 

            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['delivery_date'] = [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'inputDateFormat' => 'dd/MM/Y',
                'storeTimeZone' => 'GMT',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                //    'elementTmpl' => 'ui/form/element/date',
                       'elementTmpl' => 'Vendor_Module/deliverydate_init',
                    'options' => [],
                    'id' => 'delivery-date'
                ],
                'dataScope' => 'shippingAddress.delivery_date',
                'label' => 'Delivery Date',
                'provider' => 'checkoutProvider',
                'visible' => true,
                'validation' => [],
                'sortOrder' => 200,
                'id' => 'delivery-date'
            ];

on deliverydate_init.html

<?php $date = $block->quote->getDeliveryDate(); ?>
<script>
    require([
        "jquery",
        "jquery/ui",
        'uiRegistry'
    ], function($, ui, registry){
        registry.set('Vendor_Module_initDatepicker', function(element)
        {
            var beforeShowDay = function(date)
            {
                var excludeWeekdays = [<?php echo $block->helper->getConfigExcludedWeekdays(); ?>];

                var holidays = [];
                //holidays with * as year will get current and next year, become two holidays
                <?php foreach ($block->getHolidays() as $holiday): ?>
                holidays.push(<?php echo strtotime($holiday) * 1000; ?> );
                <?php endforeach; ?>

                function checkHolidays(date, holidays)
                {
                    var result = true;
                    $.each(holidays, function(index, holiday){
                        var holiday = new Date(holiday);
                        if(isDateEqual(date, holiday))
                        {
                            result = false;
                        }
                    });
                    return result;
                }

                function checkWeekdays(date, excludeWeekdays)
                {
                    return $.inArray(date.getDay(), excludeWeekdays) == -1;
                }

                function isDateEqual(date1, date2)
                {
                    return date1.setHours(0,0,0,0) == date2.setHours(0,0,0,0);
                }

                var result =    checkHolidays(date, holidays) && checkWeekdays(date, excludeWeekdays);
                return [result, ''];
            };

            var minDate = <?php echo $block->helper->getConfigMinDelayDays(); ?>;
            if(minDate == 0)
            {
                if(<?php echo json_encode($block->helper->isDisableAfterSameDayTime()) ?>)
                {
                    minDate = 1;
                }
            }

            if($(element).length > 0)
            {
                $(element).datepicker(
                    {
                        minDate : minDate,
                        maxDate : <?php echo $block->helper->getConfigMaxDelayDays(); ?>,
                        dateFormat: "<?php echo $block->convertDateFormatToJQueryUi($block->helper->getConfigDateFormat()); ?>",
                        beforeShowDay : beforeShowDay
                    }
                );
            }
            else
            {
                return {
                    minDate : minDate,
                    maxDate : <?php echo $block->helper->getConfigMaxDelayDays(); ?>,
                    dateFormat: "<?php echo $block->convertDateFormatToJQueryUi($block->helper->getConfigDateFormat()); ?>",
                    beforeShowDay : beforeShowDay,
                    <?php if($date && $date != '0000-00-00 00:00:00'):?> //set date if it was saved in quote before
                    defaultDate : new Date(Date.parse('<?php echo $date ?>'.replace('-','/','g')))
                    <?php endif; ?>
                };
            }
        });
    });
</script>

I would like to know what change I need to make?

I have added below code but it does not make difference.

 'inputDateFormat' => 'dd/MM/Y', 
'storeTimeZone' => 'GMT'
1 REPLY 1

Re: UK date for 'delivery date'

Hello @tvgarden,

 

Thank you for sharing such good information and also a good question. If you want to know the difference between them you can use the Magento 2 Delivery Date and then ask the developer for this query I am sure you got the answer about that 

for the technical query contact sales@appjetty.com