Skip to content
Snippets Groups Projects
Commit 7d613be9 authored by Leo Kacenjar's avatar Leo Kacenjar
Browse files

#3255026 Fix non-numeric and empty price exception. Return @price token in validation message.

parent 59e81c2f
No related branches found
No related tags found
1 merge request!2Issue #3255026: Return numeric price validation and tokenized message
......@@ -195,7 +195,10 @@ class UnitPriceWidget extends WidgetBase {
$value = $form_state->getValue($element['#parents']);
if ($value['number'] < $variation->getPrice()->getNumber()) {
$form_state->setError($element, t('The chosen price is too low'));
$currency_formatter = \Drupal::service('commerce_price.currency_formatter');
$price_string = $currency_formatter->format($variation->getPrice()
->getNumber(), $variation->getPrice()->getCurrencyCode());
$form_state->setError($element, t('The chosen price must be at least @price', ['@price' => $price_string]));
}
}
......@@ -206,7 +209,7 @@ class UnitPriceWidget extends WidgetBase {
$field_name = $this->fieldDefinition->getName();
$path = array_merge($form['#parents'], [$field_name, 0]);
$values = NestedArray::getValue($form_state->getValues(), $path);
if ($values && $values['override']) {
if ($values && $values['override'] && is_numeric($values['amount']['number'])) {
/** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
$order_item = $items[0]->getEntity();
$unit_price = new Price($values['amount']['number'], $values['amount']['currency_code']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment