Set Currency format in hybris - sap-commerce-cloud

I am trying to set format of currency for a country with impex. Currentlty it is set as '42,953.87'. I want it should be changed to the format as '42.953,87'. Right now impex I am using for it is as
INSERT_UPDATE Currency;isocode[unique=true];conversion;digits;symbol
;ABC;1;2;kr
What changes I need to make in above impex code to make it in format as 24.953,87 I tried ;ABC;;;2;kr but it does not work.Is there any other way in hybris through which I can change currency format?

I believe you are trying to import using the HAC.
Please use the numberformat attribute modifier. Please note that you will have to specify the locale of the entries. To achieve a successful import, please follow the steps:
Specify the locale: #% impex.setLocale( Locale.ENGLISH);
Enable code execution in HAC
Execute code using the numberformat modifier.
INSERT_UPDATE Currency;isocode[unique=true];conversion;digits[numberformat==#.###,##];symbol
;ABC;1;24.953,87;kr
Please comment if you are still facing any issue.

After some research, I concluded that Format of currency displayed on the storefront is based on locale value for the CMSSite. It is out of the box feature of Localization and We can update it by following impex
UPDATE CMSSite;uid[unique=true];locale[lang=$lang]
;<site_uid>;<locale_value>
Also If we need to edit the format more, in that case we need to change to change the DataPriceFactory implementation.

add the following line above the impex:
#% impex.setLocale( Locale.GERMAN );
INSERT_UPDATE Currency;isocode[unique=true];conversion;digits;symbol
;ABC;1;2;kr
set the corresponding localedo reach your expected format

I try you given locale with below code. It is look like sv_SE locale is not in standard jvm. May be you are using special configuration. Can you check it?
import java.text.*;
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Locale locale = new Locale("sv","SE");
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(locale);
DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
System.out.println(symbols.getGroupingSeparator());
}
}

Related

Issue of Reading and Converting Date of Google Calendar Events when language is set to Arabic in C#

I am Using Google APis .net client library to read calendar events.
I have following line of code
newRow["Start"] = pEventItem.Start.DateTime.HasValue ?
Convert.ToDateTime(pEventItem.Start.DateTime) : Convert.ToDateTime(pEventItem.Start.Date);
Where PEventItem is of type Google.Apis.Calendar.v3.Data.Event and NewRow[...] is of type DataRow. The Value of pEventItem.Start.Date is "2019-06-24" (as seen in debug window)
The above line of code works perfect, But fails when UI language / Culture is set to Arabic (SaudiArabia) The same Convert.ToDateTime throws error "String was not recognized as a valid DateTime".
btw, How i am changing the UI language is as below for your information.
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(ChangeLanguageTo);
Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(ChangeLanguageTo);
I tried to set 2nd parameter of the Convert.ToDateTime function in an hope that it will convert date correctly...
CultureInfo enUsCulture = new CultureInfo("en-us");
newRow["Start"] = pEventItem.Start.DateTime.HasValue ? Convert.ToDateTime(pEventItem.Start.DateTime, enUsCulture) : Convert.ToDateTime(pEventItem.Start.Date, enUsCulture);
Well Now it does not throw exception, but the returned date is incorrect. value retuned is {21/10/40 12:00:00 ص}
while The actual date pEventItem.Start.Date is "2019-06-24"
I also tried invariant culture also, but result is same, converted date is wrong. What could be the issue?
Regards
There are a few things going on here.
Firstly, if you use EventDateTime.DateTime (e.g. via pEventItem.Start.DateTime) you don't need to call Convert.ToDateTime, because that's already a DateTime?... you can just take the Value property to get a DateTime from a DateTime?. However, I should warn that that can perform time zone conversions that you may not want. (We can't fix the library to avoid those, as it would be a breaking change.) Instead, you may want to parse EventDateTime.DateTimeRaw, which is the original string value returned by the API.
When parsing, I'd suggest using the invariant culture using CultureInfo.InvariantCulture (instead of creating an en-US culture), and parse using DateTime.ParseExact, specifying the format you expect based on whether you're parsing a date or a full date/time.
In terms of "the returned date is incorrect" - I believe that's really just the formatted value that's using the default culture, including the calendar system. We can see that at play in the code below, which constructs the DateTime directly (so can't be affected by any text parsing etc). When formatted using the invariant culture, it shows as 2019-06-24, but when formatted with ar-SA, it shows as "1440-10-21" due to the default calendar system for that culture being System.Globalization.UmAlQuraCalendar:
// Note: when a calendar system is not specified,
// it's implicitly Gregorian.
DateTime date = new DateTime(2019, 6, 24);
Console.WriteLine(date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
Console.WriteLine(date.ToString("yyyy-MM-dd", new CultureInfo("ar-SA")));
So what you're seeing in the debugger is the correct date - but formatted in a way you weren't expecting.

How to create theos custom variables?

I would like to create custom variable for theos. In example ##DATECREATED## to print current date for my tweak deceptions (I'm soooo bored to edit it manually :D)
Like ##FULLPROJECTNAME## prints out tweak name in control and Makefile...
Edit: I did it with adding this to my nic.pl:
use DateTime;
$NIC->variable("DATECREATED") = DateTime->now->strftime('%d/%m/%Y');
Is it possible to do it without editing original nic.pl?
Thanks for suggestions!
I have found a solution for it!
I had to put this code inside control.pl in my theos template:
use DateTime;
NIC->variable("DATECREATED") = DateTime->now->strftime('%d/%m/%Y');

Node.js - Oracle DB and fetchAsString format

I am stuck on a problem and I am not sure what is the best way to solve it. I have a date column that I want to select and I want to fetch it as a string. Which is great, node-oracledb module has this option with fetchAsString mehotd. But it fetches the date like this for example 10-JAN-16 and I want to fetch it like this 10-01-2016. Is there a way to do that from the node-oracledb module, or I should modify the date after I get the result from the query?
UPDATE: I mean solution without to_char in the query and without query modifications
Check out this section of my series on Working with Dates in JavaScript, JSON, and Oracle Database:
https://dzone.com/articles/working-with-dates-using-the-nodejs-driver
The logon trigger shows an example of using alter session to set the default date format. Keep in mind that there is NLS_DATE_FORMAT, NLS_TIMESTAMP_FORMAT, NLS_TIMESTAMP_TZ_FORMAT.
I only show NLS_TIMESTAMP_TZ_FORMAT because I convert to that type in the examples that follow as I need to do some time zone conversion for the date format I'm using.
Another way to set the NLS parameters is to use environment variables of the same name. Note that this method will not work unless you set the NLS_LANG environment variable as well.

New string to translate in Prestashop 1.6.0.9

I need help with Prestashop translations.
I would like to add a few strings to translations in blockcms module. I've added them to .tpl file in this format:
{l s='Awards and certificates' mod='blockcms'}
and I've added to file modules/blockcms/translations/pl.php following line:
$_MODULE['<{blockcms}prestashop>blockcms_0b7b4b09a465b93640bc3f8822ff26eb'] = 'Nagrody i certyfikaty';
where 0b7b4b09a465b93640bc3f8822ff26eb is 'Awards and certificates' in md5.
Unfortunately translation is not showing in BO and string is not replace in store... What is wrong?
I guess I should register new string to translation in blockcms.php file, but I've looked there and it didn't help me to understand how it should be done.
Thank is advance for any replies ;)
To add a translation, you have to translate via backoffice : localisation > translation.
You should not edit translation files

bug in primefaces calendar timepicker?

I have this calendar with time picker on my page:
<p:calendar value="#{addTaskBacking.currentTask.deadline}" mode="inline"
pattern="dd-MM-yyyy HH:mm" mindate="01-09-2013 00:00"/>
When I set the pattern: dd-MM-yyyy without the time everything is added correctly, but when I change to: dd-MM-yyyy HH:mm I get this error:
j_idt10:j_idt12: '9-04-2014' could not be understood as a date and time.
This is when I set the inline mode, when I set the popup is all ok.
I have primefaces_v4.jar. I check this side http://forum.primefaces.org/viewtopic.php?f=3&t=22982 but i can't find any solution
Edit:
It look like all depends of mode atribute of p:calendar. If i have default popup mode everything it's fine (like in example on http://primefaces.org/showcase/ui/calendarTime.jsf. But when I change to inline mode i get this error:
cal:inlineCal: '13-04-2014' could not be understood as a date and time. Example: 13-04-2014 15:16
PrimeFaces uses SimpleDateFormat by default unless you override the formatter.
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
EDIT
Your pattern will work if you change your mindate attribute to be the same as your pattern..
IE: You can't have a pattern dd-MM-yyyy HH:mm when you have a mindate="01/09/2013"
Change your mindate to - 01-09-2013
EDIT 2
AFter debugging a fair bit you're right, there seems to be a bug when setting the inputValue field in javascript prior to being sent in the POST to the server to even use the pattern converters...
I got it all working recompiling the code with the following changes:
Line 129 in calendar.js (gets merged into primefaces.js) var newDate = this.value;
Basically at the moment it tries to do a formatDate on the input which is fine cause its the same date format split ie, dd/mm/yy etc.. but it totally skips 'time' being attached can't use parseDatetime as it does an entire object time, which should be don eon the java side as you just build the object.
this.value is what you want regardless to be sent back in the post which is what it does for _self.cfg.popup (it doesn't even set the input val because its already there!...
I'll raise an issue with PF
"Raised Issue 6790 on the PrimeFaces Issue Tracker"

Resources