Fórum OpenCart Brasil

Por um e-commerce livre, confiável e profissional

Suporte geral sobre problemas técnicos para OpenCart v1.x.
#37394
Renato,

Fiz um teste de cancelamento de ordem automatica e verifiquei que o estoque não está sendo reposto assim que a ordem é cancelada.

Verifiquei o arquivo /catalog/controller/module/expire_orders.php , e o mesmo não tem nenhum código que tenha relação com estoque.

Conseguiria me ajudar a customizar, para retornar o estoque do produto cancelado pelo script?
Código: Selecionar todos
class ControllerModuleExpireOrders extends Controller {

    public function index() {

        $data = array();

        $this->load->model('tool/expire_orders');

        $expire_orders_vars = $this->model_tool_expire_orders->getSetting('expire_orders', $this->config->get('config_store_id'));

        $data['order_status_id'] = $expire_orders_vars['expire_status_to'];
        $data['notify'] = $expire_orders_vars['expire_notify'];
        $data['comment'] = $expire_orders_vars['expire_comment'];
        $data['days'] = $expire_orders_vars['expire_days'];
        $data['status_from'] = $expire_orders_vars['expire_status_from'];

        if ($data['days'] && $data['status_from'] && $data['order_status_id']) {

            $orders = $this->model_tool_expire_orders->getOrdersToExpire($data);

            foreach ($orders as $order) {
                $this->model_tool_expire_orders->addOrderHistory($order['order_id'], $data);
            }
        }

        $bt = debug_backtrace();
        # came from preAction
        if (!empty($bt[3]) && $bt[3]['function'] == 'dispatch') return;

        $this->redirect(HTTP_SERVER);
    }
}
No admin, tem o arquivo /admin/controller/module/expire_orders.php , que é onde eu configuro qnt de dias que deve expirar a ordem, o status que está antes, e o status que vai ficar depois, um comentario padrao para ser incluido no historico, e uma flag de envio ou nao de email informando a troca d status
Código: Selecionar todos
class ControllerModuleExpireOrders extends Controller {
    private $error = array(); 
	 
    public function index() {   
        $this->load->language('module/expire_orders');

        $this->document->setTitle($this->language->get('heading_title'));
		
        $this->load->model('setting/setting');
				
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->model_setting_setting->editSetting('expire_orders', $this->request->post);		
            $this->session->data['success'] = $this->language->get('text_success');
            $this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
        }
				
        $this->data['token'] = $this->session->data['token'];

        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }

        $this->data['heading_title'] = $this->language->get('heading_title');
        $this->data['text_expire_days'] = $this->language->get('text_expire_days');
        $this->data['text_expire_status_to'] = $this->language->get('text_expire_status_to');
        $this->data['text_expire_status_from'] = $this->language->get('text_expire_status_from');
        $this->data['text_expire_notify'] = $this->language->get('text_expire_notify');
        $this->data['text_expire_comment'] = $this->language->get('text_expire_comment');
        $this->data['button_save'] = $this->language->get('button_save');
        $this->data['button_cancel'] = $this->language->get('button_cancel');

        $this->data['action'] = $this->url->link('module/expire_orders', 'token=' . $this->session->data['token'], 'SSL');
        $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');

        $this->data['breadcrumbs'] = array();

        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => false
        );

        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_module'),
            'href'      => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => ' :: '
        );

        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title'),
            'href'      => $this->url->link('module/expire_orders', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => ' :: '
        );

        $expire_orders_vars = $this->model_setting_setting->getSetting('expire_orders', $this->config->get('config_store_id'));

        foreach ( array('expire_days','expire_status_from','expire_status_to','expire_comment','expire_notify') as $key ) {

            if ( isset($this->request->post[$key]) ) {
                $this->data[$key] = $this->request->post[$key];
            } elseif ( isset($expire_orders_vars[$key]) ) {
                $this->data[$key] = $expire_orders_vars[$key];
            } else {
                $this->data[$key] = 0;
            }
        }

        $this->load->model('localisation/order_status');
        $this->data['statuses'] = $this->model_localisation_order_status->getOrderStatuses();

        $this->load->model('design/layout');
   
        $this->data['layouts'] = $this->model_design_layout->getLayouts();
				
		$this->template = 'module/expire_orders.tpl';

        $this->children = array(
            'common/header',
            'common/footer',
        );
				
        $this->response->setOutput($this->render());
    }
	
    private function validate() {
        if (!$this->user->hasPermission('modify', 'module/expire_orders')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        if (isset($this->request->post['expire_days']) && is_numeric($this->request->post['expire_days']) ) {
            if ( $this->request->post['expire_days'] < 0 || $this->request->post['expire_days'] > 30) {
                $this->error['warning'] = $this->language->get('error_out_of_range');
            }
        } else {
           $this->error['warning'] = $this->language->get('error_bad_value');
        }

        if (isset($this->request->post['expire_comment']) && strlen($this->request->post['expire_comment']) > 250) {
            $this->error['warning'] = $this->language->get('error_long_comment');
        }

        $this->request->post['expire_notify'] = (empty($this->request->post['expire_notify']) ? 0 : 1 );


        if (!$this->error) {
            return true;
        } else {
            return false;
        }	
    }
}