function commerce_pricelist_get_user_price in Commerce Pricelist 7
Get the price for a quantity of a product for current user.
Parameters
$sku:
int $quantity:
Return value
int
1 call to commerce_pricelist_get_user_price()
- commerce_pricelist_rate_rules_apply in ./
commerce_pricelist.rules.inc - Rules action: loads and applies a pricelist rate to the given line item.
File
- ./
commerce_pricelist.module, line 390 - Implements the basic functionality required for price lists
Code
function commerce_pricelist_get_user_price($user, $sku, $quantity = 0, $time = FALSE) {
$price = array();
$user_pricelists = commerce_pricelist_get_user_pricelists($user);
if (empty($user_pricelists)) {
// @todo set error
return $price;
}
$prices = commerce_pricelist_get_prices($sku, $time);
if (empty($prices)) {
// @todo set error
return $price;
}
// Loop through all pricelists for current user and match against prices
// for this product.
foreach ($user_pricelists as $pricelist) {
if (isset($prices[$sku][$pricelist->list_id])) {
foreach ($prices[$sku][$pricelist->list_id] as $quantity_limit => $price_item) {
// Check if quantity arg is higher than the quantity limit for this price.
if ($quantity >= $quantity_limit) {
// We found our price, break out.
$price = $price_item;
break 2;
}
}
}
}
return $price;
}