Всем доброго!
Посоветуйте пожалуйста как решить вопрос:
есть клиент, переписка с ним не велась (в сообщения нет его) заходим в клиенты - выбираем нужного человека, и надо отправить ему сообщение, как это сделать?
Заранее спасибо!
1) Откройте файл
/controllers/admin/AdminCustomersController.php и после:
Код:
parent::initProcess();
добавьте подобный код:
Код:
if (Tools::isSubmit('submitMessage'))
{
$customer = new Customer(Tools::getValue('id_customer'));
if (!Validate::isLoadedObject($customer)) {
$this->errors[] = Tools::displayError('The customer is invalid.');
} elseif (!Tools::getValue('message')) {
$this->errors[] = Tools::displayError('The message cannot be blank.');
} else {
$rules = call_user_func(array('Message', 'getValidationRules'), 'Message');
foreach ($rules['required'] as $field) {
if (($value = Tools::getValue($field)) == false && (string)$value != '0') {
if (!Tools::getValue('id_'.$this->table) || $field != 'passwd') {
$this->errors[] = sprintf(Tools::displayError('field %s is required.'), $field);
}
}
}
foreach ($rules['size'] as $field => $maxLength) {
if (Tools::getValue($field) && Tools::strlen(Tools::getValue($field)) > $maxLength) {
$this->errors[] = sprintf(Tools::displayError('field %1$s is too long (%2$d chars max).'), $field, $maxLength);
}
}
foreach ($rules['validate'] as $field => $function) {
if (Tools::getValue($field)) {
if (!Validate::$function(htmlentities(Tools::getValue($field), ENT_COMPAT, 'UTF-8'))) {
$this->errors[] = sprintf(Tools::displayError('field %s is invalid.'), $field);
}
}
}
if (!count($this->errors))
{
$customer_message = new CustomerMessage();
$customer_message->id_customer_thread = $customer_thread->id;
$customer_message->id_employee = (int)$this->context->employee->id;
$customer_message->message = Tools::getValue('message');
$customer_message->private = Tools::getValue('visibility');
if (!$customer_message->add()) {
$this->errors[] = Tools::displayError('An error occurred while saving the message.');
} else {
$message = $customer_message->message;
if (Configuration::get('PS_MAIL_TYPE', null, null, $order->id_shop) != Mail::TYPE_TEXT) {
$message = Tools::nl2br($customer_message->message);
}
$varsTpl = array(
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{order_name}' => 'NO',
'{message}' => $message
);
if (@Mail::Send($customer->id_lang, 'order_merchant_comment',
Mail::l('New message regarding your order', (int)$customer->id_lang), $varsTpl, $customer->email,
$customer->firstname.' '.$customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int)$customer->id_shop)) {
Tools::redirectAdmin(self::$currentIndex.'&id_customer='.$customer->id.'&viewcustomer&conf=11'.'&token='.$this->token);
}
}
$this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.');
}
}
}
2) Откройте файл
Код:
/адм.дир/themes/default/template/controllers/customers/helpers/view/view.tpl
и после:
Код:
<div class="panel">
<div class="panel-heading">
<i class="icon-eye-close"></i> {l s='Add a private note'}
</div>
<div class="alert alert-info">{l s='This note will be displayed to all employees but not to customers.'}</div>
<form id="customer_note" class="form-horizontal" action="ajax.php" method="post" onsubmit="saveCustomerNote({$customer->id|intval});return false;" >
<div class="form-group">
<div class="col-lg-12">
<textarea name="note" id="noteContent" onkeyup="$('#submitCustomerNote').removeAttr('disabled');">{$customer_note}</textarea>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<button type="submit" id="submitCustomerNote" class="btn btn-default pull-right" disabled="disabled">
<i class="icon-save"></i>
{l s='Save'}
</button>
</div>
</div>
<span id="note_feedback"></span>
</form>
</div>
добавьте подобный код:
Код:
<div id="messages" class="well hidden-print">
<form action="{$smarty.server.REQUEST_URI|escape:'html':'UTF-8'}" method="post">
<div id="message" class="form-horizontal">
<div class="form-group">
<label class="control-label col-lg-3">{l s='Message'}</label>
<div class="col-lg-9">
<textarea id="txt_msg" class="textarea-autosize" name="message">{Tools::getValue('message')|escape:'html':'UTF-8'}</textarea>
<p id="nbchars"></p>
</div>
</div>
<input type="hidden" name="id_customer" value="{$customer->id|intval}" />
<button type="submit" id="submitMessage" class="btn btn-primary pull-right" name="submitMessage">
{l s='Send message'}
</button>
<div class="clearfix"></div>
</div>
</form>
</div>