You are here

function uc_discounts_get_discounted_price_for_product in Ubercart Discounts (Alternative) 7.2

Same name and namespace in other branches
  1. 6.2 uc_discounts/uc_discounts.module \uc_discounts_get_discounted_price_for_product()

Helper function that gets the codeless discounted price of a product.

Parameters

object $product: Loaded ubercart product node.

bool $return_null: If TRUE return NULL for the price if there are no discounts.

Return value

float The price of the product after discount has been applied.

2 calls to uc_discounts_get_discounted_price_for_product()
discounted_price_handler::render in product_price_alterer_field/includes/discounted_price_handler.inc
Render the field.
product_price_alterer_field_field in product_price_alterer_field/product_price_alterer_field.module
Implementation of hook_field()

File

uc_discounts/uc_discounts.module, line 2029

Code

function uc_discounts_get_discounted_price_for_product($product, $return_null = TRUE) {
  $discounts = uc_discounts_get_codeless_discounts_for_product_and_quantity($product, 1);
  if (empty($discounts)) {
    return $return_null ? NULL : $product->sell_price;
  }
  $total_discount_amount = 0;
  foreach ($discounts as $discount) {
    $total_discount_amount += $discount->amount;
  }
  return $product->sell_price - $total_discount_amount;
}