Автор Тема: Подключить форму заказа  (Прочитано 4522 раз)

14 Апрель 2013, 02:02:06
  • Новичок
  • *
  • Сообщений: 9
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Доброго времени суток всем. Помогите пожалуйста с решением одного вопроса, а именно, подключить форму заказа на сайте
http://fashion-style.md/index.php?id_cms=10&controller=cms&id_lang=8

Форму набросала, не исключаю, что коряво, подскажите что сделать чтобы она заработала, что вписать в файле обработчике и куда его закидывать нужно? спасибо всем за ранее.

<h2>Форма заполнения заказа на сайте <span style="color: #ce2a04;">fashion-style.md</span></h2>
<form id="create_order" class="form" action="/auth/change_user_final.html" method="post">
<p style="text-align: right;"><em>Поля <span style="color: #ce2a04;">*</span> обязательны для заполнения</em></p>
<input id="do" type="hidden" name="do" value="auth" /> <input id="variables" type="hidden" name="variables" value="AddOrders" />
<div class="form-row-black"> </div>
<div class="form-row pos_1">
<div class="label">Введите имя<span style="color: #ce2a04;">*</span></div>
<div class="input-container"><input class="input req-string" type="text" name="1__order_name" value="" /></div>
</div>
<div class="form-row pos_1">
<div class="label">Ваш Е-mail</div>
<div class="input-container"><input class="input req-string" type="text" name="1__order_namber" value="" /></div>
</div>
<div class="form-row pos_1">
<div class="label">Контактный номер<span style="color: #ce2a04;">*</span></div>
<div class="input-container"><input class="input req-string" type="text" name="1__order_namber" value="" /></div>
</div>
<div class="form-row pos_1">
<div class="label">Ссылка на товар<span style="color: #ce2a04;">*</span></div>
<div class="input-container"><input class="input req-string" type="text" name="1__order_link" value="" /></div>
</div>
<div class="form-row pos_1">
<div class="label">Категория товара</div>
<div class="input-container"><select name="kategoria" size="1"> <option value="woman"> Женская одежда </option> <option selected="selected" value="man"> Мужская одежда </option> <option value="baby"> Детская одежда </option></select></div>
</div>
<div class="form-row pos_1">
<div class="label">Количество, шт <span style="color: #ce2a04;">*</span></div>
<div class="input-container"><select name="kolicestvo" size="1"> <option selected="selected" value="one"> 1 </option> <option value="two"> 2 </option> <option value="three"> 3 </option><option value="tho"> 4 </option><option value="five"> 5 </option></select></div>
</div>
<div class="form-row pos_1">
<div class="label">Цена товара, долл<span style="color: #ce2a04;">*</span></div>
<textarea name="adress" cols="20"></textarea></div>
<div class="form-row pos_1">
<div class="label">Комментарий к товару <br />(цвет, размер, прочее)<br /><a href="http://localhost/maria/index.php?id_cms=6&amp;controller=cms&amp;id_lang=8" target="_blank"><span style="color: #ce2a04;">Таблица размеров</span></a></div>
<textarea name="adress" rows="3" cols="55"></textarea></div>
<div class="form-row pos_1">
<div class="label">Введите адрес для доставки</div>
<textarea name="adress" rows="5" cols="55"></textarea></div>
<br /><hr id="last_line" />
<div class="form-row pos_1"><input class="sendBtn BtnAddPosition" type="button" value="Добавить позицию" />      <input class="sendBtn BtnAddPosition" type="button" value="Отправить заказ" />      <input type="reset" value="Отмена" /></div>
<div id="error_order" class="error-div"> </div>
</form>
14 Апрель 2013, 14:29:51
Ответ #1
  • Модератор
  • Ветеран
  • *****
  • Сообщений: 86688
  • Репутация: +25428/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Для формы контактов файл
/themes/default/contact-form.tpl
Изменять, добавлять поля нужно в этом файле, а не на странице смс.
14 Апрель 2013, 18:28:04
Ответ #2
  • Новичок
  • *
  • Сообщений: 9
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
если редактировать этот файл contact-form.tpl, то изменения можно увидеть на странице обратная связь, я правильно понимаю?
14 Апрель 2013, 19:26:21
Ответ #3
  • Ветеран
  • *****
  • Сообщений: 885
  • Репутация: +206/-0
    • Просмотр профиля
contact-form.tpl - это страница контактов.
На страницу смс код HTML можно вставить через редактор.
Только вам нужно поменять файл обработчик формы change_user_final.html
<form id="create_order" class="form" action="/auth/change_user_final.html" method="post">на ContactController.php, а в нем создать фунции обработки формы заказа.
19 Апрель 2013, 15:54:43
Ответ #4
  • Новичок
  • *
  • Сообщений: 9
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
может я не догоняю, что-то, но у меня файла ContactController.php нет.
а может кто-то из знающих помочь добавить в стандартной форме сделать изменения, например добавить поле для ввода номера телефона, эти изменения надо сделать в файле contact-form.tp, верно? спасибо за помощь, заранее
19 Апрель 2013, 18:25:27
Ответ #5
  • Партнер
  • Ветеран
  • ****
  • Сообщений: 22816
  • Репутация: +17143/-1
  • Разработка веб-сайтов и веб-программирование
    • Просмотр профиля
Чтобы добавить дополнительное поле в форму контактов нужно:
1. В шаблоне /themes/my_theme/contact-form.tpl добавить
<p class="text">
<label for="email">{l s='Телефон'}</label>
<input type="text" id="telephone" name="telephone" value="{if isset($smarty.post.telephone)}{$smarty.post.telephone}{/if}">
</p>
2. В class ContactController, файл и переменные зависят от версии.
Prestashop 1.5 - /controllers/front/ContactController.php
Prestashop 1.4 - /controllers/ContactController.php
$email_variables =
....
if (Mail::Send((int)self::$cookie->id_lang, ...
Добавить поле телефон
'{telephone}' => $telephoneили
'{telephone}' => $_POST['telephone']3. В шаблон письма добавить поле Телефон - /mails/ru/contact.html
Телефон: {telephone}
Интернет-магазин под ключ.
Какой выбрать движок для интернет магазина ?
Какой движок лучше ?
Magento или Prestashop ?
Решение всех Ваших вопросов в создании Интернет-магазина.
20 Апрель 2013, 02:29:16
Ответ #6
  • Новичок
  • *
  • Сообщений: 9
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
первая часть прошла успешно, добавила дополнительное поле в themes/my_theme/contact-form.tpl
но вот вторая часть стопорнулась, у меня установлена преста 1.5. не знаю куда вставить код '{telephone}' => $_POST['telephone']
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2012 PrestaShop SA
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

class ContactControllerCore extends FrontController
{
public $php_self 'contact';
public $ssl true;

/**
 * Start forms process
 * @see FrontController::postProcess()
 */
public function postProcess()
{
if (Tools::isSubmit('submitMessage'))
{
$fileAttachment null;
if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !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::getValue('message'); // Html entities is not usefull, iscleanHtml check there is no bad html tags.
if (!($from trim(Tools::getValue('from'))) || !Validate::isEmail($from))
$this->errors[] = Tools::displayError('Invalid e-mail address');
else if (!$message)
$this->errors[] = Tools::displayError('Message cannot be blank');
else if (!Validate::isCleanHtml($message))
$this->errors[] = Tools::displayError('Invalid message');
else if (!($id_contact = (int)(Tools::getValue('id_contact'))) || !(Validate::isLoadedObject($contact = new Contact($id_contact$this->context->language->id))))
$this->errors[] = Tools::displayError('Please select a subject from the list.');
else if (!empty($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['error'] != 0)
$this->errors[] = Tools::displayError('An error occurred during the file upload');
else if (!empty($_FILES['fileUpload']['name']) && !in_array(substr($_FILES['fileUpload']['name'], -4), $extension) && !in_array(substr($_FILES['fileUpload']['name'], -5), $extension))
$this->errors[] = Tools::displayError('Bad file extension');
else
{
$customer $this->context->customer;
if (!$customer->id)
$customer->getByEmail($from);

$contact = new Contact($id_contact$this->context->language->id);

if (!((
($id_customer_thread = (int)Tools::getValue('id_customer_thread'))
&& (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 cm.id_shop = '.(int)$this->context->shop->id.' AND token = \''.pSQL(Tools::getValue('token')).'\'')
) || (
$id_customer_thread CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, (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 cm.id_shop = '.(int)$this->context->shop->id.' 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'] && $row['id_customer'] != $customer->id && $row['email'] != $from)
continue;
if ($row['id_order'] != && 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') != && $row['id_product'] == Tools::getValue('id_product'))
$tmp += 2;
if ($tmp >= && $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
LEFT JOIN '
._DB_PREFIX_.'customer_thread cc on (cm.id_customer_thread = cc.id_customer_thread)
WHERE cc.id_customer_thread = '
.(int)($id_customer_thread).' AND cc.id_shop = '.(int)$this->context->shop->id.'
ORDER BY cm.date_add DESC'
);
if ($old_message == $message)
{
$this->context->smarty->assign('alreadySent'1);
$contact->email '';
$contact->customer_service 0;
}
if (!empty($contact->email))
{
$id_order = (int)Tools::getValue('id_order'0);
$order = new Order($id_order);

$mail_var_list = array(
'{email}' => $from,
'{message}' => Tools::nl2br(stripslashes($message)),
'{id_order}' => $id_order,
'{order_name}' => $order->getUniqReference(),
'{attached_file}' => isset($_FILES['fileUpload'], $_FILES['fileUpload']['name']) ? $_FILES['fileUpload']['name'] : ''
);

if (Mail::Send($this->context->language->id'contact'Mail::l('Message from contact form'),
$mail_var_list$contact->email$contact->name$from, ($customer->id $customer->firstname.' '.$customer->lastname ''),
$fileAttachment) &&
Mail::Send($this->context->language->id'contact_form'Mail::l('Your message has been correctly sent'), $mail_var_list$from))
$this->context->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)$this->context->language->id;
$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);
$ct->id_shop = (int)$this->context->shop->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)$this->context->language->id;
$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 Tools::htmlentitiesUTF8($message);
if (isset($filename) && 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))
{
$var_list = array(
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => stripslashes($message)
);
if ($ct->id_order)
{
$order = new Order($ct->id_order);
$var_list['{order_name}'] = $order->reference;
}
if (isset($filename))
$var_list['{attached_file}'] = $_FILES['fileUpload']['name'];
Mail::Send($this->context->language->id'contact_form'Mail::l('Your message has been correctly sent'), $var_list$from);
}
$this->context->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();
$this->addCSS(_THEME_CSS_DIR_.'contact-form.css');
$this->addJS(_THEME_JS_DIR_.'contact-form.js');
}

/**
 * Assign template vars related to page content
 * @see FrontController::initContent()
 */
public function initContent()
{
parent::initContent();

$this->assignOrderList();

$email Tools::safeOutput(Tools::getValue('from',
((isset($this->context->cookie) && isset($this->context->cookie->email) && Validate::isEmail($this->context->cookie->email)) ? $this->context->cookie->email '')));
$this->context->smarty->assign(array(
'errors' => $this->errors,
'email' => $email,
'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD')
));


if ($id_customer_thread = (int)Tools::getValue('id_customer_thread') && $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 cm.id_shop = '
.(int)$this->context->shop->id.
AND token = \''
.pSQL($token).'\'
'
);
$this->context->smarty->assign('customerThread'$customerThread);
}

$this->context->smarty->assign(array(
'contacts' => Contact::getContacts($this->context->language->id),
'message' => html_entity_decode(Tools::getValue('message'))
));

$this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl');
}

/**
 * Assign template vars related to order list and product list ordered by the customer
 */
protected function assignOrderList()
{
if ($this->context->customer->isLogged())
{
$this->context->smarty->assign('isLogged'1);

$products = array();
$result Db::getInstance()->executeS('
SELECT id_order
FROM '
._DB_PREFIX_.'orders
WHERE id_customer = '
.(int)$this->context->customer->id.' ORDER BY date_add');
$orders = array();
foreach ($result as $row)
{
$order = new Order($row['id_order']);
$date explode(' '$order->date_add);
$tmp $order->getProducts();
foreach ($tmp as $key => $val)
$products[$row['id_order']][$val['product_id']] = array('value' => $val['product_id'], 'label' => $val['product_name']);
$orders[] = array('value' => $order->id'label' => $order->getUniqReference().' - '.Tools::displayDate($date[0], $this->context->language->id), 'selected' => (int)Tools::getValue('id_order') == $order->id);
}

$this->context->smarty->assign('orderList'$orders);
$this->context->smarty->assign('orderedProductList'$products);
}
}
}

21 Апрель 2013, 12:37:10
Ответ #7
  • Администратор
  • Ветеран
  • *****
  • Сообщений: 102503
  • Репутация: +34219/-0
    • Просмотр профиля
Цитата: mAgency
2. В class ContactController, файл и переменные зависят от версии.
Prestashop 1.5 - /controllers/front/ContactController.php
$mail_var_list = array('{telephone}' => $telephone,....