Bom consegui criar a página customizada claro que não ficou uma maravilha mas funciona rsss o cliente solicitou um link extra no menu do topo de orçamento, esse link teria como função exibir um formulário com um anexo e enviar para o email dele. Bom peguei o modelo do CONTACT.PHP que era o que eu precisava porém faltava o upload, você pode simplesmente adicionar ao contact as informações abaixo ou pode criar sua página avulsa como eu fiz.
Versão utilizada: Opencart 1.5.1.3
Template: Cópia do original modificando apenas o menu, cores e coisinhas bestas
Bom então vamos ao POG(Programação Orientada a Gambiarra):
Criei a pasta "orcamento" e o arquivo "orcamento.php"
catalog/controller/orcamento/orcamento.php
Obs: coloquei as rotas orcamento/orcamento pois estou utilizando URL Amigável, caso não utilize então mude se não me engano é index.php?route=orcamento/orcamento, tem que me pesquisar não sei direito.
Outro detalhe é o email que coloquei primeiro o meu pessoal para testar e comentei o email que vem do sistema, então primeiro faça os testes depois remova o seu email e na linha abaixo possui o código para pegar o email do sistema.
Código: Selecionar todos<?php
class ControllerOrcamentoOrcamento extends Controller {
private $error = array();
public function index() {
$this->language->load('orcamento/orcamento');
$this->document->setTitle($this->language->get('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
//email para testes
$email_destino = 'seu_email@gmail.com';
//após teste utilizar o email do sistema
#$email_destino = $mail->setTo($this->config->get('config_email'));
$assunto = sprintf($this->language->get('email_subject'), $this->request->post['name']);
$mensagem = "<br><br><b>Nome:</b> " .$this->request->post['name']. "<br>";
$mensagem .= "<b>Email:</b> " .$this->request->post['email']. " <br>";
$mensagem .= strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8'));
//formato o campo da mensagem
$mensagem = wordwrap( $mensagem, 50, "
", 1);
$arquivo = isset($_FILES["upload"]) ? $_FILES["upload"] : FALSE;
if(file_exists($arquivo["tmp_name"]) and !empty($arquivo)){
$fp = fopen($_FILES["upload"]["tmp_name"],"rb");
$anexo = fread($fp,filesize($_FILES["upload"]["tmp_name"]));
$anexo = base64_encode($anexo);
fclose($fp);
$anexo = chunk_split($anexo);
$boundary = "XYZ-" . date("dmYis") . "-ZYX";
$mens = "--$boundary\n";
$mens .= "Content-Transfer-Encoding: 8bits\n";
$mens .= "Content-Type: text/html; charset=\"UTF-8\"\n\n"; //plain
$mens .= "$mensagem\n";
$mens .= "--$boundary\n";
$mens .= "Content-Type: ".$arquivo["type"]."\n";
$mens .= "Content-Disposition: attachment; filename=\"".$arquivo["name"]."\"\n";
$mens .= "Content-Transfer-Encoding: base64\n\n";
$mens .= "$anexo\n";
$mens .= "--$boundary--\r\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "From: " .$this->request->post['email']. " <" .$this->request->post['name'].">\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
$headers .= "$boundary\n";
//envio o email com o anexo
mail($email_destino,$assunto,$mens,$headers);
}
//caso não tenha arquivo em anexo
else
{
//email para testes
$email_destino = 'seu_email@gmail.com';
//após teste utilizar o email do sistema
#$email_destino = $mail->setTo($this->config->get('config_email'));
$assunto = sprintf($this->language->get('email_subject'), $this->request->post['name']);
$mensagem = "<br><br><b>Nome:</b> " .$this->request->post['name']. "<br>";
$mensagem .= "<b>Email:</b> " .$this->request->post['email']. " <br>";
$mensagem .= strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8'));
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=UTF-8\n";
$header .= "From: " .$this->request->post['email']. "\n";
mail($email_destino, $assunto, $mensagem, $header);
}
$this->redirect($this->url->link('orcamento/orcamento/success'));
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('orcamento/orcamento'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_location'] = $this->language->get('text_location');
$this->data['text_contact'] = $this->language->get('text_contact');
$this->data['text_address'] = $this->language->get('text_address');
$this->data['text_telephone'] = $this->language->get('text_telephone');
$this->data['text_fax'] = $this->language->get('text_fax');
$this->data['entry_name'] = $this->language->get('entry_name');
$this->data['entry_email'] = $this->language->get('entry_email');
$this->data['entry_enquiry'] = $this->language->get('entry_enquiry');
$this->data['entry_upload'] = $this->language->get('entry_upload');
$this->data['entry_captcha'] = $this->language->get('entry_captcha');
if (isset($this->error['name'])) {
$this->data['error_name'] = $this->error['name'];
} else {
$this->data['error_name'] = '';
}
if (isset($this->error['email'])) {
$this->data['error_email'] = $this->error['email'];
} else {
$this->data['error_email'] = '';
}
if (isset($this->error['enquiry'])) {
$this->data['error_enquiry'] = $this->error['enquiry'];
} else {
$this->data['error_enquiry'] = '';
}
if (isset($this->error['upload'])) {
$this->data['error_upload'] = $this->error['upload'];
} else {
$this->data['error_upload'] = '';
}
if (isset($this->error['captcha'])) {
$this->data['error_captcha'] = $this->error['captcha'];
} else {
$this->data['error_captcha'] = '';
}
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('orcamento/orcamento');
$this->data['store'] = $this->config->get('config_name');
$this->data['address'] = nl2br($this->config->get('config_address'));
$this->data['telephone'] = $this->config->get('config_telephone');
$this->data['fax'] = $this->config->get('config_fax');
if (isset($this->request->post['name'])) {
$this->data['name'] = $this->request->post['name'];
} else {
$this->data['name'] = $this->customer->getFirstName();
}
if (isset($this->request->post['email'])) {
$this->data['email'] = $this->request->post['email'];
} else {
$this->data['email'] = $this->customer->getEmail();
}
//via
if (isset($this->request->files['upload'])) {
$this->data['upload'] = $this->request->files['upload'];
} else {
$this->data['email'] = $this->customer->getEmail();
}
if (isset($this->request->post['enquiry'])) {
$this->data['enquiry'] = $this->request->post['enquiry'];
} else {
$this->data['enquiry'] = '';
}
if (isset($this->request->post['captcha'])) {
$this->data['captcha'] = $this->request->post['captcha'];
} else {
$this->data['captcha'] = '';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/orcamento/orcamento.tpl')) {
$this->template = $this->config->get('config_template') . '/template/orcamento/orcamento.tpl';
} else {
$this->template = 'default/template/orcamento/orcamento.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
public function success() {
$this->language->load('orcamento/orcamento');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('orcamento/orcamento'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_message'] = $this->language->get('text_message');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->link('common/home');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/success.tpl';
} else {
$this->template = 'default/template/common/success.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
public function captcha() {
$this->load->library('captcha');
$captcha = new Captcha();
$this->session->data['captcha'] = $captcha->getCode();
$captcha->showImage();
}
private function validate() {
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
$this->error['name'] = $this->language->get('error_name');
}
if (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
$this->error['enquiry'] = $this->language->get('error_enquiry');
}
if (!isset($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
$this->error['captcha'] = $this->language->get('error_captcha');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>
Bom feito isso é necessário criar o template (nota-se que criei a estrutura /orcamento/orcamento.tpl)
catalog/view/theme/nome_do_seu_tema/orcamento/orcamento.tpl
Código: Selecionar todos<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<h1><?php echo $heading_title; ?></h1>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="contact">
<h2><?php echo $text_location; ?></h2>
<div class="contact-info">
<div class="content"><div class="left"><b><?php echo $text_address; ?></b><br />
<?php echo $store; ?><br />
<?php echo $address; ?></div>
<div class="right">
<?php if ($telephone) { ?>
<b><?php echo $text_telephone; ?></b><br />
<?php echo $telephone; ?><br />
<br />
<?php } ?>
<?php if ($fax) { ?>
<b><?php echo $text_fax; ?></b><br />
<?php echo $fax; ?>
<?php } ?>
</div>
</div>
</div>
<h2><?php echo $text_contact; ?></h2>
<div class="content">
<b><?php echo $entry_name; ?></b><br />
<input type="text" name="name" value="<?php echo $name; ?>" />
<br />
<?php if ($error_name) { ?>
<span class="error"><?php echo $error_name; ?></span>
<?php } ?>
<br />
<b><?php echo $entry_email; ?></b><br />
<input type="text" name="email" value="<?php echo $email; ?>" />
<br />
<?php if ($error_email) { ?>
<span class="error"><?php echo $error_email; ?></span>
<?php } ?>
<br />
<b><?php echo $entry_enquiry; ?></b><br />
<textarea name="enquiry" cols="40" rows="10" style="width: 99%;"><?php echo $enquiry; ?></textarea>
<br />
<?php if ($error_enquiry) { ?>
<span class="error"><?php echo $error_enquiry; ?></span>
<?php } ?>
<br />
<br />
<b><?php echo $entry_upload; ?></b><br />
<input type="file" name="upload" />
<br />
<?php if ($error_upload) { ?>
<span class="error"><?php echo $error_upload; ?></span>
<?php } ?>
<br />
<b><?php echo $entry_captcha; ?></b><br />
<input type="text" name="captcha" value="<?php echo $captcha; ?>" />
<br />
<img src="index.php?route=orcamento/orcamento/captcha/captcha" alt="" />
<?php if ($error_captcha) { ?>
<span class="error"><?php echo $error_captcha; ?></span>
<?php } ?>
</div>
<div class="buttons">
<div class="right"><a onclick="$('#contact').submit();" class="button"><span><?php echo $button_continue; ?></span></a></div>
</div>
</form>
<?php echo $content_bottom; ?></div>
<?php echo $footer; ?>
Bom agora é criar o arquivo de tradução
catalog/language/portuguese-br/orcamento/orcamento.php
Código: Selecionar todos<?php
// Heading
$_['heading_title'] = 'Orçamento';
// Text
$_['text_location'] = 'Onde estamos';
$_['text_contact'] = 'Envie a imagem da peça desejada para receber o orçamento';
$_['text_address'] = 'Endereço:';
$_['text_email'] = 'E-mail:';
$_['text_telephone'] = 'Telefone:';
$_['text_fax'] = 'Fax:';
$_['text_message'] = '<p>Sua mensagem foi enviada com sucesso! Entraremos em contato.</p>';
// Entry Fields
$_['entry_name'] = 'Seu Nome:';
$_['entry_email'] = 'Seu E-mail:';
$_['entry_enquiry'] = 'Mensagem:';
$_['entry_upload'] = 'Anexar imagem:';
$_['entry_captcha'] = 'Digite o código da imagem:';
// Email
$_['email_subject'] = 'Mensagem %s';
// Errors
$_['error_name'] = 'Atenção: Seu nome deve ter entre 3 e 32 caracteres!';
$_['error_email'] = 'Atenção: Seu e-mail parece não ser válido!';
$_['error_upload'] = 'Atenção: Erro ao enviar anexo!';
$_['error_enquiry'] = 'Atenção: A mensagem deve ter entre 10 e 3000 caracteres!';
$_['error_captcha'] = 'Atenção: O código digitado não é o mesmo da imagem!';
?>
Bom agora é só adicionar o link no menu do topo editando o arquivo
(Estou utilizando esse arquivo separado no meu template porque se deixar o layout default, se o opencart atualizar ele vai alterar esse arquivo e você vai perder as alterações que havia feito)
catalog/view/theme/nome_do_seu_tema/template/common/header.tpl
Basicamente basta adicionar ANTES de:
</ul>
<div id="notification"></div>
o seu menu (observe a URL pois estou utilizando URL Amigável)
COM URL AMIGAVEL
Código: Selecionar todos<li>
<a href="orcamento/orcamento">
Orçamento
</a>
</li>
SEM URL AMIGAVEL
Código: Selecionar todos<li>
<a href="index.php?route=orcamento/orcamento">
Orçamento
</a>
</li>
mais um menuzinho