first commit

This commit is contained in:
Konstantin
2026-05-30 09:27:58 +03:00
commit de0344d218
2371 changed files with 661486 additions and 0 deletions
+482
View File
@@ -0,0 +1,482 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutCart extends Controller {
public function index() {
$this->load->language('checkout/cart');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->setRobots('noindex,follow');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'href' => $this->url->link('common/home'),
'text' => $this->language->get('text_home')
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('checkout/cart'),
'text' => $this->language->get('heading_title')
);
if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
if (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
$data['error_warning'] = $this->language->get('error_stock');
} elseif (isset($this->session->data['error'])) {
$data['error_warning'] = $this->session->data['error'];
unset($this->session->data['error']);
} else {
$data['error_warning'] = '';
}
if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) {
$data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register'));
} else {
$data['attention'] = '';
}
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
$data['action'] = $this->url->link('checkout/cart/edit', '', true);
if ($this->config->get('config_cart_weight')) {
$data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'));
} else {
$data['weight'] = '';
}
$this->load->model('tool/image');
$this->load->model('tool/upload');
$data['products'] = array();
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
}
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));
} else {
$image = '';
}
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
$price = $this->currency->format($unit_price, $this->session->data['currency']);
$total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
} else {
$price = false;
$total = false;
}
$recurring = '';
if ($product['recurring']) {
$frequencies = array(
'day' => $this->language->get('text_day'),
'week' => $this->language->get('text_week'),
'semi_month' => $this->language->get('text_semi_month'),
'month' => $this->language->get('text_month'),
'year' => $this->language->get('text_year')
);
if ($product['recurring']['trial']) {
$recurring = sprintf($this->language->get('text_trial_description'), $this->currency->format($this->tax->calculate($product['recurring']['trial_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['trial_cycle'], $frequencies[$product['recurring']['trial_frequency']], $product['recurring']['trial_duration']) . ' ';
}
if ($product['recurring']['duration']) {
$recurring .= sprintf($this->language->get('text_payment_description'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
} else {
$recurring .= sprintf($this->language->get('text_payment_cancel'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
}
}
$data['products'][] = array(
'cart_id' => $product['cart_id'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => $recurring,
'quantity' => $product['quantity'],
'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
'reward' => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
'price' => $price,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
}
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency']),
'remove' => $this->url->link('checkout/cart', 'remove=' . $key)
);
}
}
// Totals
$this->load->model('setting/extension');
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array(
'totals' => &$totals,
'taxes' => &$taxes,
'total' => &$total
);
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_setting_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get('total_' . $result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
$sort_order = array();
foreach ($totals as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $totals);
}
$data['totals'] = array();
foreach ($totals as $total) {
$data['totals'][] = array(
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $this->session->data['currency'])
);
}
$data['continue'] = $this->url->link('common/home');
$data['checkout'] = $this->url->link('checkout/checkout', '', true);
$this->load->model('setting/extension');
$data['modules'] = array();
$files = glob(DIR_APPLICATION . '/controller/extension/total/*.php');
if ($files) {
foreach ($files as $file) {
$result = $this->load->controller('extension/total/' . basename($file, '.php'));
if ($result) {
$data['modules'][] = $result;
}
}
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('checkout/cart', $data));
} else {
$data['text_error'] = $this->language->get('text_empty');
$data['continue'] = $this->url->link('common/home');
unset($this->session->data['success']);
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('error/not_found', $data));
}
}
public function add() {
$this->load->language('checkout/cart');
$json = array();
if (isset($this->request->post['product_id'])) {
$product_id = (int)$this->request->post['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if (isset($this->request->post['quantity'])) {
$quantity = (int)$this->request->post['quantity'];
} else {
$quantity = 1;
}
if (isset($this->request->post['option'])) {
$option = array_filter($this->request->post['option']);
} else {
$option = array();
}
$product_options = $this->model_catalog_product->getProductOptions($this->request->post['product_id']);
foreach ($product_options as $product_option) {
if ($product_option['required'] && empty($option[$product_option['product_option_id']])) {
$json['error']['option'][$product_option['product_option_id']] = sprintf($this->language->get('error_required'), $product_option['name']);
}
}
if (isset($this->request->post['recurring_id'])) {
$recurring_id = $this->request->post['recurring_id'];
} else {
$recurring_id = 0;
}
$recurrings = $this->model_catalog_product->getProfiles($product_info['product_id']);
if ($recurrings) {
$recurring_ids = array();
foreach ($recurrings as $recurring) {
$recurring_ids[] = $recurring['recurring_id'];
}
if (!in_array($recurring_id, $recurring_ids)) {
$json['error']['recurring'] = $this->language->get('error_recurring_required');
}
}
if (!$json) {
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
// Unset all shipping and payment methods
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
// Totals
$this->load->model('setting/extension');
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array(
'totals' => &$totals,
'taxes' => &$taxes,
'total' => &$total
);
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_setting_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get('total_' . $result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
$sort_order = array();
foreach ($totals as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $totals);
}
$json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));
} else {
$json['redirect'] = str_replace('&amp;', '&', $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']));
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function edit() {
$this->load->language('checkout/cart');
$json = array();
// Update
if (!empty($this->request->post['quantity'])) {
foreach ($this->request->post['quantity'] as $key => $value) {
$this->cart->update($key, $value);
}
$this->session->data['success'] = $this->language->get('text_remove');
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
$this->response->redirect($this->url->link('checkout/cart'));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function remove() {
$this->load->language('checkout/cart');
$json = array();
// Remove
if (isset($this->request->post['key'])) {
$this->cart->remove($this->request->post['key']);
unset($this->session->data['vouchers'][$this->request->post['key']]);
$json['success'] = $this->language->get('text_remove');
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
// Totals
$this->load->model('setting/extension');
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array(
'totals' => &$totals,
'taxes' => &$taxes,
'total' => &$total
);
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_setting_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get('total_' . $result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
$sort_order = array();
foreach ($totals as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $totals);
}
$json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,152 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutCheckout extends Controller {
public function index() {
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->response->redirect($this->url->link('checkout/cart'));
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$this->response->redirect($this->url->link('checkout/cart'));
}
}
$this->load->language('checkout/checkout');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->setRobots('noindex,follow');
$this->document->addScript('store/view/javascript/jquery/datetimepicker/moment/moment.min.js');
$this->document->addScript('store/view/javascript/jquery/datetimepicker/moment/moment-with-locales.min.js');
$this->document->addScript('store/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('store/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
// Required by klarna
if ($this->config->get('payment_klarna_account') || $this->config->get('payment_klarna_invoice')) {
$this->document->addScript('http://cdn.klarna.com/public/kitt/toc/v1.0/js/klarna.terms.min.js');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_cart'),
'href' => $this->url->link('checkout/cart')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('checkout/checkout', '', true)
);
$data['text_checkout_option'] = sprintf($this->language->get('text_checkout_option'), 1);
$data['text_checkout_account'] = sprintf($this->language->get('text_checkout_account'), 2);
$data['text_checkout_payment_address'] = sprintf($this->language->get('text_checkout_payment_address'), 2);
$data['text_checkout_shipping_address'] = sprintf($this->language->get('text_checkout_shipping_address'), 3);
$data['text_checkout_shipping_method'] = sprintf($this->language->get('text_checkout_shipping_method'), 4);
if ($this->cart->hasShipping()) {
$data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 5);
$data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 6);
} else {
$data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 3);
$data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 4);
}
if (isset($this->session->data['error'])) {
$data['error_warning'] = $this->session->data['error'];
unset($this->session->data['error']);
} else {
$data['error_warning'] = '';
}
$data['logged'] = $this->customer->isLogged();
if (isset($this->session->data['account'])) {
$data['account'] = $this->session->data['account'];
} else {
$data['account'] = '';
}
$data['shipping_required'] = $this->cart->hasShipping();
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('checkout/checkout', $data));
}
public function country() {
$json = array();
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
if ($country_info) {
$this->load->model('localisation/zone');
$json = array(
'country_id' => $country_info['country_id'],
'name' => $country_info['name'],
'iso_code_2' => $country_info['iso_code_2'],
'iso_code_3' => $country_info['iso_code_3'],
'address_format' => $country_info['address_format'],
'postcode_required' => $country_info['postcode_required'],
'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
'status' => $country_info['status']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function customfield() {
$json = array();
$this->load->model('account/custom_field');
// Customer Group
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,420 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutConfirm extends Controller {
public function index() {
$redirect = '';
if ($this->cart->hasShipping()) {
// Validate if shipping address has been set.
if (!isset($this->session->data['shipping_address'])) {
$redirect = $this->url->link('checkout/checkout', '', true);
}
// Validate if shipping method has been set.
if (!isset($this->session->data['shipping_method'])) {
$redirect = $this->url->link('checkout/checkout', '', true);
}
} else {
unset($this->session->data['shipping_address']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
}
// Validate if payment address has been set.
if (!isset($this->session->data['payment_address'])) {
$redirect = $this->url->link('checkout/checkout', '', true);
}
// Validate if payment method has been set.
if (!isset($this->session->data['payment_method'])) {
$redirect = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$redirect = $this->url->link('checkout/cart');
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$redirect = $this->url->link('checkout/cart');
break;
}
}
if (!$redirect) {
$order_data = array();
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array(
'totals' => &$totals,
'taxes' => &$taxes,
'total' => &$total
);
$this->load->model('setting/extension');
$sort_order = array();
$results = $this->model_setting_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get('total_' . $result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
$sort_order = array();
foreach ($totals as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $totals);
$order_data['totals'] = $totals;
$this->load->language('checkout/checkout');
$order_data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
$order_data['store_id'] = $this->config->get('config_store_id');
$order_data['store_name'] = $this->config->get('config_name');
if ($order_data['store_id']) {
$order_data['store_url'] = $this->config->get('config_url');
} else {
if ($this->request->server['HTTPS']) {
$order_data['store_url'] = HTTPS_SERVER;
} else {
$order_data['store_url'] = HTTP_SERVER;
}
}
$this->load->model('account/customer');
if ($this->customer->isLogged()) {
$customer_info = $this->model_account_customer->getCustomer($this->customer->getId());
$order_data['customer_id'] = $this->customer->getId();
$order_data['customer_group_id'] = $customer_info['customer_group_id'];
$order_data['firstname'] = $customer_info['firstname'];
$order_data['lastname'] = $customer_info['lastname'];
$order_data['email'] = $customer_info['email'];
$order_data['telephone'] = $customer_info['telephone'];
$order_data['custom_field'] = json_decode($customer_info['custom_field'], true);
} elseif (isset($this->session->data['guest'])) {
$order_data['customer_id'] = 0;
$order_data['customer_group_id'] = $this->session->data['guest']['customer_group_id'];
$order_data['firstname'] = $this->session->data['guest']['firstname'];
$order_data['lastname'] = $this->session->data['guest']['lastname'];
$order_data['email'] = $this->session->data['guest']['email'];
$order_data['telephone'] = $this->session->data['guest']['telephone'];
$order_data['custom_field'] = $this->session->data['guest']['custom_field'];
}
$order_data['payment_firstname'] = $this->session->data['payment_address']['firstname'];
$order_data['payment_lastname'] = $this->session->data['payment_address']['lastname'];
$order_data['payment_company'] = $this->session->data['payment_address']['company'];
$order_data['payment_address_1'] = $this->session->data['payment_address']['address_1'];
$order_data['payment_address_2'] = $this->session->data['payment_address']['address_2'];
$order_data['payment_city'] = $this->session->data['payment_address']['city'];
$order_data['payment_postcode'] = $this->session->data['payment_address']['postcode'];
$order_data['payment_zone'] = $this->session->data['payment_address']['zone'];
$order_data['payment_zone_id'] = $this->session->data['payment_address']['zone_id'];
$order_data['payment_country'] = $this->session->data['payment_address']['country'];
$order_data['payment_country_id'] = $this->session->data['payment_address']['country_id'];
$order_data['payment_address_format'] = $this->session->data['payment_address']['address_format'];
$order_data['payment_custom_field'] = (isset($this->session->data['payment_address']['custom_field']) ? $this->session->data['payment_address']['custom_field'] : array());
if (isset($this->session->data['payment_method']['title'])) {
$order_data['payment_method'] = $this->session->data['payment_method']['title'];
} else {
$order_data['payment_method'] = '';
}
if (isset($this->session->data['payment_method']['code'])) {
$order_data['payment_code'] = $this->session->data['payment_method']['code'];
} else {
$order_data['payment_code'] = '';
}
if ($this->cart->hasShipping()) {
$order_data['shipping_firstname'] = $this->session->data['shipping_address']['firstname'];
$order_data['shipping_lastname'] = $this->session->data['shipping_address']['lastname'];
$order_data['shipping_company'] = $this->session->data['shipping_address']['company'];
$order_data['shipping_address_1'] = $this->session->data['shipping_address']['address_1'];
$order_data['shipping_address_2'] = $this->session->data['shipping_address']['address_2'];
$order_data['shipping_city'] = $this->session->data['shipping_address']['city'];
$order_data['shipping_postcode'] = $this->session->data['shipping_address']['postcode'];
$order_data['shipping_zone'] = $this->session->data['shipping_address']['zone'];
$order_data['shipping_zone_id'] = $this->session->data['shipping_address']['zone_id'];
$order_data['shipping_country'] = $this->session->data['shipping_address']['country'];
$order_data['shipping_country_id'] = $this->session->data['shipping_address']['country_id'];
$order_data['shipping_address_format'] = $this->session->data['shipping_address']['address_format'];
$order_data['shipping_custom_field'] = (isset($this->session->data['shipping_address']['custom_field']) ? $this->session->data['shipping_address']['custom_field'] : array());
if (isset($this->session->data['shipping_method']['title'])) {
$order_data['shipping_method'] = $this->session->data['shipping_method']['title'];
} else {
$order_data['shipping_method'] = '';
}
if (isset($this->session->data['shipping_method']['code'])) {
$order_data['shipping_code'] = $this->session->data['shipping_method']['code'];
} else {
$order_data['shipping_code'] = '';
}
} else {
$order_data['shipping_firstname'] = '';
$order_data['shipping_lastname'] = '';
$order_data['shipping_company'] = '';
$order_data['shipping_address_1'] = '';
$order_data['shipping_address_2'] = '';
$order_data['shipping_city'] = '';
$order_data['shipping_postcode'] = '';
$order_data['shipping_zone'] = '';
$order_data['shipping_zone_id'] = '';
$order_data['shipping_country'] = '';
$order_data['shipping_country_id'] = '';
$order_data['shipping_address_format'] = '';
$order_data['shipping_custom_field'] = array();
$order_data['shipping_method'] = '';
$order_data['shipping_code'] = '';
}
$order_data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
$option_data[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value_id' => $option['product_option_value_id'],
'option_id' => $option['option_id'],
'option_value_id' => $option['option_value_id'],
'name' => $option['name'],
'value' => $option['value'],
'type' => $option['type']
);
}
$order_data['products'][] = array(
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'download' => $product['download'],
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $product['price'],
'total' => $product['total'],
'tax' => $this->tax->getTax($product['price'], $product['tax_class_id']),
'reward' => $product['reward']
);
}
// Gift Voucher
$order_data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $voucher) {
$order_data['vouchers'][] = array(
'description' => $voucher['description'],
'code' => token(10),
'to_name' => $voucher['to_name'],
'to_email' => $voucher['to_email'],
'from_name' => $voucher['from_name'],
'from_email' => $voucher['from_email'],
'voucher_theme_id' => $voucher['voucher_theme_id'],
'message' => $voucher['message'],
'amount' => $voucher['amount']
);
}
}
$order_data['comment'] = $this->session->data['comment'];
$order_data['total'] = $total_data['total'];
if (isset($this->request->cookie['tracking'])) {
$order_data['tracking'] = $this->request->cookie['tracking'];
$subtotal = $this->cart->getSubTotal();
// Affiliate
$affiliate_info = $this->model_account_customer->getAffiliateByTracking($this->request->cookie['tracking']);
if ($affiliate_info) {
$order_data['affiliate_id'] = $affiliate_info['customer_id'];
$order_data['commission'] = ($subtotal / 100) * $affiliate_info['commission'];
} else {
$order_data['affiliate_id'] = 0;
$order_data['commission'] = 0;
}
// Marketing
$this->load->model('checkout/marketing');
$marketing_info = $this->model_checkout_marketing->getMarketingByCode($this->request->cookie['tracking']);
if ($marketing_info) {
$order_data['marketing_id'] = $marketing_info['marketing_id'];
} else {
$order_data['marketing_id'] = 0;
}
} else {
$order_data['affiliate_id'] = 0;
$order_data['commission'] = 0;
$order_data['marketing_id'] = 0;
$order_data['tracking'] = '';
}
$order_data['language_id'] = $this->config->get('config_language_id');
$order_data['currency_id'] = $this->currency->getId($this->session->data['currency']);
$order_data['currency_code'] = $this->session->data['currency'];
$order_data['currency_value'] = $this->currency->getValue($this->session->data['currency']);
$order_data['ip'] = $this->request->server['REMOTE_ADDR'];
if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) {
$order_data['forwarded_ip'] = $this->request->server['HTTP_X_FORWARDED_FOR'];
} elseif (!empty($this->request->server['HTTP_CLIENT_IP'])) {
$order_data['forwarded_ip'] = $this->request->server['HTTP_CLIENT_IP'];
} else {
$order_data['forwarded_ip'] = '';
}
if (isset($this->request->server['HTTP_USER_AGENT'])) {
$order_data['user_agent'] = $this->request->server['HTTP_USER_AGENT'];
} else {
$order_data['user_agent'] = '';
}
if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) {
$order_data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE'];
} else {
$order_data['accept_language'] = '';
}
$this->load->model('checkout/order');
$this->session->data['order_id'] = $this->model_checkout_order->addOrder($order_data);
$this->load->model('tool/upload');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
$recurring = '';
if ($product['recurring']) {
$frequencies = array(
'day' => $this->language->get('text_day'),
'week' => $this->language->get('text_week'),
'semi_month' => $this->language->get('text_semi_month'),
'month' => $this->language->get('text_month'),
'year' => $this->language->get('text_year'),
);
if ($product['recurring']['trial']) {
$recurring = sprintf($this->language->get('text_trial_description'), $this->currency->format($this->tax->calculate($product['recurring']['trial_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['trial_cycle'], $frequencies[$product['recurring']['trial_frequency']], $product['recurring']['trial_duration']) . ' ';
}
if ($product['recurring']['duration']) {
$recurring .= sprintf($this->language->get('text_payment_description'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
} else {
$recurring .= sprintf($this->language->get('text_payment_cancel'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
}
}
$data['products'][] = array(
'cart_id' => $product['cart_id'],
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => $recurring,
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']),
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
}
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $voucher) {
$data['vouchers'][] = array(
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency'])
);
}
}
$data['totals'] = array();
foreach ($order_data['totals'] as $total) {
$data['totals'][] = array(
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $this->session->data['currency'])
);
}
$data['payment'] = $this->load->controller('extension/payment/' . $this->session->data['payment_method']['code']);
} else {
$data['redirect'] = $redirect;
}
$this->response->setOutput($this->load->view('checkout/confirm', $data));
}
}
@@ -0,0 +1,47 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutFailure extends Controller {
public function index() {
$this->load->language('checkout/failure');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->setRobots('noindex,follow');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_basket'),
'href' => $this->url->link('checkout/cart')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_checkout'),
'href' => $this->url->link('checkout/checkout', '', true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_failure'),
'href' => $this->url->link('checkout/failure')
);
$data['text_message'] = sprintf($this->language->get('text_message'), $this->url->link('information/contact'));
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('common/success', $data));
}
}
+350
View File
@@ -0,0 +1,350 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutGuest extends Controller {
public function index() {
$this->load->language('checkout/checkout');
$data['customer_groups'] = array();
if (is_array($this->config->get('config_customer_group_display'))) {
$this->load->model('account/customer_group');
$customer_groups = $this->model_account_customer_group->getCustomerGroups();
foreach ($customer_groups as $customer_group) {
if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$data['customer_groups'][] = $customer_group;
}
}
}
if (isset($this->session->data['guest']['customer_group_id'])) {
$data['customer_group_id'] = $this->session->data['guest']['customer_group_id'];
} else {
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
if (isset($this->session->data['guest']['firstname'])) {
$data['firstname'] = $this->session->data['guest']['firstname'];
} else {
$data['firstname'] = '';
}
if (isset($this->session->data['guest']['lastname'])) {
$data['lastname'] = $this->session->data['guest']['lastname'];
} else {
$data['lastname'] = '';
}
if (isset($this->session->data['guest']['email'])) {
$data['email'] = $this->session->data['guest']['email'];
} else {
$data['email'] = '';
}
if (isset($this->session->data['guest']['telephone'])) {
$data['telephone'] = $this->session->data['guest']['telephone'];
} else {
$data['telephone'] = '';
}
if (isset($this->session->data['payment_address']['company'])) {
$data['company'] = $this->session->data['payment_address']['company'];
} else {
$data['company'] = '';
}
if (isset($this->session->data['payment_address']['address_1'])) {
$data['address_1'] = $this->session->data['payment_address']['address_1'];
} else {
$data['address_1'] = '';
}
if (isset($this->session->data['payment_address']['address_2'])) {
$data['address_2'] = $this->session->data['payment_address']['address_2'];
} else {
$data['address_2'] = '';
}
if (isset($this->session->data['payment_address']['postcode'])) {
$data['postcode'] = $this->session->data['payment_address']['postcode'];
} elseif (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->session->data['payment_address']['city'])) {
$data['city'] = $this->session->data['payment_address']['city'];
} else {
$data['city'] = '';
}
if (isset($this->session->data['payment_address']['country_id'])) {
$data['country_id'] = $this->session->data['payment_address']['country_id'];
} elseif (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->session->data['payment_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['payment_address']['zone_id'];
} elseif (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
if (isset($this->session->data['guest']['custom_field'])) {
if (isset($this->session->data['guest']['custom_field'])) {
$guest_custom_field = $this->session->data['guest']['custom_field'];
} else {
$guest_custom_field = array();
}
if (isset($this->session->data['payment_address']['custom_field'])) {
$address_custom_field = $this->session->data['payment_address']['custom_field'];
} else {
$address_custom_field = array();
}
$data['guest_custom_field'] = $guest_custom_field + $address_custom_field;
} else {
$data['guest_custom_field'] = array();
}
$data['shipping_required'] = $this->cart->hasShipping();
if (isset($this->session->data['guest']['shipping_address'])) {
$data['shipping_address'] = $this->session->data['guest']['shipping_address'];
} else {
$data['shipping_address'] = true;
}
// Captcha
if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('guest', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'));
} else {
$data['captcha'] = '';
}
$this->response->setOutput($this->load->view('checkout/guest', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
// Validate if customer is logged in.
if ($this->customer->isLogged()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
// Check if guest checkout is available.
if (!$this->config->get('config_checkout_guest') || $this->config->get('config_customer_price') || $this->cart->hasDownload()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
if (!$json) {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
$json['error']['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$json['error']['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$json['error']['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$json['error']['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$json['error']['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) {
$json['error']['zone'] = $this->language->get('error_zone');
}
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
// Captcha
if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('guest', (array)$this->config->get('config_captcha_page'))) {
$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');
if ($captcha) {
$json['error']['captcha'] = $captcha;
}
}
}
if (!$json) {
$this->session->data['account'] = 'guest';
$this->session->data['guest']['customer_group_id'] = $customer_group_id;
$this->session->data['guest']['firstname'] = $this->request->post['firstname'];
$this->session->data['guest']['lastname'] = $this->request->post['lastname'];
$this->session->data['guest']['email'] = $this->request->post['email'];
$this->session->data['guest']['telephone'] = $this->request->post['telephone'];
if (isset($this->request->post['custom_field']['account'])) {
$this->session->data['guest']['custom_field'] = $this->request->post['custom_field']['account'];
} else {
$this->session->data['guest']['custom_field'] = array();
}
$this->session->data['payment_address']['firstname'] = $this->request->post['firstname'];
$this->session->data['payment_address']['lastname'] = $this->request->post['lastname'];
$this->session->data['payment_address']['company'] = $this->request->post['company'];
$this->session->data['payment_address']['address_1'] = $this->request->post['address_1'];
$this->session->data['payment_address']['address_2'] = $this->request->post['address_2'];
$this->session->data['payment_address']['postcode'] = $this->request->post['postcode'];
$this->session->data['payment_address']['city'] = $this->request->post['city'];
$this->session->data['payment_address']['country_id'] = $this->request->post['country_id'];
$this->session->data['payment_address']['zone_id'] = $this->request->post['zone_id'];
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info) {
$this->session->data['payment_address']['country'] = $country_info['name'];
$this->session->data['payment_address']['iso_code_2'] = $country_info['iso_code_2'];
$this->session->data['payment_address']['iso_code_3'] = $country_info['iso_code_3'];
$this->session->data['payment_address']['address_format'] = $country_info['address_format'];
} else {
$this->session->data['payment_address']['country'] = '';
$this->session->data['payment_address']['iso_code_2'] = '';
$this->session->data['payment_address']['iso_code_3'] = '';
$this->session->data['payment_address']['address_format'] = '';
}
if (isset($this->request->post['custom_field']['address'])) {
$this->session->data['payment_address']['custom_field'] = $this->request->post['custom_field']['address'];
} else {
$this->session->data['payment_address']['custom_field'] = array();
}
$this->load->model('localisation/zone');
$zone_info = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
if ($zone_info) {
$this->session->data['payment_address']['zone'] = $zone_info['name'];
$this->session->data['payment_address']['zone_code'] = $zone_info['code'];
} else {
$this->session->data['payment_address']['zone'] = '';
$this->session->data['payment_address']['zone_code'] = '';
}
if (!empty($this->request->post['shipping_address'])) {
$this->session->data['guest']['shipping_address'] = $this->request->post['shipping_address'];
} else {
$this->session->data['guest']['shipping_address'] = false;
}
if ($this->session->data['guest']['shipping_address']) {
$this->session->data['shipping_address']['firstname'] = $this->request->post['firstname'];
$this->session->data['shipping_address']['lastname'] = $this->request->post['lastname'];
$this->session->data['shipping_address']['company'] = $this->request->post['company'];
$this->session->data['shipping_address']['address_1'] = $this->request->post['address_1'];
$this->session->data['shipping_address']['address_2'] = $this->request->post['address_2'];
$this->session->data['shipping_address']['postcode'] = $this->request->post['postcode'];
$this->session->data['shipping_address']['city'] = $this->request->post['city'];
$this->session->data['shipping_address']['country_id'] = $this->request->post['country_id'];
$this->session->data['shipping_address']['zone_id'] = $this->request->post['zone_id'];
if ($country_info) {
$this->session->data['shipping_address']['country'] = $country_info['name'];
$this->session->data['shipping_address']['iso_code_2'] = $country_info['iso_code_2'];
$this->session->data['shipping_address']['iso_code_3'] = $country_info['iso_code_3'];
$this->session->data['shipping_address']['address_format'] = $country_info['address_format'];
} else {
$this->session->data['shipping_address']['country'] = '';
$this->session->data['shipping_address']['iso_code_2'] = '';
$this->session->data['shipping_address']['iso_code_3'] = '';
$this->session->data['shipping_address']['address_format'] = '';
}
if ($zone_info) {
$this->session->data['shipping_address']['zone'] = $zone_info['name'];
$this->session->data['shipping_address']['zone_code'] = $zone_info['code'];
} else {
$this->session->data['shipping_address']['zone'] = '';
$this->session->data['shipping_address']['zone_code'] = '';
}
if (isset($this->request->post['custom_field']['address'])) {
$this->session->data['shipping_address']['custom_field'] = $this->request->post['custom_field']['address'];
} else {
$this->session->data['shipping_address']['custom_field'] = array();
}
}
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,208 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutGuestShipping extends Controller {
public function index() {
$this->load->language('checkout/checkout');
if (isset($this->session->data['shipping_address']['firstname'])) {
$data['firstname'] = $this->session->data['shipping_address']['firstname'];
} else {
$data['firstname'] = '';
}
if (isset($this->session->data['shipping_address']['lastname'])) {
$data['lastname'] = $this->session->data['shipping_address']['lastname'];
} else {
$data['lastname'] = '';
}
if (isset($this->session->data['shipping_address']['company'])) {
$data['company'] = $this->session->data['shipping_address']['company'];
} else {
$data['company'] = '';
}
if (isset($this->session->data['shipping_address']['address_1'])) {
$data['address_1'] = $this->session->data['shipping_address']['address_1'];
} else {
$data['address_1'] = '';
}
if (isset($this->session->data['shipping_address']['address_2'])) {
$data['address_2'] = $this->session->data['shipping_address']['address_2'];
} else {
$data['address_2'] = '';
}
if (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->session->data['shipping_address']['city'])) {
$data['city'] = $this->session->data['shipping_address']['city'];
} else {
$data['city'] = '';
}
if (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($this->session->data['guest']['customer_group_id']);
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
$data['custom_fields'][] = $custom_field;
}
}
if (isset($this->session->data['shipping_address']['custom_field'])) {
$data['address_custom_field'] = $this->session->data['shipping_address']['custom_field'];
} else {
$data['address_custom_field'] = array();
}
$this->response->setOutput($this->load->view('checkout/guest_shipping', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
// Validate if customer is logged in.
if ($this->customer->isLogged()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
// Check if guest checkout is available.
if (!$this->config->get('config_checkout_guest') || $this->config->get('config_customer_price') || $this->cart->hasDownload()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
if (!$json) {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$json['error']['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$json['error']['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$json['error']['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) {
$json['error']['zone'] = $this->language->get('error_zone');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($this->session->data['guest']['customer_group_id']);
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
}
}
if (!$json) {
$this->session->data['shipping_address']['firstname'] = $this->request->post['firstname'];
$this->session->data['shipping_address']['lastname'] = $this->request->post['lastname'];
$this->session->data['shipping_address']['company'] = $this->request->post['company'];
$this->session->data['shipping_address']['address_1'] = $this->request->post['address_1'];
$this->session->data['shipping_address']['address_2'] = $this->request->post['address_2'];
$this->session->data['shipping_address']['postcode'] = $this->request->post['postcode'];
$this->session->data['shipping_address']['city'] = $this->request->post['city'];
$this->session->data['shipping_address']['country_id'] = $this->request->post['country_id'];
$this->session->data['shipping_address']['zone_id'] = $this->request->post['zone_id'];
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info) {
$this->session->data['shipping_address']['country'] = $country_info['name'];
$this->session->data['shipping_address']['iso_code_2'] = $country_info['iso_code_2'];
$this->session->data['shipping_address']['iso_code_3'] = $country_info['iso_code_3'];
$this->session->data['shipping_address']['address_format'] = $country_info['address_format'];
} else {
$this->session->data['shipping_address']['country'] = '';
$this->session->data['shipping_address']['iso_code_2'] = '';
$this->session->data['shipping_address']['iso_code_3'] = '';
$this->session->data['shipping_address']['address_format'] = '';
}
$this->load->model('localisation/zone');
$zone_info = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
if ($zone_info) {
$this->session->data['shipping_address']['zone'] = $zone_info['name'];
$this->session->data['shipping_address']['zone_code'] = $zone_info['code'];
} else {
$this->session->data['shipping_address']['zone'] = '';
$this->session->data['shipping_address']['zone_code'] = '';
}
if (isset($this->request->post['custom_field'])) {
$this->session->data['shipping_address']['custom_field'] = $this->request->post['custom_field']['address'];
} else {
$this->session->data['shipping_address']['custom_field'] = array();
}
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,95 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutLogin extends Controller {
public function index() {
$this->load->language('checkout/checkout');
$data['checkout_guest'] = ($this->config->get('config_checkout_guest') && !$this->config->get('config_customer_price') && !$this->cart->hasDownload());
if (isset($this->session->data['account'])) {
$data['account'] = $this->session->data['account'];
} else {
$data['account'] = 'register';
}
$data['forgotten'] = $this->url->link('account/forgotten', '', true);
$this->response->setOutput($this->load->view('checkout/login', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
if ($this->customer->isLogged()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
if (!$json) {
$this->load->model('account/customer');
// Check how many login attempts have been made.
$login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
if ($login_info && ($login_info['total'] >= $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
$json['error']['warning'] = $this->language->get('error_attempts');
}
// Check if customer has been approved.
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
if ($customer_info && !$customer_info['status']) {
$json['error']['warning'] = $this->language->get('error_approved');
}
if (!isset($json['error'])) {
if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
$json['error']['warning'] = $this->language->get('error_login');
$this->model_account_customer->addLoginAttempt($this->request->post['email']);
} else {
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
}
}
}
if (!$json) {
// Unset guest
unset($this->session->data['guest']);
// Default Shipping Address
$this->load->model('account/address');
if ($this->config->get('config_tax_customer') == 'payment') {
$this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
}
if ($this->config->get('config_tax_customer') == 'shipping') {
$this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
}
// Wishlist
if (isset($this->session->data['wishlist']) && is_array($this->session->data['wishlist'])) {
$this->load->model('account/wishlist');
foreach ($this->session->data['wishlist'] as $key => $product_id) {
$this->model_account_wishlist->addWishlist($product_id);
unset($this->session->data['wishlist'][$key]);
}
}
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,176 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutPaymentAddress extends Controller {
public function index() {
$this->load->language('checkout/checkout');
if (isset($this->session->data['payment_address']['address_id'])) {
$data['address_id'] = $this->session->data['payment_address']['address_id'];
} else {
$data['address_id'] = $this->customer->getAddressId();
}
$this->load->model('account/address');
$data['addresses'] = $this->model_account_address->getAddresses();
if (isset($this->session->data['payment_address']['country_id'])) {
$data['country_id'] = $this->session->data['payment_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->session->data['payment_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['payment_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$data['custom_fields'] = array();
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
$data['custom_fields'][] = $custom_field;
}
}
if (isset($this->session->data['payment_address']['custom_field'])) {
$data['payment_address_custom_field'] = $this->session->data['payment_address']['custom_field'];
} else {
$data['payment_address_custom_field'] = array();
}
$this->response->setOutput($this->load->view('checkout/payment_address', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
// Validate if customer is logged in.
if (!$this->customer->isLogged()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$json['redirect'] = $this->url->link('checkout/cart');
break;
}
}
if (!$json) {
$this->load->model('account/address');
if (isset($this->request->post['payment_address']) && $this->request->post['payment_address'] == 'existing') {
if (empty($this->request->post['address_id'])) {
$json['error']['warning'] = $this->language->get('error_address');
} elseif (!in_array($this->request->post['address_id'], array_keys($this->model_account_address->getAddresses()))) {
$json['error']['warning'] = $this->language->get('error_address');
}
if (!$json) {
$this->session->data['payment_address'] = $this->model_account_address->getAddress($this->request->post['address_id']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
}
} else {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$json['error']['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen($this->request->post['city']) < 2) || (utf8_strlen($this->request->post['city']) > 32)) {
$json['error']['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$json['error']['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) {
$json['error']['zone'] = $this->language->get('error_zone');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
}
if (!$json) {
$address_id = $this->model_account_address->addAddress($this->customer->getId(), $this->request->post);
$this->session->data['payment_address'] = $this->model_account_address->getAddress($address_id);
// If no default address ID set we use the last address
if (!$this->customer->getAddressId()) {
$this->load->model('account/customer');
$this->model_account_customer->editAddressId($this->customer->getId(), $address_id);
}
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
}
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,193 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutPaymentMethod extends Controller {
public function index() {
$this->load->language('checkout/checkout');
if (isset($this->session->data['payment_address'])) {
// Totals
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array(
'totals' => &$totals,
'taxes' => &$taxes,
'total' => &$total
);
$this->load->model('setting/extension');
$sort_order = array();
$results = $this->model_setting_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get('total_' . $result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
// Payment Methods
$method_data = array();
$this->load->model('setting/extension');
$results = $this->model_setting_extension->getExtensions('payment');
$recurring = $this->cart->hasRecurringProducts();
foreach ($results as $result) {
if ($this->config->get('payment_' . $result['code'] . '_status')) {
if (!is_file(DIR_APPLICATION . 'model/extension/payment/' . $result['code'] . '.php')) {
continue;
}
$this->load->model('extension/payment/' . $result['code']);
$method = $this->{'model_extension_payment_' . $result['code']}->getMethod($this->session->data['payment_address'], $total);
if ($method) {
if ($recurring) {
if (property_exists($this->{'model_extension_payment_' . $result['code']}, 'recurringPayments') && $this->{'model_extension_payment_' . $result['code']}->recurringPayments()) {
$method_data[$result['code']] = $method;
}
} else {
$method_data[$result['code']] = $method;
}
}
}
}
$sort_order = array();
foreach ($method_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $method_data);
$this->session->data['payment_methods'] = $method_data;
}
if (empty($this->session->data['payment_methods'])) {
$data['error_warning'] = sprintf($this->language->get('error_no_payment'), $this->url->link('information/contact'));
} else {
$data['error_warning'] = '';
}
if (isset($this->session->data['payment_methods'])) {
$data['payment_methods'] = $this->session->data['payment_methods'];
} else {
$data['payment_methods'] = array();
}
if (isset($this->session->data['payment_method']['code'])) {
$data['code'] = $this->session->data['payment_method']['code'];
} else {
$data['code'] = '';
}
if (isset($this->session->data['comment'])) {
$data['comment'] = $this->session->data['comment'];
} else {
$data['comment'] = '';
}
$data['scripts'] = $this->document->getScripts();
if ($this->config->get('config_checkout_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_checkout_id'));
if ($information_info) {
$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_checkout_id'), true), $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
if (isset($this->session->data['agree'])) {
$data['agree'] = $this->session->data['agree'];
} else {
$data['agree'] = '';
}
$this->response->setOutput($this->load->view('checkout/payment_method', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
// Validate if payment address has been set.
if (!isset($this->session->data['payment_address'])) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$json['redirect'] = $this->url->link('checkout/cart');
break;
}
}
if (!isset($this->request->post['payment_method'])) {
$json['error']['warning'] = $this->language->get('error_payment');
} elseif (!isset($this->session->data['payment_methods'][$this->request->post['payment_method']])) {
$json['error']['warning'] = $this->language->get('error_payment');
}
if ($this->config->get('config_checkout_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_checkout_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
if (!$json) {
$this->session->data['payment_method'] = $this->session->data['payment_methods'][$this->request->post['payment_method']];
$this->session->data['comment'] = strip_tags($this->request->post['comment']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,251 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutRegister extends Controller {
public function index() {
$this->load->language('checkout/checkout');
$data['entry_newsletter'] = sprintf($this->language->get('entry_newsletter'), $this->config->get('config_name'));
$data['customer_groups'] = array();
if (is_array($this->config->get('config_customer_group_display'))) {
$this->load->model('account/customer_group');
$customer_groups = $this->model_account_customer_group->getCustomerGroups();
foreach ($customer_groups as $customer_group) {
if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$data['customer_groups'][] = $customer_group;
}
}
}
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
if (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
// Captcha
if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'));
} else {
$data['captcha'] = '';
}
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info) {
$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), true), $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
$data['shipping_required'] = $this->cart->hasShipping();
$this->response->setOutput($this->load->view('checkout/register', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
// Validate if customer is already logged out.
if ($this->customer->isLogged()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$json['redirect'] = $this->url->link('checkout/cart');
break;
}
}
if (!$json) {
$this->load->model('account/customer');
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
$json['error']['email'] = $this->language->get('error_email');
}
if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$json['error']['warning'] = $this->language->get('error_exists');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$json['error']['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$json['error']['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$json['error']['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$json['error']['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) {
$json['error']['zone'] = $this->language->get('error_zone');
}
if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) {
$json['error']['password'] = $this->language->get('error_password');
}
if ($this->request->post['confirm'] != $this->request->post['password']) {
$json['error']['confirm'] = $this->language->get('error_confirm');
}
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
// Captcha
if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) {
$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');
if ($captcha) {
$json['error']['captcha'] = $captcha;
}
}
}
if (!$json) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Default Payment Address
$this->load->model('account/address');
$address_id = $this->model_account_address->addAddress($customer_id, $this->request->post);
// Set the address as default
$this->model_account_customer->editAddressId($customer_id, $address_id);
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
$this->session->data['account'] = 'register';
$this->load->model('account/customer_group');
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
if ($customer_group_info && !$customer_group_info['approval']) {
$this->customer->login($this->request->post['email'], $this->request->post['password']);
$this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
if (!empty($this->request->post['shipping_address'])) {
$this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
}
} else {
$json['redirect'] = $this->url->link('account/success');
}
unset($this->session->data['guest']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,187 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutShippingAddress extends Controller {
public function index() {
$this->load->language('checkout/checkout');
if (isset($this->session->data['shipping_address']['address_id'])) {
$data['address_id'] = $this->session->data['shipping_address']['address_id'];
} else {
$data['address_id'] = $this->customer->getAddressId();
}
$this->load->model('account/address');
$data['addresses'] = $this->model_account_address->getAddresses();
if (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$data['custom_fields'] = array();
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
$data['custom_fields'][] = $custom_field;
}
}
if (isset($this->session->data['shipping_address']['custom_field'])) {
$data['shipping_address_custom_field'] = $this->session->data['shipping_address']['custom_field'];
} else {
$data['shipping_address_custom_field'] = array();
}
$this->response->setOutput($this->load->view('checkout/shipping_address', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
// Validate if customer is logged in.
if (!$this->customer->isLogged()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate if shipping is required. If not the customer should not have reached this page.
if (!$this->cart->hasShipping()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$json['redirect'] = $this->url->link('checkout/cart');
break;
}
}
if (!$json) {
$this->load->model('account/address');
if (isset($this->request->post['shipping_address']) && $this->request->post['shipping_address'] == 'existing') {
if (empty($this->request->post['address_id'])) {
$json['error']['warning'] = $this->language->get('error_address');
} elseif (!in_array($this->request->post['address_id'], array_keys($this->model_account_address->getAddresses()))) {
$json['error']['warning'] = $this->language->get('error_address');
}
if (!$json) {
$this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->request->post['address_id']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
}
} else {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$json['error']['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$json['error']['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$json['error']['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) {
$json['error']['zone'] = $this->language->get('error_zone');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
}
if (!$json) {
$address_id = $this->model_account_address->addAddress($this->customer->getId(), $this->request->post);
$this->session->data['shipping_address'] = $this->model_account_address->getAddress($address_id);
// If no default address ID set we use the last address
if (!$this->customer->getAddressId()) {
$this->load->model('account/customer');
$this->model_account_customer->editAddressId($this->customer->getId(), $address_id);
}
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
}
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,134 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutShippingMethod extends Controller {
public function index() {
$this->load->language('checkout/checkout');
if (isset($this->session->data['shipping_address'])) {
// Shipping Methods
$method_data = array();
$this->load->model('setting/extension');
$results = $this->model_setting_extension->getExtensions('shipping');
foreach ($results as $result) {
if ($this->config->get('shipping_' . $result['code'] . '_status')) {
if (!is_file(DIR_APPLICATION . 'model/extension/shipping/' . $result['code'] . '.php')) {
continue;
}
$this->load->model('extension/shipping/' . $result['code']);
$quote = $this->{'model_extension_shipping_' . $result['code']}->getQuote($this->session->data['shipping_address']);
if ($quote) {
$method_data[$result['code']] = array(
'title' => $quote['title'],
'quote' => $quote['quote'],
'sort_order' => $quote['sort_order'],
'error' => $quote['error']
);
}
}
}
$sort_order = array();
foreach ($method_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $method_data);
$this->session->data['shipping_methods'] = $method_data;
}
if (empty($this->session->data['shipping_methods'])) {
$data['error_warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
} else {
$data['error_warning'] = '';
}
if (isset($this->session->data['shipping_methods'])) {
$data['shipping_methods'] = $this->session->data['shipping_methods'];
} else {
$data['shipping_methods'] = array();
}
if (isset($this->session->data['shipping_method']['code'])) {
$data['code'] = $this->session->data['shipping_method']['code'];
} else {
$data['code'] = '';
}
if (isset($this->session->data['comment'])) {
$data['comment'] = $this->session->data['comment'];
} else {
$data['comment'] = '';
}
$this->response->setOutput($this->load->view('checkout/shipping_method', $data));
}
public function save() {
$this->load->language('checkout/checkout');
$json = array();
// Validate if shipping is required. If not the customer should not have reached this page.
if (!$this->cart->hasShipping()) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate if shipping address has been set.
if (!isset($this->session->data['shipping_address'])) {
$json['redirect'] = $this->url->link('checkout/checkout', '', true);
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$json['redirect'] = $this->url->link('checkout/cart');
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$json['redirect'] = $this->url->link('checkout/cart');
break;
}
}
if (!isset($this->request->post['shipping_method'])) {
$json['error']['warning'] = $this->language->get('error_shipping');
} else {
$shipping = explode('.', $this->request->post['shipping_method']);
if (!isset($shipping[0]) || !isset($shipping[1]) || !isset($this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {
$json['error']['warning'] = $this->language->get('error_shipping');
}
}
if (!$json) {
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
$this->session->data['comment'] = strip_tags($this->request->post['comment']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,80 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerCheckoutSuccess extends Controller {
public function index() {
$this->load->language('checkout/success');
if (isset($this->session->data['order_id'])) {
$this->session->data['last_order_id'] = $this->session->data['order_id'];
$this->cart->clear();
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['guest']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
unset($this->session->data['reward']);
unset($this->session->data['voucher']);
unset($this->session->data['vouchers']);
unset($this->session->data['totals']);
}
if (!empty($this->session->data['last_order_id']) ) {
$this->document->setTitle(sprintf($this->language->get('heading_title_customer'), $this->session->data['last_order_id']));
$this->document->setRobots('noindex,follow');
} else {
$this->document->setTitle($this->language->get('heading_title'));
$this->document->setRobots('noindex,follow');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_basket'),
'href' => $this->url->link('checkout/cart')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_checkout'),
'href' => $this->url->link('checkout/checkout', '', true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_success'),
'href' => $this->url->link('checkout/success')
);
if (!empty($this->session->data['last_order_id'])) {
$data['heading_title'] = sprintf($this->language->get('heading_title_customer'), $this->session->data['last_order_id']);
} else {
$data['heading_title'] = $this->language->get('heading_title');
}
if ($this->customer->isLogged() && !empty($this->session->data['last_order_id'])) {
$data['text_message'] = sprintf($this->language->get('text_customer'), $this->url->link('account/order/info&order_id=' . $this->session->data['last_order_id'], '', true), $this->url->link('account/account', '', true), $this->url->link('account/order', '', true), $this->url->link('information/contact'), $this->url->link('product/special'), $this->session->data['last_order_id'], $this->url->link('account/download', '', true));
} else {
$data['text_message'] = sprintf($this->language->get('text_guest'), $this->url->link('information/contact'));
}
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('common/success', $data));
}
}