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
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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']);