function commerce_pricelist_get_prices in Commerce Pricelist 7
Return an array of prices like {sku : {pricelist_id: {quantity : price }}}.
@todo take currency into account...
Parameters
$sku:
bool $time:
Return value
array
1 call to commerce_pricelist_get_prices()
- commerce_pricelist_get_user_price in ./
commerce_pricelist.module - Get the price for a quantity of a product for current user.
File
- ./
commerce_pricelist.module, line 337 - Implements the basic functionality required for price lists
Code
function commerce_pricelist_get_prices($sku, $time = FALSE) {
$cache_id = 'commerce_pricelist_get_prices_' . $sku;
$prices =& drupal_static($cache_id);
if (!isset($prices)) {
if ($cache = cache_get($cache_id)) {
$prices = $cache->data;
}
else {
if (!$time) {
$time = time();
}
$prices = array();
$pricelist_items = array();
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_pricelist_item')
->propertyCondition('sku', $sku, '=')
->propertyCondition('valid_from', $time, '<')
->propertyCondition('valid_to', $time, '>')
->propertyOrderBy('quantity', 'DESC');
$result = $query
->execute();
if (!empty($result['commerce_pricelist_item'])) {
$pricelist_items = commerce_pricelist_item_load_multiple(array_keys($result['commerce_pricelist_item']));
}
// Create price array keyed by price list.
foreach ($pricelist_items as $item) {
$prices[$sku][$item->pricelist_id][$item->quantity] = array(
'currency_code' => $item->currency_code,
'amount' => $item->price_amount,
);
}
cache_set($cache_id, $prices, 'cache', time() + 300);
// 5min
}
}
return $prices;
}