* @copyright 2019 Futurenext srl * @license https://www.zakeke.com/privacy/#general_conditions */ class ZakekeInfoModuleFrontController extends ModuleFrontController { /** @var int */ protected $id_zakeke_item; /** @var string */ protected $preview; /** @var array */ protected $items = array(); public function init() { parent::init(); $id_item = Tools::getValue('id_item'); if (!$id_item) { $this->errors[] = $this->module->l('id_item must be not empty.'); return; } $id_zakeke_item = ZakekeItem::zakekeItemId($id_item); if ($id_zakeke_item !== false) { $zakeke_item = new ZakekeItem($id_zakeke_item); } else { $id_zakeke_configurator_item = ZakekeConfiguratorItem::zakekeConfiguratorItemId($id_item); if ($id_zakeke_configurator_item !== false) { $zakeke_item = new ZakekeConfiguratorItem($id_zakeke_configurator_item); $this->items = Tools::jsonDecode($zakeke_item->items_json, true); } else { $this->errors[] = $this->module->l('Zakeke item not found.'); return; } } $this->id = $zakeke_item->id; $this->preview = $zakeke_item->preview; } public function display() { ob_end_clean(); header('Content-Type: application/json'); if (!$this->errors) { $this->ajaxDie(json_encode(array( 'success' => true, 'idItem' => $this->id_zakeke_item, 'preview' => $this->preview, 'items' => $this->items ))); } else { $this->ajaxDie(json_encode(array( 'hasError' => true, 'errors' => $this->errors ))); } } }