93 lines
4.4 KiB
PHP
93 lines
4.4 KiB
PHP
|
<?php
|
||
|
|
||
|
class OrderDetailController extends OrderDetailControllerCore
|
||
|
{
|
||
|
|
||
|
public function postProcess()
|
||
|
{
|
||
|
if (Tools::isSubmit('submitMessage')) {
|
||
|
$idOrder = (int)Tools::getValue('id_order');
|
||
|
$msgText = Tools::getValue('msgText');
|
||
|
|
||
|
if (!$idOrder || !Validate::isUnsignedId($idOrder)) {
|
||
|
$this->errors[] = Tools::displayError('The order is no longer valid.');
|
||
|
} elseif (empty($msgText)) {
|
||
|
$this->errors[] = Tools::displayError('The message cannot be blank.');
|
||
|
} elseif (!Validate::isMessage($msgText)) {
|
||
|
$this->errors[] = Tools::displayError('This message is invalid (HTML is not allowed).');
|
||
|
}
|
||
|
if (!count($this->errors)) {
|
||
|
$order = new Order($idOrder);
|
||
|
if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
|
||
|
//check if a thread already exist
|
||
|
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id);
|
||
|
$id_product = (int)Tools::getValue('id_product');
|
||
|
$cm = new CustomerMessage();
|
||
|
if (!$id_customer_thread) {
|
||
|
$ct = new CustomerThread();
|
||
|
$ct->id_contact = 0;
|
||
|
$ct->id_customer = (int)$order->id_customer;
|
||
|
$ct->id_shop = (int)$this->context->shop->id;
|
||
|
if ($id_product && $order->orderContainProduct($id_product)) {
|
||
|
$ct->id_product = $id_product;
|
||
|
}
|
||
|
$ct->id_order = (int)$order->id;
|
||
|
$ct->id_lang = (int)$this->context->language->id;
|
||
|
$ct->email = $this->context->customer->email;
|
||
|
$ct->status = 'open';
|
||
|
$ct->token = Tools::passwdGen(12);
|
||
|
$ct->add();
|
||
|
} else {
|
||
|
$ct = new CustomerThread((int)$id_customer_thread);
|
||
|
$ct->status = 'open';
|
||
|
$ct->update();
|
||
|
}
|
||
|
|
||
|
$cm->id_customer_thread = $ct->id;
|
||
|
$cm->message = $msgText;
|
||
|
$cm->ip_address = (int)ip2long($_SERVER['REMOTE_ADDR']);
|
||
|
$cm->add();
|
||
|
|
||
|
if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) {
|
||
|
$to = strval(Configuration::get('PS_SHOP_EMAIL'));
|
||
|
} else {
|
||
|
$to = new Contact((int)Configuration::get('PS_MAIL_EMAIL_MESSAGE'));
|
||
|
$to = strval($to->email);
|
||
|
}
|
||
|
$toName = strval(Configuration::get('PS_SHOP_NAME'));
|
||
|
$customer = $this->context->customer;
|
||
|
|
||
|
$product = new Product($id_product);
|
||
|
$product_name = '';
|
||
|
if (Validate::isLoadedObject($product) && isset($product->name[(int)$this->context->language->id])) {
|
||
|
$product_name = $product->name[(int)$this->context->language->id];
|
||
|
}
|
||
|
|
||
|
if (Validate::isLoadedObject($customer)) {
|
||
|
Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'),
|
||
|
array(
|
||
|
'{lastname}' => $customer->lastname,
|
||
|
'{firstname}' => $customer->firstname,
|
||
|
'{email}' => $customer->email,
|
||
|
'{id_order}' => (int)$order->id,
|
||
|
'{order_name}' => $order->getUniqReference(),
|
||
|
'{message}' => Tools::nl2br($msgText),
|
||
|
'{product_name}' => $product_name
|
||
|
),
|
||
|
$to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||
|
}
|
||
|
|
||
|
if (Tools::getValue('ajax') != 'true') {
|
||
|
Tools::redirect('index.php?controller=order-detail&id_order='.(int)$idOrder.'&confirm=true');
|
||
|
}
|
||
|
|
||
|
$this->context->smarty->assign('message_confirmation', true);
|
||
|
} else {
|
||
|
$this->errors[] = Tools::displayError('Order not found');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|