magefan / module-blog

Magento 2 Blog Extension is a solution that helps you to create a blog on Magento and manage posts,categories, tags, authors, and comments.
https://magefan.com/magento2-blog-extension
Other
265 stars 136 forks source link

'Publish at' date format after upgrade from 2.07 to 2.10 is correct but cannot be saved #30

Closed PierAlex closed 7 years ago

PierAlex commented 8 years ago

Hi, My locale input format is dd/mm/yyyy Calendar picker for the 'publish at' date insert the date correctly (dd/mm/yyyy). Magento need the date in the mm/dd/yyyy date. The problem is in Magento; however, is there a workaround to solve it? Thanks.

magefan commented 8 years ago

@PierAlex what version do you using? have you the latest one (2.2.3)?

PierAlex commented 8 years ago

@magefan installed the last version, same error. image If I write manually the date in the format 07/28/2016, it goes on.

magefan commented 8 years ago

@PierAlex could you also tell what locale is setted on your magento and what locale is in your browser?

PierAlex commented 8 years ago

@magefan Chrome image

Magento image

Maybe it can halps: in Magento standard modules, the date is not always displayed in the same way. E.g. in the order grid, the purchase date is mmm, dd,yyyy.,.. but if I edit an order the same date is in dd/mmm/yyyy format. For products, 'Set Product as New From' and 'to' dates are in the format mm/dd/yyyy and the calendar picker provide the date in this format. image For catalog price rules, in the grid, the date fields displays dd/mmm/yyyy but in edit, dates are in mm/dd/yyyy and the calendar picker provide this format image

So it appears that there is not a standard, or that a standard is not respected in Maento standard modules, to display dates but there is a standard for dates input (mm/dd/yyyy) that not consider locales. Calendar pickers provides the same format mm/dd/yyyy.

In your case, the calendar provides tha date in the format dd/mm/yyyy that is correct for locale input but not for Magento standard.

For query filters such as orders reporting, the picker provide the date in the dd/mm/yyyy but those fields doesn't need to be saved. image

Ale

PierAlex commented 8 years ago

I just added an issue for magento. I think this is a Magento Issue. For a workaround it may be useful to have the picker in the Magento "standard" input format (mm/dd/yyyy) and an additional label that tells who inserts posts that the format for the date is mm/dd/yyyy to avoid wrong insertions (for dd<=12).

YATB

PieterCappelle commented 8 years ago

Having the same problem on Magento 2.1.0. Any updates on this?

magefan commented 8 years ago

@PieterCappelle, cannot replicate this issue on own test environments. Could you please contact us (http://magefan.com/contact/), so we can check on your side, and provide a solution for the community?

JacobDrummond commented 8 years ago

Preconditions

  1. PHP 5.6.16
  2. MySQL 5.6.21-log
  3. Nginx 1.4.6
  4. Magento 2.1.0 5 Install Magefan_Blog 2.2.4

Steps to reproduce

  1. In System > All Users > User > [You], set the interface locale to English (United Kingdom): blog-3
  2. Set blog post date to value where day is >12. (This is important, as Magento will wrongly guess that days <12 are months, meaning no validation error): blog-1

Expected result

  1. Successfully save blog post with new date

Actual result

  1. Validation error on UK-formatted date: blog-2

Cause

  1. Magefan (correctly) changes date format by locale in form block
  2. Magento appears to ignore date locale when processing forms. For example, dates in admin product forms are all American-format regardless of locale.

Solution

  1. Ignore locale date format until the rest of Magento catches up with Magefan?
JacobDrummond commented 8 years ago

Temporary solution

app\code[Developer][YourModule]\etc\adminhtml\events.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="magefan_blog_post_edit_tab_main_prepare_form">
        <observer name="[Developer]_[YourModule]_Observer_BlogPrepareForm" instance="[Developer]\[YourModule]\Observer\BlogPrepareForm" />
    </event>
</config>

app\code[Developer][YourModule]\Observer\BlogPrepareForm.php:

<?php

namespace [Developer]\[YourModule]\Observer;

class BlogPrepareForm implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        /* @var \Magento\Framework\Data\Form $form*/
        $form = $observer->getEvent()->getForm();

        // Loop through form elements and set publish_time format to US
        foreach($form->getElements() as $fieldset)
        {
            foreach($fieldset->getElements() as $input)
            {
                if($input instanceof \Magento\Framework\Data\Form\Element\Date)
                {
                    $input->setDateFormat('MM/dd/y');
                }
            }
        }
    }
}
woakley commented 7 years ago

I've tried the fix above but am now getting:

Something went wrong while saving this posts. DateTime::__construct(): Failed to parse time string (0,9/1,7/2,016) at position 0 (0): Unexpected character

JacobDrummond commented 7 years ago

@woakley, a few date/locale issues were resolved in Magento2 #6323. If you patch-in that fix, and undo the one above, do blog dates work again?

magefan commented 7 years ago

We close this issue, as there was no new replies for a long time.

RForster92 commented 7 years ago

Experiencing this issue also in MG2.1.0. When trying to save/publish a blogpost, the datepicker adheres to the GB time, but then says "Please enter a valid date." as a message and won't save. If I type in the date in Americanized format, it then saves.

Is there any temporary solution until a proper fix at all?

firefox_screenshot_2017-01-06t09-47-21 557z

magefan commented 7 years ago

@RForster92 , are you using blog extension greater 2.3.0? Can't replicate it on v2.4.2

RForster92 commented 7 years ago

We are using v2.2.0 of the blog extension on version 2.1.0 of Magento2

magefan commented 7 years ago

@RForster92 , please update blog extension to the newest version (current newest version is 2.4.3). Beginning from version 2.3.0 our blog extension use new ui for admin forms, so the issue must gone.

kennedyabitbol commented 6 years ago

Hi,

Update blog is not working Magento 2.1.12, Magefan Blog 2.8.0

magefan commented 6 years ago

@kennedyabitbol , from what blog version you trying to update to v2.8.0 ?

kennedyabitbol commented 6 years ago

hi @magefan I already got 2.8.0 installed