<?php

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

class ControllerPaymentOrcamento extends ControllerPaymentPaymentDefault {

  protected function index(){
	parent::index();

	$this->app();

	$this->data['back']         = $this->url->link('checkout/checkout', '', 'SSL');
	$this->data['text_payment'] = $this->config->get('orcamento_instrucoes');
	$this->data['text_payment_app'] = html_entity_decode(nl2br($this->config->get('orcamento_instrucoes')));
		
 	if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/orcamento.tpl')) {
		$this->template = $this->config->get('config_template') . '/template/payment/orcamento.tpl';
	} else {
		$this->template = 'default/template/payment/orcamento.tpl';
	}

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


  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('orcamento_status_iniciado'), '');

		if (isset($this->session->data['order_id'])) {
			$this->cart->clear();

			unset($this->session->data['shipping_method']);
			unset($this->session->data['shipping_methods']);
			unset($this->session->data['payment_method']);
			unset($this->session->data['payment_methods']);
			unset($this->session->data['guest']);
			unset($this->session->data['comment']);
			unset($this->session->data['coupon']);
			unset($this->session->data['reward']);
			unset($this->session->data['voucher']);
			unset($this->session->data['vouchers']);
		}
	}
	$this->response->setOutput(json_encode($json));
  }

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

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