Overriding / Hooking Date_Format In Php Or Smarty !?

Hi there,

I'm trying to override fn_date_format in fn.common but there isn't any hook, is there anyway around without compromising core !?

if it isn't possible :

is there any way to assign another function to date_format in smarty via addon?

for example here how it's used in smarty :

{$log.timestamp|date_format:"`$settings.Appearance.date_format`, `$settings.Appearance.time_format`"}

Is there any way to override it without overriding each template that is using this function?

Hello.

In your example is using date_format (standard function in php) not fn_date_format (function from Cs-Cart).

In your modifications, you can use whatever you want.

Best regards

Robert

What is it you are trying to accomplish that you can't achieve with date/time formats? You can always adjust the db to be whatever (or empty) date/time notation you want if you don't want to use the setting provided in the admin area settings.

If you do not have required format in the settings, you can add it. For example, in phpMyAdmin find the cscart_settings_variants table and add new record

variant_id: '' (empty)

object_id: 52

name: '%Y.%m.%d' (change according to your needs, check all available placeholders here https://www.smarty.net/docsv2/en/language.modifier.date.format.tpl)

position: 14

Then just select new format on the Settings -> Appearance pahe

Hello.

In your example is using date_format (standard function in php) not fn_date_format (function from Cs-Cart).

In your modifications, you can use whatever you want.

Best regards

Robert

It's using fn_date_fotmat, if you override it and you can see it gets change! it doesn't use standard php method

What is it you are trying to accomplish that you can't achieve with date/time formats? You can always adjust the db to be whatever (or empty) date/time notation you want if you don't want to use the setting provided in the admin area settings.

What I'm trying to accomplish is converting the date in templates to different calendar types for example :

if(CART_LANGUAGE === 'fa') {
    $format = str_replace('%', '', $format);
    $formatter = new IntlDateFormatter(
    'fa_IR@calendar=persian',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'Asia/Tehran',
    IntlDateFormatter::TRADITIONAL,
    $format);
return $formatter->format($timestamp);
}

adding different calendars like :

  • Japanese (@calendar=japanese)
  • Buddhist (@calendar=buddhist)
  • Chinese (@calendar=chinese)
  • Persian (@calendar=persian)
  • Indian (@calendar=indian)
  • Islamic (@calendar=islamic)
  • Hebrew (@calendar=hebrew)
  • Coptic (@calendar=coptic)
  • Ethiopic (@calendar=ethiopic)

If you do not have required format in the settings, you can add it. For example, in phpMyAdmin find the cscart_settings_variants table and add new record

variant_id: '' (empty)

object_id: 52

name: '%Y.%m.%d' (change according to your needs, check all available placeholders here https://www.smarty.net/docsv2/en/language.modifier.date.format.tpl)

position: 14

Then just select new format on the Settings -> Appearance pahe

definitely, a helpful tip which I need later, but as I explained in my previous post I want to add different calendar types, I don't want to change timestamp and how it's getting stored in DB or format, I want to change it in view ( templates ) based on language another example :

$IntlDateFormatter = new IntlDateFormatter(
‘es_ES@calendar=buddhist’,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
‘Australia/Yancowinna’,
IntlDateFormatter::TRADITIONAL
);
echo $IntlDateFormatter->format($timestamp);
// martes, 21 de julio de 2558 BE, 23:16:08 (Hora estándar de Australia central)

That would be nice if we could hook or edit fn_date_format without editing core or overriding every template that is using this function, I'm looking for a solution too

You would have to edit the smarty_plugins/modifier.date_format.php file to make the changes you want. It uses fn_date_format(). You can always request a hook be added to fn_date_format(). But cs-cart hasn't responded to the "request a hook" thread in the developer forum for over a year.

Note there are several FIXME lines in fn_date_format() so some changes may be coming in a future release.

definitely, a helpful tip which I need later, but as I explained in my previous post I want to add different calendar types, I don't want to change timestamp and how it's getting stored in DB or format, I want to change it in view ( templates ) based on language another example :

Please note that our solution will change timestamp format stored in database. It just adds new format which will be processed in templates only (in fn_date_format function)

You would have to edit the smarty_plugins/modifier.date_format.php file to make the changes you want. It uses fn_date_format(). You can always request a hook be added to fn_date_format(). But cs-cart hasn't responded to the "request a hook" thread in the developer forum for over a year.

Note there are several FIXME lines in fn_date_format() so some changes may be coming in a future release.

That's sad they won't listen to hook requests :(,

Thanks for smarty modifier hint, I think that would be the best place for now since it's less likely to get updated and could be skipped during upgrades

Please note that our solution will change timestamp format stored in database. It just adds new format which will be processed in templates only (in fn_date_format function)

My problem is I don't need a new format, I want to convert the date to different calendar types via PHP Intl

I think I go with smarty date_format modifier and use my function there

anyway thanks for the tips