<?php

loadcontroller('base/module');

class ControllerShippingFreteaCombinar extends ControllerBaseModule {

    protected $referencePathFile = 'shipping/freteacombinar';

    protected function loadData() {
        $this->load->type('tipocomum');
        $this->load->type('tipofrete');
				
        $this->dataVue['Type_Status'] = Type_Status::getEnumList();
        $this->dataVue['Type_DsimDnao'] = Type_DsimDnao::getEnumList();
        $this->dataVue['configurations'] = $this->model_setting_setting->getSetting('freteacombinar');
    }

    protected function loadModel() {
        parent::loadModel();
        $this->load->dmodel('proccess/order_to_situation');
        $this->load->model('localisation/order_status');
    }

    public function saveSetting() {
        $this->loadLanguage();

        $response = [];

        if (!$this->user->hasPermission('modify', 'shipping/freteacombinar')) {
            $response['warning'] = $this->language->get('error_permission');
            return $this->response->setOutputJson($response);
        }

        $this->errors = $this->validate();
        if (!$this->errors) {

        
            $this->load->model('setting/setting');
            $this->model_setting_setting->editSetting('freteacombinar', $this->request->post);

            $response['success'] = $this->language->get('text_success');
        } else {
            $response['errors'] = $this->errors;
        }

        return $this->response->setOutputJson($response);
    }

    protected function validate() {
        $this->loadLanguage();
        $this->load->type('tipocomum');

        extract($this->request->post);

        $errors = [];
				
        $errors = $this->validate->execute([
            'freteacombinar_status' => [
                'value' => $freteacombinar_status,
                'validates' => ['isEmpty', 'isEnabledOrDisabled']
            ],
            'freteacombinar_sort_order' => [
                'value' => $freteacombinar_sort_order,
                'validates' => ['isIntegerNumber']
            ],
        ]);

        return $errors;
    }

    public function install() {
        $this->load->model('setting/setting');

        $this->model_setting_setting->editSetting('freteacombinar', $freteacombinarAuthInfo);
    }

}
