name = 'refundreason'; $this->tab = 'administration'; $this->author = 'Antadis'; $this->version = '1.0'; parent::__construct(); $this->displayName = $this->l('Reason for refund'); $this->description = $this->l('Allows to give a reason for refunds'); $this->reasons = array( '---', $this->l('Cancelled (before shipping)'), $this->l('Cancelled (received, -7d)'), $this->l('Return (received +7d)'), $this->l('Product default'), $this->l('Missing product (supplier)'), $this->l('Logistics error'), $this->l('Other'), $this->l('ZZZZZ1'), $this->l('ZZZZZ2'), $this->l('ZZZZZ3'), $this->l('ZZZZZ4'), $this->l('ZZZZZ5'), ); } public function uninstall() { Db::getInstance()->Execute(' DROP TABLE `'._DB_PREFIX_.'refundreason` '); return parent::uninstall(); } public function install() { if(!(parent::install() && Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'refundreason` ( `id_reason` INTEGER NOT NULL, `id_order_slip` INTEGER NOT NULL, `id_employee` INTEGER DEFAULT NULL, PRIMARY KEY(`id_reason`, `id_order_slip`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 ') && $this->registerHook('adminOrder') && $this->registerHook('orderSlip') )) { return FALSE; } return TRUE; } public function hookAdminOrder($params) { global $cookie; $output = ''; if($reasons = Db::getInstance()->ExecuteS(' SELECT * FROM `'._DB_PREFIX_.'order_slip` s LEFT JOIN `'._DB_PREFIX_.'refundreason` r ON s.`id_order_slip` = r.`id_order_slip` WHERE s.`id_order` = '.(int) $params['id_order'].' ')) { $output .= '
'.$this->l('Refund reasons').''.$this->l('Refund reasons').' '; foreach($reasons as $reason) { $output .= ''.$this->l('#').$reason['id_order_slip'].''.$this->l(':').' '.$this->reasons[$reason['id_reason']].'
'; } $output .= '
'; } $output .= ' '; return $output; } public function hookOrderSlip($params) { global $cookie; $id_order = (int) $params['order']->id; $id_reason = Tools::getValue('typeReason'); if($slip = Db::getInstance()->getRow(' SELECT `id_order_slip` FROM `'._DB_PREFIX_.'order_slip` WHERE `id_order` = '.$id_order.' ORDER BY `date_add` DESC ')) { Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'refundreason` VALUES ('.(int) $id_reason.', '.(int) $slip['id_order_slip'].', '.(int) $cookie->id_employee.') '); } } }