[+] FO : Messages in order detail are now stored in the Customer Service (SAV)
This commit is contained in:
@@ -55,5 +55,19 @@ class CustomerMessageCore extends ObjectModel
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public static function getMessagesByOrderId($id_order)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT cm.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname, (COUNT(cm.id_customer_message) = 0 AND ct.id_customer != 0) AS is_new_for_me
|
||||
FROM `'._DB_PREFIX_.'customer_message` cm
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer_thread` ct ON ct.`id_customer_thread` = cm.`id_customer_thread`
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON ct.`id_customer` = c.`id_customer`
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = cm.`id_employee`
|
||||
WHERE ct.id_order = '.(int)$id_order.'
|
||||
GROUP BY cm.id_customer_message
|
||||
ORDER BY cm.date_add DESC');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,13 @@ class CustomerThreadCore extends ObjectModel
|
||||
SELECT * FROM '._DB_PREFIX_.'customer_thread ct
|
||||
LEFT JOIN '._DB_PREFIX_.'customer_message cm ON ct.id_customer_thread = cm.id_customer_thread
|
||||
WHERE id_customer = '.(int)($id_customer));
|
||||
}
|
||||
}
|
||||
|
||||
public static function getIdCustomerThreadByEmailAndIdOrder($email, $id_order)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm
|
||||
WHERE cm.email = \''.pSQL($email).'\' AND cm.id_shop = '.(int)Context::getContext()->shop->getId(true).' AND cm.id_order = '.(int)$id_order.'');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,9 +106,7 @@ class ContactControllerCore extends FrontController
|
||||
SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm
|
||||
WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND cm.id_shop = '.(int)$this->id_current_shop.' 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_shop = '.(int)$this->id_current_shop.' AND cm.id_order = '.(int)(Tools::getValue('id_order')).'')
|
||||
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, (int)Tools::getValue('id_order'))
|
||||
)))
|
||||
{
|
||||
$fields = Db::getInstance()->ExecuteS('
|
||||
|
||||
@@ -59,12 +59,34 @@ class OrderDetailControllerCore extends FrontController
|
||||
$order = new Order($idOrder);
|
||||
if (Validate::isLoadedObject($order) AND $order->id_customer == $this->context->customer->id)
|
||||
{
|
||||
$message = new Message();
|
||||
$message->id_customer = (int)$this->context->customer->id;
|
||||
$message->message = $msgText;
|
||||
$message->id_order = (int)($idOrder);
|
||||
$message->private = false;
|
||||
$message->add();
|
||||
//check if a thread already exist
|
||||
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id);
|
||||
|
||||
p(var_dump($id_customer_thread));
|
||||
|
||||
$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->getId(true);
|
||||
if ($id_product = (int)Tools::getValue('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);
|
||||
$cm->id_customer_thread = $ct->id;
|
||||
$cm->message = Tools::htmlentitiesutf8(Tools::nl2br($msgText));
|
||||
$cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
|
||||
$cm->add();
|
||||
|
||||
if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE'))
|
||||
$to = strval(Configuration::get('PS_SHOP_EMAIL'));
|
||||
else
|
||||
@@ -73,16 +95,18 @@ class OrderDetailControllerCore extends FrontController
|
||||
$to = strval($to->email);
|
||||
}
|
||||
$toName = strval(Configuration::get('PS_SHOP_NAME'));
|
||||
$customer = $this->context->customer->id;
|
||||
$customer = $this->context->customer;
|
||||
|
||||
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)($message->id_order),
|
||||
'{message}' => $message->message),
|
||||
'{id_order}' => (int)($order->id),
|
||||
'{message}' => $msgText),
|
||||
$to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||||
|
||||
if (Tools::getValue('ajax') != 'true')
|
||||
Tools::redirect('index.php?controller=order-detail&id_order='.(int)$idOrder);
|
||||
}
|
||||
@@ -140,7 +164,7 @@ class OrderDetailControllerCore extends FrontController
|
||||
'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues,
|
||||
'deliveryState' => (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state) ? new State($addressDelivery->id_state) : false,
|
||||
'is_guest' => false,
|
||||
'messages' => Message::getMessagesByOrderId((int)($order->id)),
|
||||
'messages' => CustomerMessage::getMessagesByOrderId((int)($order->id)),
|
||||
'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE,
|
||||
'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
|
||||
'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'),
|
||||
|
||||
@@ -107,7 +107,7 @@ function updateOrderLineDisplay(domCheckbox){
|
||||
//send a message in relation to the order with ajax
|
||||
function sendOrderMessage (){
|
||||
paramString = "controller=order-detail&ajax=true";
|
||||
$('form#sendOrderMessage').find('input, textarea').each(function(){
|
||||
$('form#sendOrderMessage').find('input, textarea, select').each(function(){
|
||||
paramString += '&' + $(this).attr('name') + '=' + encodeURI($(this).val());
|
||||
});
|
||||
$.ajax({
|
||||
|
||||
@@ -356,6 +356,15 @@
|
||||
<form action="{$link->getPageLink('order-detail', true)}" method="post" class="std" id="sendOrderMessage">
|
||||
<p class="bold">{l s='Add a message:'}</p>
|
||||
<p>{l s='If you would like to add a comment about your order, please write it below.'}</p>
|
||||
<p>
|
||||
<label for="id_product">{l s='Product'}</label>
|
||||
<select name="id_product" style="width:300px;">
|
||||
<option value="0">{l s='-- Choose --'}</option>
|
||||
{foreach from=$products item=product name=products}
|
||||
<option value="{$product.product_id}">{$product.product_name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</p>
|
||||
<p class="textarea">
|
||||
<textarea cols="67" rows="3" name="msgText"></textarea>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user