Jump to content

Modificar Formulario Contacto - Prestashop 1.4 [SOLUCIONADO]


Recommended Posts

Hola, en mi formulario contacto sale la opcion "numero de pedido"

quiero sacar esa opción tengo entendido que tengo que modificar el archivo /controllers/ContactController.php por una cosa de validacion de los campos

 

class ContactControllerCore extends FrontController
{
public $php_self = 'contact-form.php';
public $ssl = true;
public function preProcess()
{
 parent::preProcess();
 if (self::$cookie->isLogged())
 {
  self::$smarty->assign('isLogged', 1);
  $customer = new Customer((int)(self::$cookie->id_customer));
  if (!Validate::isLoadedObject($customer))
die(Tools::displayError('Customer not found'));
  $products = array();
  $orders = array();
  $getOrders = Db::getInstance()->ExecuteS('
SELECT id_order
FROM '._DB_PREFIX_.'orders
WHERE id_customer = '.(int)$customer->id.' ORDER BY date_add');
  foreach ($getOrders as $row)
  {
$order = new Order($row['id_order']);
$date = explode(' ', $order->date_add);
$orders[$row['id_order']] = Tools::displayDate($date[0], self::$cookie->id_lang);
$tmp = $order->getProducts();
foreach ($tmp as $key => $val)
	 $products[$val['product_id']] = $val['product_name'];
  }
  $orderList = '';
  foreach ($orders as $key => $val)
$orderList .= '<option value="'.$key.'" '.((int)(Tools::getValue('id_order')) == $key ? 'selected' : '').' >'.$key.' -- '.$val.'</option>';
  $orderedProductList = '';
  foreach ($products as $key => $val)
$orderedProductList .= '<option value="'.$key.'" '.((int)(Tools::getValue('id_product')) == $key ? 'selected' : '').' >'.$val.'</option>';
  self::$smarty->assign('orderList', $orderList);
  self::$smarty->assign('orderedProductList', $orderedProductList);
 }
 if (Tools::isSubmit('submitMessage'))
 {
  $fileAttachment = NULL;
  if (isset($_FILES['fileUpload']['name']) AND !empty($_FILES['fileUpload']['name']) AND !empty($_FILES['fileUpload']['tmp_name']))
  {
$extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
$filename = uniqid().substr($_FILES['fileUpload']['name'], -5);
$fileAttachment['content'] = file_get_contents($_FILES['fileUpload']['tmp_name']);
$fileAttachment['name'] = $_FILES['fileUpload']['name'];
$fileAttachment['mime'] = $_FILES['fileUpload']['type'];
  }
  $message = Tools::htmlentitiesUTF8(Tools::getValue('message'));
  if (!($from = trim(Tools::getValue('from'))) OR !Validate::isEmail($from))
$this->errors[] = Tools::displayError('Invalid e-mail address');
  elseif (!($message = nl2br2($message)))
$this->errors[] = Tools::displayError('Message cannot be blank');
  elseif (!Validate::isCleanHtml($message))
$this->errors[] = Tools::displayError('Invalid message');
  elseif (!($id_contact = (int)(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact((int)($id_contact), (int)(self::$cookie->id_lang)))))
$this->errors[] = Tools::displayError('Please select a subject on the list.');
  elseif (!empty($_FILES['fileUpload']['name']) AND $_FILES['fileUpload']['error'] != 0)
$this->errors[] = Tools::displayError('An error occurred during the file upload');
  elseif (!empty($_FILES['fileUpload']['name']) AND !in_array(substr($_FILES['fileUpload']['name'], -4), $extension) AND !in_array(substr($_FILES['fileUpload']['name'], -5), $extension))
$this->errors[] = Tools::displayError('Bad file extension');
  else
  {
if ((int)(self::$cookie->id_customer))
	 $customer = new Customer((int)(self::$cookie->id_customer));
else
{
	 $customer = new Customer();
	 $customer->getByEmail($from);
}
$contact = new Contact($id_contact, self::$cookie->id_lang);
if (!((
	  $id_customer_thread = (int)Tools::getValue('id_customer_thread')
	  AND (int)Db::getInstance()->getValue('
	  SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm
	  WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND token = \''.pSQL(Tools::getValue('token')).'\'')
	 ) OR (
	  $id_customer_thread = (int)Db::getInstance()->getValue('
	  SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm
	  WHERE cm.email = \''.pSQL($from).'\' AND cm.id_order = '.(int)(Tools::getValue('id_order')).'')
	 )))
{
	 $fields = Db::getInstance()->ExecuteS('
	 SELECT cm.id_customer_thread, cm.id_contact, cm.id_customer, cm.id_order, cm.id_product, cm.email
	 FROM '._DB_PREFIX_.'customer_thread cm
	 WHERE email = \''.pSQL($from).'\' AND ('.
	  ($customer->id ? 'id_customer = '.(int)($customer->id).' OR ' : '').'
	  id_order = '.(int)(Tools::getValue('id_order')).')');
	 $score = 0;
	 foreach ($fields as $key => $row)
	 {
	  $tmp = 0;
	  if ((int)$row['id_customer'] AND $row['id_customer'] != $customer->id AND $row['email'] != $from)
	   continue;
	  if ($row['id_order'] != 0 AND Tools::getValue('id_order') != $row['id_order'])
	   continue;
	  if ($row['email'] == $from)
	   $tmp += 4;
	  if ($row['id_contact'] == $id_contact)
	   $tmp++;
	  if (Tools::getValue('id_product') != 0 AND $row['id_product'] ==  Tools::getValue('id_product'))
	   $tmp += 2;
	  if ($tmp >= 5 AND $tmp >= $score)
	  {
	   $score = $tmp;
	   $id_customer_thread = $row['id_customer_thread'];
	  }
	 }
}
$old_message = Db::getInstance()->getValue('
	 SELECT cm.message FROM '._DB_PREFIX_.'customer_message cm
	 WHERE cm.id_customer_thread = '.(int)($id_customer_thread).'
	 ORDER BY date_add DESC');
if ($old_message == htmlentities($message, ENT_COMPAT, 'UTF-8'))
{
	 self::$smarty->assign('alreadySent', 1);
	 $contact->email = '';
	 $contact->customer_service = 0;
}
if (!empty($contact->email))
{
	 if (Mail::Send((int)self::$cookie->id_lang, 'contact', Mail::l('Message from contact form', (int)self::$cookie->id_lang), array('{email}' => $from, '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : ''), $fileAttachment)
	  AND Mail::Send((int)self::$cookie->id_lang, 'contact_form', Mail::l('Your message has been correctly sent', (int)self::$cookie->id_lang), array('{message}' => stripslashes($message)), $from))
	  self::$smarty->assign('confirmation', 1);
	 else
	  $this->errors[] = Tools::displayError('An error occurred while sending message.');
}
if ($contact->customer_service)
{
	 if ((int)$id_customer_thread)
	 {
	  $ct = new CustomerThread($id_customer_thread);
	  $ct->status = 'open';
	  $ct->id_lang = (int)self::$cookie->id_lang;
	  $ct->id_contact = (int)($id_contact);
	  if ($id_order = (int)Tools::getValue('id_order'))
	   $ct->id_order = $id_order;
	  if ($id_product = (int)Tools::getValue('id_product'))
	   $ct->id_product = $id_product;
	  $ct->update();
	 }
	 else
	 {
	  $ct = new CustomerThread();
	  if (isset($customer->id))
	   $ct->id_customer = (int)($customer->id);
	  if ($id_order = (int)Tools::getValue('id_order'))
	   $ct->id_order = $id_order;
	  if ($id_product = (int)Tools::getValue('id_product'))
	   $ct->id_product = $id_product;
	  $ct->id_contact = (int)($id_contact);
	  $ct->id_lang = (int)self::$cookie->id_lang;
	  $ct->email = $from;
	  $ct->status = 'open';
	  $ct->token = Tools::passwdGen(12);
	  $ct->add();
	 }
	 if ($ct->id)
	 {
	  $cm = new CustomerMessage();
	  $cm->id_customer_thread = $ct->id;
	  $cm->message = htmlentities($message, ENT_COMPAT, 'UTF-8');
	  if (isset($filename) AND rename($_FILES['fileUpload']['tmp_name'], _PS_MODULE_DIR_.'../upload/'.$filename))
	   $cm->file_name = $filename;
	  $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
	  $cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
	  if ($cm->add())
	  {
	   if (empty($contact->email))
		Mail::Send((int)self::$cookie->id_lang, 'contact_form', Mail::l('Your message has been correctly sent', (int)self::$cookie->id_lang), array('{message}' => stripslashes($message)), $from);
	   self::$smarty->assign('confirmation', 1);
	  }
	  else
	   $this->errors[] = Tools::displayError('An error occurred while sending message.');
	 }
	 else
	  $this->errors[] = Tools::displayError('An error occurred while sending message.');
}
if (count($this->errors) > 1)
	 array_unique($this->errors);
  }
 }
}
public function setMedia()
{
 parent::setMedia();
 Tools::addCSS(_THEME_CSS_DIR_.'contact-form.css');
}
public function process()
{
 parent::process();
 $email = Tools::safeOutput(Tools::getValue('from', ((isset(self::$cookie) AND isset(self::$cookie->email) AND Validate::isEmail(self::$cookie->email)) ? self::$cookie->email : '')));
 self::$smarty->assign(array(
  'errors' => $this->errors,
  'email' => $email,
  'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD')
 ));[/size][/font][/color]
[color=#343943][font=Arial, Helvetica, sans-serif][size=3]  if ($id_customer_thread = (int)Tools::getValue('id_customer_thread') AND $token = Tools::getValue('token'))
 {
  $customerThread = Db::getInstance()->getRow('
  SELECT cm.* FROM '._DB_PREFIX_.'customer_thread cm
  WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND token = \''.pSQL($token).'\'');
  self::$smarty->assign('customerThread', $customerThread);
 }
 self::$smarty->assign(array('contacts' => Contact::getContacts((int)(self::$cookie->id_lang)),
 'message' => html_entity_decode(Tools::getValue('message'))
 ));
}
public function displayContent()
{
 $_POST = array_merge($_POST, $_GET);
 parent::displayContent();
 self::$smarty->display(_PS_THEME_DIR_.'contact-form.tpl');
}
}

¿Que tengo que modificar de todo esto?y que fichero mas tengo que modificar para sacar esa opcion(Numero de pedido) de "contacto"?

Link to comment
Share on other sites

Tienes que editar el fichero: /themes/tu-plantilla/contact-form.tpl y cargarte esto:

 

 {if !$PS_CATALOG_MODE}
  {if (!isset($customerThread.id_order) || $customerThread.id_order > 0)}
  <p class="text">
<label for="id_order">{l s='Order ID'}</label>
{if !isset($customerThread.id_order) && isset($isLogged) && $isLogged == 1}
 <select name="id_order" ><option value="0">{l s='-- Choose --'}</option>{$orderList}</select>
{elseif !isset($customerThread.id_order) && !isset($isLogged)}
 <input type="text" name="id_order" id="id_order" value="{if isset($customerThread.id_order) && $customerThread.id_order > 0}{$customerThread.id_order|intval}{else}{if isset($smarty.post.id_order)}{$smarty.post.id_order|intval}{/if}{/if}" />
{elseif $customerThread.id_order > 0}
 <input type="text" name="id_order" id="id_order" value="{$customerThread.id_order|intval}" readonly="readonly" />
{/if}
  </p>
  {/if}
  {if isset($isLogged) && $isLogged}
  <p class="text">
  <label for="id_product">{l s='Product'}</label>
{if !isset($customerThread.id_product)}
 <select name="id_product" style="width:300px;"><option value="0">{l s='-- Choose --'}</option>{$orderedProductList}</select>
{elseif $customerThread.id_product > 0}
 <input type="text" name="id_product" id="id_product" value="{$customerThread.id_product|intval}" readonly="readonly" />
{/if}
  </p>
  {/if}
 {/if}

 

Una vez modificado el fichero, no se te olvide ir a la pestaña Preferencias/Rendimiento y señalar Forzar compilación "SI".

Link to comment
Share on other sites

Gracias modifique solo el fichero que me mensionas themes/tu-plantilla/contact-form.tpl

borre lo que comentaste y ahora funciona perfecto!

Un placer ayudarte y servirte!

 

Si das el tema como solucionado, edita el titulo del tema y añade la palabra "Solucionado" al titulo, esto ayudara a mantener una mayor organización en el foro.

 

Un Saludo y recuerda que estaremos en el foro, para guiarte por este mundo oscuro y tenebroso.

Link to comment
Share on other sites

  • 8 months later...

Estimados; he seguido los pasos y me falta el último:

¿qué es lo que tengo que borrar para que funcione perfecto?

Cuando dices "borré lo que comentaste"... no sé a que se refieren. Por favor díganme o muéstrenme qué es lo que tengo que borrar.

 

Disculpen mi falta de conocimientos técnicos pero le agradeceré mucho su ayuda.

Muchas Gracias y saludos.

Link to comment
Share on other sites

  • 2 months later...

Nadie que grande eres.

 

La verdad que yo debia quitar del formulario lo siguiente "nº de Pedido" que gracias a ti esta borrado.

 

Pero tambien deberia quitar el "asunto" o "tema", ya que no quiero que el usuario selecione ninguno, quiero bloquearlo a uno solo contacto y que quede oculto!

 

Ya que siempre ira al mismo administrador.

 

Como lo deberia hacer para que posterior funcionara correctamente?

 

Gracias de antemano.

Link to comment
Share on other sites

Estimados; he seguido los pasos y me falta el último:

¿qué es lo que tengo que borrar para que funcione perfecto?

Cuando dices "borré lo que comentaste"... no sé a que se refieren. Por favor díganme o muéstrenme qué es lo que tengo que borrar.

 

Disculpen mi falta de conocimientos técnicos pero le agradeceré mucho su ayuda.

Muchas Gracias y saludos.

 

Hola joyaspriss,

 

creo que encontre lo que teniamos que borrar, probe varias cosas y en el mismo archivo themes/tu-plantilla/contact-form.tpl

 

tenes que borrar esto:

 

 

<p class="text">

<label for="id_order">{l s='Order ID'}</label>

{if !isset($customerThread.id_order) && isset($isLogged) && $isLogged == 1}

<select name="id_order" ><option value="0">{l s='-- Choose --'}</option>{$orderList}</select>

{elseif !isset($customerThread.id_order) && !isset($isLogged)}

<input type="text" name="id_order" id="id_order" value="{if isset($customerThread.id_order) && $customerThread.id_order > 0}{$customerThread.id_order|intval}{else}{if isset($smarty.post.id_order)}{$smarty.post.id_order|intval}{/if}{/if}" />

{elseif $customerThread.id_order > 0}

<input type="text" name="id_order" id="id_order" value="{$customerThread.id_order|intval}" readonly="readonly" />

{/if}

</p>

 

no olvides "Una vez modificado el fichero, no se te olvide ir a la pestaña Preferencias/Rendimiento y señalar Forzar compilación "SI"."

Saludos

Edited by Alexis rech (see edit history)
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...