diff -u b/src/Plugin/Field/FieldFormatter/PriceRuleFormatter.php b/src/Plugin/Field/FieldFormatter/PriceRuleFormatter.php --- b/src/Plugin/Field/FieldFormatter/PriceRuleFormatter.php +++ b/src/Plugin/Field/FieldFormatter/PriceRuleFormatter.php @@ -28,16 +28,16 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $context = new Context($this->currentUser, $this->currentStore->getStore()); $elements = []; + /** @var \Drupal\commerce\PurchasableEntityInterface $purchasable_entity */ + $purchasable_entity = $items->getEntity(); + $resolved_price = $this->chainPriceResolver->resolve($purchasable_entity, 1, $context); + $number = $resolved_price->getNumber(); + $currency = $this->currencyStorage->load($resolved_price->getCurrencyCode()); + $new_price = $this->numberFormatter->formatCurrency($number, $currency); + /** @var \Drupal\commerce_price\Plugin\Field\FieldType\PriceItem $item */ foreach ($items as $delta => $item) { - /** @var \Drupal\commerce\PurchasableEntityInterface $purchasable_entity */ - $purchasable_entity = $items->getEntity(); - $resolved_price = $this->chainPriceResolver->resolve($purchasable_entity, 1, $context); - $number = $resolved_price->getNumber(); - $currency = $this->currencyStorage->load($resolved_price->getCurrencyCode()); $default_price = $this->numberFormatter->formatCurrency($item->number, $currency); - $new_price = $this->numberFormatter->formatCurrency($number, $currency); - $elements[$delta] = [ '#markup' => '' . $default_price . ' ' . $new_price, '#cache' => [