0

So here is my issue;

I got a price in a Number (decimal) field in a node, I need to process this number in some ways depending on users interactions then send it back (via an ajax request) as an integer, but also formatted with proper currency sign which is stored in the fields prefix/suffix settings.

I should mention that this should also work with translations of the price and its prefix/suffixes.

I get the price now this way;

$node = \Drupal::entityTypeManager()->getStorage('node')->load($node_id);
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$translated_node = $node->getTranslation($language);
$price = $translated_node->get('field_price')->getValue()[0]['value'];`

So now I want to constuct a formated variable with the translated prefix/suffix depending on which language is curretly selected.

1

After some trial and error and cache problems I found the answer to this myself. Here is how I got the prefix/suffix;

$prefix = $translated_node->get('field_price')->getSettings()['prefix'];
$suffix = $translated_node->get('field_price')->getSettings()['suffix'];

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.