<?php
class ControllerSpecific4861ModuleValorMinimo extends Controller {

	public function index() {

    if(!$this->config->get('valor_minimo_status') || ($this->config->get('valor_minimo')<=0)){
			return false;
		}

		$subtotal = $this->cart->getSubTotal();
    $valor_minimo = floatval(str_replace(['.', ','],['','.'],$this->config->get('valor_minimo')));

    $this->data['missing_value'] = $this->currency->format($valor_minimo - $subtotal);
    $this->data['progress_total'] = $subtotal / $valor_minimo * 100;

    if($this->config->get('starter_kit_status')){
      $starter_kit_product = explode(',' ,$this->config->get('starter_kit_product'));
      $products = $this->cart->getProducts();

      $haskit = array_filter(array_map(function($value) use ($starter_kit_product){
          return (in_array(intval($value), $starter_kit_product));
      }, array_keys($products)));

      if( ($subtotal < $valor_minimo) && ($this->customer->getTipo_pessoa() == $this->config->get('valor_minimo_tipopessoa') || ($this->config->get('valor_minimo_tipopessoa')==Type_CadastroPessoa::Tp_Ambos)) && !$haskit ){
        $this->data['warning'] = true ;
      }else{
        return false;
      }

    }else if( ($subtotal < $valor_minimo) && ($this->customer->getTipo_pessoa() == $this->config->get('valor_minimo_tipopessoa') || ($this->config->get('valor_minimo_tipopessoa')==Type_CadastroPessoa::Tp_Ambos)) ){
			$this->data['warning'] = true ;
		}else{
			return false;
		}

    $language = $this->load->language('module/valor_minimo');
		$this->data = array_merge($this->data, $language);

		$this->data['minimum_value'] = $this->currency->getSymbolLeft().$this->config->get('valor_minimo');

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/valor_minimo.twig')) {
			$this->template = $this->config->get('config_template') . '/template/module/valor_minimo.twig';
		} else {
			$this->template = 'default/template/module/valor_minimo.twig';
		}

		$this->render();
	}

}
