Упрощенная форма оформления заказа без регистрации

Опубликовано: 13 Фев 2015

В одном из предыдущих уроков мы упрощали форму регистрации. Сегодня поговорим о форме заказа. Я покажу, как сделать упрощенное оформление заказа в OpenCart БЕЗ регистрации.
Что имеется в виду под "упрощенная форма"? Это не заказ в один клик, а оптимизация.

.Делаем резервные копии файлов, которые будут редактированы в данном уроке:

\catalog\view\theme\default\template\checkout\guest.tpl
\catalog\view\theme\default\template\checkout\payment_address.tpl
\catalog\view\theme\default\template\checkout\guest_shipping.tpl
\catalog\controller\checkout\guest.php
\catalog\controller\checkout\payment_address.php
\catalog\controller\checkout\guest_shipping.php
\catalog\controller\checkout\confirm.php
\catalog\model\checkout\order.php

1. Открываем файл:

\catalog\view\theme\default\template\checkout\guest.tpl

удаляем:

<?php echo $entry_fax; ?><br />
<input type="text" name="fax" value="<?php echo $fax; ?>" class="large-field" />
<br />
<br />
<?php echo $entry_company; ?><br />
<input type="text" name="company" value="<?php echo $company; ?>" class="large-field" />
<br />
<br />
<div id="company-id-display"><span id="company-id-required" class="required">*</span> <?php echo $entry_company_id; ?><br />
<input type="text" name="company_id" value="<?php echo $company_id; ?>" class="large-field" />
<br />
<br />
<?php echo $entry_address_2; ?><br />
<input type="text" name="address_2" value="<?php echo $address_2; ?>" class="large-field" />
<br />
<br />
<span id="payment-postcode-required" class="required">*</span> <?php echo $entry_postcode; ?><br />
<input type="text" name="postcode" value="<?php echo $postcode; ?>" class="large-field" />
<br />
<br />

2. Ищем файл:

\catalog\view\theme\default\template\checkout\payment_address.tpl

удаляем:

<tr>
<td><?php echo $entry_company; ?></td>
<td><input type="text" name="company" value="" class="large-field" /></td>
</tr>
<?php if ($company_id_display) { ?>
<tr>
<td><?php if ($company_id_required) { ?>
<span class="required">*</span>
<?php } ?>
<?php echo $entry_company_id; ?></td>
<td><input type="text" name="company_id" value="" class="large-field" /></td>
</tr>
<?php } ?>
<tr>
<td><?php echo $entry_address_2; ?></td>
<td><input type="text" name="address_2" value="" class="large-field" /></td>
</tr>
<tr>
<td><span id="payment-postcode-required" class="required">*</span> <?php echo $entry_postcode; ?></td>
<td><input type="text" name="postcode" value="" class="large-field" /></td>
</tr>

3. Убираем ненужно в:

\catalog\view\theme\default\template\checkout\guest_shipping.tpl

<tr>
<td><?php echo $entry_company; ?></td>
<td><input type="text" name="company" value="<?php echo $company; ?>" class="large-field" /></td>
</tr>
<tr>
<td><?php echo $entry_address_2; ?></td>
<td><input type="text" name="address_2" value="<?php echo $address_2; ?>" class="large-field" /></td>
</tr>
<tr>
<td><span id="shipping-postcode-required" class="required">*</span> <?php echo $entry_postcode; ?></td>
<td><input type="text" name="postcode" value="<?php echo $postcode; ?>" class="large-field" /></td>
</tr>

4. Теперь работаем с файлами php.

Открываем:

\catalog\controller\checkout\guest.php

$this->data['entry_address_2'] = $this->language->get('entry_address_2');
$this->data['entry_postcode'] = $this->language->get('entry_postcode');
$this->data['entry_company'] = $this->language->get('entry_company');
$this->data['entry_company_id'] = $this->language->get('entry_company_id');
$this->data['entry_fax'] = $this->language->get('entry_fax');
if (isset($this->session->data['guest']['fax'])) {
$this->data['fax'] = $this->session->data['guest']['fax'];
} else {
$this->data['fax'] = '';
}
if (isset($this->session->data['guest']['payment']['company'])) {
$this->data['company'] = $this->session->data['guest']['payment']['company'];
} else {
$this->data['company'] = '';
}
if ($country_info) {
if ($country_info['postcode_required'] && (utf8_strlen($this->request->post['postcode']) < 2) || (utf8_strlen($this->request->post['postcode']) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
// VAT Validation
$this->load->helper('vat');
if ($this->config->get('config_vat') && $this->request->post['tax_id'] && (vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid')) {
$json['error']['tax_id'] = $this->language->get('error_vat');
}
}
// Company ID
if (isset($this->session->data['guest']['payment']['company_id'])) {
$this->data['company_id'] = $this->session->data['guest']['payment']['company_id'];
} else {
$this->data['company_id'] = '';
}
if (isset($this->session->data['guest']['payment']['address_2'])) {
$this->data['address_2'] = $this->session->data['guest']['payment']['address_2'];
} else {
$this->data['address_2'] = '';
}
if (isset($this->session->data['guest']['payment']['postcode'])) {
$this->data['postcode'] = $this->session->data['guest']['payment']['postcode'];
} elseif (isset($this->session->data['shipping_postcode'])) {
$this->data['postcode'] = $this->session->data['shipping_postcode'];
} else {
$this->data['postcode'] = '';
}
$this->session->data['guest']['fax'] = $this->request->post['fax'];
$this->session->data['guest']['payment']['company'] = $this->request->post['company'];
$this->session->data['guest']['payment']['company_id'] = $this->request->post['company_id'];
$this->session->data['guest']['payment']['address_2'] = $this->request->post['address_2'];
$this->session->data['guest']['payment']['postcode'] = $this->request->post['postcode'];
$this->session->data['guest']['shipping']['company'] = $this->request->post['company'];
$this->session->data['guest']['shipping']['address_2'] = $this->request->post['address_2'];
$this->session->data['guest']['shipping']['postcode'] = $this->request->post['postcode'];
$this->session->data['shipping_postcode'] = $this->request->post['postcode'];

5. \catalog\controller\checkout\payment_address.php

удаляем ненужное:

$this->data['entry_company'] = $this->language->get('entry_company');
$this->data['entry_company_id'] = $this->language->get('entry_company_id');
$this->data['entry_address_2'] = $this->language->get('entry_address_2');
$this->data['entry_postcode'] = $this->language->get('entry_postcode');

6. \catalog\controller\checkout\guest_shipping.php

чистим мусор:

$this->data['entry_company'] = $this->language->get('entry_company');
$this->data['entry_address_2'] = $this->language->get('entry_address_2');
$this->data['entry_postcode'] = $this->language->get('entry_postcode');
if (isset($this->session->data['guest']['shipping']['company'])) {
$this->data['company'] = $this->session->data['guest']['shipping']['company'];
} else {
$this->data['company'] = '';
}
if (isset($this->session->data['guest']['shipping']['address_2'])) {
$this->data['address_2'] = $this->session->data['guest']['shipping']['address_2'];
} else {
$this->data['address_2'] = '';
}
if (isset($this->session->data['guest']['shipping']['postcode'])) {
$this->data['postcode'] = $this->session->data['guest']['shipping']['postcode'];
} elseif (isset($this->session->data['shipping_postcode'])) {
$this->data['postcode'] = $this->session->data['shipping_postcode'];
} else {
$this->data['postcode'] = '';
}
if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['postcode']) < 2) || (utf8_strlen($this->request->post['postcode']) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
$this->session->data['guest']['shipping']['address_2'] = $this->request->post['address_2'];
$this->session->data['guest']['shipping']['company'] = trim($this->request->post['company']);
$this->session->data['guest']['shipping']['postcode'] = $this->request->post['postcode'];
$this->session->data['shipping_postcode'] = $this->request->post['postcode'];

7. Избавляемся от ненужного в:

\catalog\controller\checkout\confirm.php

$data['fax'] = $this->customer->getFax();
$data['fax'] = $this->session->data['guest']['fax'];
$data['payment_company'] = $payment_address['company'];
$data['payment_company_id'] = $payment_address['company_id'];
$data['payment_address_2'] = $payment_address['address_2'];
$data['payment_postcode'] = $payment_address['postcode'];
$data['shipping_company'] = $shipping_address['company'];
$data['shipping_address_2'] = $shipping_address['address_2'];
$data['shipping_postcode'] = $shipping_address['postcode'];
$data['shipping_company'] = '';
$data['shipping_address_2'] = '';
$data['shipping_postcode'] = '';

8. В этом файле будьте внимательны!!!

\catalog\model\checkout\order.php

на 4 строке (!!!) удалить:

"', fax = '" . $this->db->escape($data['fax']) .
"', payment_company = '" . $this->db->escape($data['payment_company']) .
"', payment_company_id = '" . $this->db->escape($data['payment_company_id']) .
"', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) .
"', payment_postcode = '" . $this->db->escape($data['payment_postcode']) .
"', shipping_company = '" . $this->db->escape($data['shipping_company']) .
"', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) .
"', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) .

Обратите внимание на структуру кода! Масив начинается с "',  и заканчивается:  . ! Смотрите что удаляете. В противном случае получите ошибку sql.

Комментарии (0)


Оставить комментарий




Разрешённые теги: <b><i><br>Добавить новый комментарий: