1

Let's say I have 3 products in a product display that cost $5.00, $3.00, $7.00.

Right now in Commerce Kickstart 2, the view displays the first product's price which happens to be $5.00.

I would like the View to display the price range, $3.00 - $7.00, but only if there is a variance in prices (if all the products are $3.00 - just display $3.00).

0

I've done it using Display Suite code field like that:

<?php
$max['amount'] = 0;
$min['amount'] = 0;
$products = field_get_items('node', $entity, 'field_products');
foreach($products as $product) {
  $product = commerce_product_load($product['product_id']);
  $commerce_price = array_shift(field_get_items('commerce_product', $product, 'commerce_price'));
  if($commerce_price['amount'] > $max['amount']) {
    $max = $commerce_price;
  }
  if($commerce_price['amount'] < $min['amount'] || $min['amount'] == 0) {
    $min = $commerce_price;
  }
}
return $min['amount'] < $max['amount'] ? commerce_currency_format($min['amount'], $min['currency_code']) . ' - ' . commerce_currency_format($max['amount'], $max['currency_code']) : commerce_currency_format($min['amount'], $min['currency_code']);
?>
0

A more generic approach of achieving this would be to use the module Drupal Commerce Extra Price Formatters

At the moment of writing this words, the functionality to display price formatted in ranges is achieved by means of this patch.

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.