<?php
class ModelExtensionTotalTotal extends Model {
	public function getTotal($total) {
		$this->load->language('extension/total/total');

		$total['totals'][] = array(
			'code'       => 'total',
			'title'      => $this->language->get('text_total'),
			'value'      => $total['total'],
			'sort_order' => $this->config->get('total_sort_order')
		);
		
	}
	public function updateTotalInOrder($order_id){
	    $total=$this->db->query("SELECT value 
	        FROM " . DB_PREFIX . "order_total  
                WHERE 
                    order_id =" . (int)$order_id . " AND 
                    code='total'")->row;

	    $this->db->query("UPDATE " . DB_PREFIX . "order SET total=" . (float)$total['value'] . " WHERE order_id=".(int)$order_id);

    }
    public function getTotalInOrder($order_id){
        $total=$this->db->query("SELECT value 
	        FROM " . DB_PREFIX . "order_total  
                WHERE 
                    order_id =" . (int)$order_id . " AND 
                    code='total'")->row;
       return $total;

    }
    public function delteTotal($order_id,$totals){
       $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id=" . (int)$order_id);
        foreach($totals as $total){

            $this->db->query("INSERT INTO " .  DB_PREFIX . "order_total
                SET
                    code='"  . $this->db->escape($total['code']) . "',
                    title='" . $this->db->escape($total['title']) . "',
                    value='" . (float)$total['value'] . "',
                    sort_order='" . (int)$total['sort_order'] . "',
                    order_id=" . (int)$order_id
                            );
        }
    }

}
