[+] FO : Messages in order detail are now stored in the Customer Service (SAV)

This commit is contained in:
vAugagneur
2011-09-13 07:18:04 +00:00
parent e2bb3d430a
commit ae697852cf
6 changed files with 67 additions and 15 deletions
+14
View File
@@ -55,5 +55,19 @@ class CustomerMessageCore extends ObjectModel
$fields['date_add'] = pSQL($this->date_add); $fields['date_add'] = pSQL($this->date_add);
return $fields; 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');
}
} }
+7
View File
@@ -80,5 +80,12 @@ class CustomerThreadCore extends ObjectModel
LEFT JOIN '._DB_PREFIX_.'customer_message cm ON ct.id_customer_thread = cm.id_customer_thread LEFT JOIN '._DB_PREFIX_.'customer_message cm ON ct.id_customer_thread = cm.id_customer_thread
WHERE id_customer = '.(int)($id_customer)); 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.'');
}
} }
+1 -3
View File
@@ -106,9 +106,7 @@ class ContactControllerCore extends FrontController
SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm 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')).'\'') 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 ( ) OR (
$id_customer_thread = (int)Db::getInstance()->getValue(' $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, (int)Tools::getValue('id_order'))
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')).'')
))) )))
{ {
$fields = Db::getInstance()->ExecuteS(' $fields = Db::getInstance()->ExecuteS('
+34 -10
View File
@@ -59,12 +59,34 @@ class OrderDetailControllerCore extends FrontController
$order = new Order($idOrder); $order = new Order($idOrder);
if (Validate::isLoadedObject($order) AND $order->id_customer == $this->context->customer->id) if (Validate::isLoadedObject($order) AND $order->id_customer == $this->context->customer->id)
{ {
$message = new Message(); //check if a thread already exist
$message->id_customer = (int)$this->context->customer->id; $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id);
$message->message = $msgText;
$message->id_order = (int)($idOrder); p(var_dump($id_customer_thread));
$message->private = false;
$message->add(); $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')) if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE'))
$to = strval(Configuration::get('PS_SHOP_EMAIL')); $to = strval(Configuration::get('PS_SHOP_EMAIL'));
else else
@@ -73,16 +95,18 @@ class OrderDetailControllerCore extends FrontController
$to = strval($to->email); $to = strval($to->email);
} }
$toName = strval(Configuration::get('PS_SHOP_NAME')); $toName = strval(Configuration::get('PS_SHOP_NAME'));
$customer = $this->context->customer->id; $customer = $this->context->customer;
if (Validate::isLoadedObject($customer)) if (Validate::isLoadedObject($customer))
Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'), Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'),
array( array(
'{lastname}' => $customer->lastname, '{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname, '{firstname}' => $customer->firstname,
'{email}' => $customer->email, '{email}' => $customer->email,
'{id_order}' => (int)($message->id_order), '{id_order}' => (int)($order->id),
'{message}' => $message->message), '{message}' => $msgText),
$to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname); $to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname);
if (Tools::getValue('ajax') != 'true') if (Tools::getValue('ajax') != 'true')
Tools::redirect('index.php?controller=order-detail&id_order='.(int)$idOrder); Tools::redirect('index.php?controller=order-detail&id_order='.(int)$idOrder);
} }
@@ -140,7 +164,7 @@ class OrderDetailControllerCore extends FrontController
'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues,
'deliveryState' => (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state) ? new State($addressDelivery->id_state) : false, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state) ? new State($addressDelivery->id_state) : false,
'is_guest' => false, 'is_guest' => false,
'messages' => Message::getMessagesByOrderId((int)($order->id)), 'messages' => CustomerMessage::getMessagesByOrderId((int)($order->id)),
'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE,
'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'),
+1 -1
View File
@@ -107,7 +107,7 @@ function updateOrderLineDisplay(domCheckbox){
//send a message in relation to the order with ajax //send a message in relation to the order with ajax
function sendOrderMessage (){ function sendOrderMessage (){
paramString = "controller=order-detail&ajax=true"; 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()); paramString += '&' + $(this).attr('name') + '=' + encodeURI($(this).val());
}); });
$.ajax({ $.ajax({
+9
View File
@@ -356,6 +356,15 @@
<form action="{$link->getPageLink('order-detail', true)}" method="post" class="std" id="sendOrderMessage"> <form action="{$link->getPageLink('order-detail', true)}" method="post" class="std" id="sendOrderMessage">
<p class="bold">{l s='Add a message:'}</p> <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>{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"> <p class="textarea">
<textarea cols="67" rows="3" name="msgText"></textarea> <textarea cols="67" rows="3" name="msgText"></textarea>
</p> </p>