public function ListQuoteItems($quote_id) { // return; // fix that function App::uses("Quote", "QuoteManager.Model"); $list_quote = new Quote(); $query = "SELECT t.code as code,SUM(t.quantity) as quantity FROM(SELECT coi.code as code ,coi.quantity as quantity FROM cabinet_order_items as coi WHERE coi.cabinet_order_id in (\n SELECT co.id FROM cabinet_orders AS co WHERE co.quote_id ={$quote_id}) || coi.quote_id={$quote_id} ) AS t GROUP BY t.code"; $list_data = $list_quote->query($query); $list = array(); $title_list = array(); $name_list = array(); $price_list = array(); $all_items = $this->ListAllTypesOfItems(); $index = 0; // debug($list_data); foreach ($list_data as $row) { $list[$row['t']['code']] = $row[0]['quantity']; @($name_list[$row['t']['code']] = $all_items['main_list'][$row['t']['code']]); @($price_list[$row['t']['code']] = $all_items['price_list'][$row['t']['code']]); @($title_list[$row['t']['code']] = $all_items['title_list'][$row['t']['code']]); $index++; } $query = "SELECT t.code as code,SUM(t.quantity) as quantity FROM(SELECT coi.code as code ,coi.quantity as quantity FROM granite_order_items as coi WHERE coi.granite_order_id= (\n SELECT co.id FROM granite_orders AS co WHERE co.quote_id ={$quote_id}) || coi.quote_id={$quote_id} ) AS t GROUP BY t.code"; $list_data = $list_quote->query($query); // debug($list_data); foreach ($list_data as $row) { if (array_key_exists($row['t']['code'], $list)) { $list[$row['t']['code']] = $list[$row['t']['code']] + $row[0]['quantity']; } else { $list[$row['t']['code']] = $row[0]['quantity']; $name_list[$row['t']['code']] = $all_items['main_list'][$row['t']['code']]; $price_list[$row['t']['code']] = $all_items['price_list'][$row['t']['code']]; $title_list[$row['t']['code']] = $all_items['title_list'][$row['t']['code']]; } } return array('quantity_list' => $list, 'name_list' => $name_list, 'price_list' => $price_list, 'title_list' => $title_list); }