<?php

class ControllerCommonEtiqueta extends Controller
{
  public function index()
  {


    $json = array();

    try {

      if (isset($this->request->get['id_futura'])) {

        $result = $this->db->query('SELECT
                                        mo.order_id AS order_id,
                                        mo.mktOrderId AS mktOrderId,
                                        mo.tipo_integracao AS tipo_integracao
                                      FROM oc_marketplace_order mo
                                      INNER JOIN oc_order o ON (mo.order_id = o.order_id)
                                      WHERE o.id_futura = ' . $this->request->get['id_futura'])->row;

        if (!$result) {
          throw new exception('Pedido não pertence aos marketplaces');
        }

        $result = $this->marketplace->splitEtiqueta($result['tipo_integracao'], $result['mktOrderId']);

        $json['link'] = $result;

      } else {
        throw new exception('Id de pedido não encontrado no e-commerce!');
      }

    } catch (Exception $e) {
      $json['error'] = $e->getMessage();
    }

    $this->response->setOutputJson($json);

  }
}
