- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
public function find_all() {
$result = parent::find_all();
if ($result->count() > 0) {
$parents_id = queryToArray::from($result->as_array())
->where(function ($prod) {
return $prod->sys_type == 'PARENT';
})
->select(function($k, $v) { return $v->id; })
->result();
if (count($parents_id)) {
$prices = unserialize(
Cache::instance()->get_or_call(
'prices_'.implode(':', $parents_id),
Date::HOUR * 6,
function() use ($parents_id) {
return serialize(
queryToArray::from(
DB::query(
Database::SELECT,
'SELECT parent.id as id, (SELECT min(price) FROM products as child WHERE child.parent_id = parent.id AND child.shop_state IN (\'publicated\', \'booked\')) as min, (SELECT max(price) FROM products as child WHERE child.parent_id = parent.id AND child.shop_state IN (\'publicated\', \'booked\')) as max FROM products as parent WHERE parent.id IN :ids')
->param(':ids', $parents_id)
->execute()
->as_array())
->select(function ($k, $v) {
return array(
'key' => $v['id'],
'value' =>
array(
'min' => (float) $v['min'],
'max' => (float) $v['max']));
})
->result());
}));
$products = $result->as_array();
foreach ($products as $product) {
if (isset($prices[$product->id])) {
$this->_set_prices($product, $prices[$product->id]);
}
}
return new Database_Result_Local($products, Database::instance()->last_query, $products[0]);
}
}
return $result;
}
3_dar 13.10.2015 19:49 # 0
guest 16.10.2015 22:16 # 0
3.14159265 17.10.2015 18:51 # 0
3_dar 17.10.2015 23:08 # +1