<?php

$loader = $this->registry->get('load');
$loader->controller('payment/payment_default');

class ControllerPaymentCod extends ControllerPaymentPaymentDefault {
	protected function index() {

		parent::index();
		$this->app();

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/cod.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/payment/cod.tpl';
		} else {
			$this->template = 'default/template/payment/cod.tpl';
		}

		$this->render('payment/cod');
	}

	public function app()
	{
	  parent::app();
	}		

	public function confirm() {
		$json = array();
		$json['error'] = $this->validate();
		
		if (!$json['error']) {	
			$this->load->dmodel('checkout/order');
			$this->dmodel_checkout_order->confirm($this->session->data['order_id'], $this->config->get('cod_order_status_id'));
		}

		$this->response->setOutput(json_encode($json));			
	}

	public function validate(){
		return parent::validate();
	}	

}
