We need a Resolved Price price field formatter. This will show the resolved price (discounted, sale, whatever). It should also have a setting to show the original price.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Assigned: Unassigned » mglaman
mglaman’s picture

Title: Create a "resolved price" formatter » Create a "calculated price" formatter

Discussed with bojanz. Since this will have the ability to show taxes that are included, renaming to PriceCalculatedFormatter, "Calculated".

mglaman’s picture

Status: Active » Needs work
FileSize
7.42 KB

Initial WIP from before.

bojanz’s picture

I think it makes sense to extend the Default formatter to reduce code.

mglaman’s picture

+++ b/modules/price/config/schema/commerce_price.schema.yml
@@ -28,3 +28,17 @@ field.formatter.settings.commerce_price_default:
+    show_original_price:
+      type: boolean
+      label: 'Display the original price, if resolved price is different'

+++ b/modules/price/src/Plugin/Field/FieldFormatter/PriceCalculatedFormatter.php
@@ -0,0 +1,179 @@
+      'show_original_price' => FALSE,
...
+    $elements['show_original_price'] = [
+      '#type' => 'checkbox',
+      '#title' => $this->t('Display the original price, if resolved price is different.'),
+      '#default_value' => $this->getSetting('show_original_price'),
+    ];
...
+      if ($resolved_amount->equals($item->toPrice())) {

Discussed w/ bojanz. Going to remove the "show original price" option to reduce complexity when working with multiple currencies.

mglaman’s picture

Status: Needs work » Needs review
FileSize
352.33 KB

Extended base class, uses price resolver.

We should add tests

  • bojanz committed 2b855e7 on 8.x-2.x authored by mglaman
    Issue #2803241: Create a "calculated price" formatter (#512)
    
    
bojanz’s picture

Status: Needs review » Fixed

Here we go.

agoradesign’s picture

btw, the 'show_original_price' key is still present in field.formatter.settings.commerce_price_calculated schema definition, although not used (or is it??)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hockey2112’s picture

Was this committed? It appears that it is not available in Commerce 8.x-2.24. For example, the commerce_cart_services.yml still contains "class: Drupal\commerce_cart\OrderItemMatcher" instead of "class: Drupal\commerce_cart\LineItemMatcher".

mglaman’s picture

Was this committed? It appears that it is not available in Commerce 8.x-2.24. For example, the commerce_cart_services.yml still contains "class: Drupal\commerce_cart\OrderItemMatcher" instead of "class: Drupal\commerce_cart\LineItemMatcher".

Yes. We renamed LineItems to OrderItems after this. Look for "Calculated price" field formatter.

hockey2112’s picture

Ah, got it, thanks! Is there any way to break out and display just the tax amount on a per-product or per-order basis in Views?