first commit
This commit is contained in:
410
catalog/controller/checkout/cart.php
Normal file
410
catalog/controller/checkout/cart.php
Normal file
@ -0,0 +1,410 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class Cart
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class Cart extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('checkout/cart');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
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', 'language=' . $this->config->get('config_language')), $this->url->link('account/register', 'language=' . $this->config->get('config_language')));
|
||||
} else {
|
||||
$data['attention'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
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'] = '';
|
||||
}
|
||||
|
||||
$data['list'] = $this->load->controller('checkout/cart.getList');
|
||||
|
||||
$data['modules'] = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('total');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
$result = $this->load->controller('extension/' . $extension['extension'] . '/total/' . $extension['code']);
|
||||
|
||||
if (!$result instanceof \Exception) {
|
||||
$data['modules'][] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
$data['checkout'] = $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$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_no_results');
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('checkout/cart');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$data['list'] = $this->url->link(' ', 'language=' . $this->config->get('config_language'));
|
||||
$data['product_edit'] = $this->url->link('checkout/cart.edit', 'language=' . $this->config->get('config_language'));
|
||||
$data['product_remove'] = $this->url->link('checkout/cart.remove', 'language=' . $this->config->get('config_language'));
|
||||
$data['voucher_remove'] = $this->url->link('checkout/voucher.remove', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
// Display prices
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$price_status = true;
|
||||
} else {
|
||||
$price_status = false;
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
$this->load->model('tool/upload');
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$this->load->model('checkout/cart');
|
||||
|
||||
$products = $this->model_checkout_cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
|
||||
}
|
||||
|
||||
if ($product['option']) {
|
||||
foreach ($product['option'] as $key => $option) {
|
||||
$product['option'][$key]['value'] = (oc_strlen($option['value']) > 20 ? oc_substr($option['value'], 0, 20) . '..' : $option['value']);
|
||||
}
|
||||
}
|
||||
|
||||
$description = '';
|
||||
|
||||
if ($product['subscription']) {
|
||||
if ($product['subscription']['trial_status']) {
|
||||
$trial_price = $this->currency->format($this->tax->calculate($product['subscription']['trial_price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$trial_cycle = $product['subscription']['trial_cycle'];
|
||||
$trial_frequency = $this->language->get('text_' . $product['subscription']['trial_frequency']);
|
||||
$trial_duration = $product['subscription']['trial_duration'];
|
||||
|
||||
$description .= sprintf($this->language->get('text_subscription_trial'), $price_status ? $trial_price : '', $trial_cycle, $trial_frequency, $trial_duration);
|
||||
}
|
||||
|
||||
$price = $this->currency->format($this->tax->calculate($product['subscription']['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
|
||||
$cycle = $product['subscription']['cycle'];
|
||||
$frequency = $this->language->get('text_' . $product['subscription']['frequency']);
|
||||
$duration = $product['subscription']['duration'];
|
||||
|
||||
if ($duration) {
|
||||
$description .= sprintf($this->language->get('text_subscription_duration'), $price_status ? $price : '', $cycle, $frequency, $duration);
|
||||
} else {
|
||||
$description .= sprintf($this->language->get('text_subscription_cancel'), $price_status ? $price : '', $cycle, $frequency);
|
||||
}
|
||||
}
|
||||
|
||||
$data['products'][] = [
|
||||
'cart_id' => $product['cart_id'],
|
||||
'thumb' => $product['image'],
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'option' => $product['option'],
|
||||
'subscription' => $description,
|
||||
'quantity' => $product['quantity'],
|
||||
'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
|
||||
'minimum' => $product['minimum'],
|
||||
'reward' => $product['reward'],
|
||||
'price' => $price_status ? $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']) : '',
|
||||
'total' => $price_status ? $this->currency->format($this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']) : '',
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product['product_id'])
|
||||
];
|
||||
}
|
||||
|
||||
// Gift Voucher
|
||||
$data['vouchers'] = [];
|
||||
|
||||
$vouchers = $this->model_checkout_cart->getVouchers();
|
||||
|
||||
foreach ($vouchers as $key => $voucher) {
|
||||
$data['vouchers'][] = [
|
||||
'key' => $key,
|
||||
'description' => $voucher['description'],
|
||||
'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['totals'] = [];
|
||||
|
||||
$totals = [];
|
||||
$taxes = $this->cart->getTaxes();
|
||||
$total = 0;
|
||||
|
||||
// Display prices
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
($this->model_checkout_cart->getTotals)($totals, $taxes, $total);
|
||||
|
||||
foreach ($totals as $result) {
|
||||
$data['totals'][] = [
|
||||
'title' => $result['title'],
|
||||
'text' => $price_status ? $this->currency->format($result['value'], $this->session->data['currency']) : ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->load->view('checkout/cart_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function add(): void {
|
||||
$this->load->language('checkout/cart');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['product_id'])) {
|
||||
$product_id = (int)$this->request->post['product_id'];
|
||||
} else {
|
||||
$product_id = 0;
|
||||
}
|
||||
|
||||
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 = [];
|
||||
}
|
||||
|
||||
if (isset($this->request->post['subscription_plan_id'])) {
|
||||
$subscription_plan_id = (int)$this->request->post['subscription_plan_id'];
|
||||
} else {
|
||||
$subscription_plan_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$product_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($product_info) {
|
||||
// If variant get master product
|
||||
if ($product_info['master_id']) {
|
||||
$product_id = $product_info['master_id'];
|
||||
}
|
||||
|
||||
// Only use values in the override
|
||||
if (isset($product_info['override']['variant'])) {
|
||||
$override = $product_info['override']['variant'];
|
||||
} else {
|
||||
$override = [];
|
||||
}
|
||||
|
||||
// Merge variant code with options
|
||||
foreach ($product_info['variant'] as $key => $value) {
|
||||
if (array_key_exists($key, $override)) {
|
||||
$option[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate options
|
||||
$product_options = $this->model_catalog_product->getOptions($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']);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate subscription products
|
||||
$subscriptions = $this->model_catalog_product->getSubscriptions($product_id);
|
||||
|
||||
if ($subscriptions) {
|
||||
$subscription_plan_ids = [];
|
||||
|
||||
foreach ($subscriptions as $subscription) {
|
||||
$subscription_plan_ids[] = $subscription['subscription_plan_id'];
|
||||
}
|
||||
|
||||
if (!in_array($subscription_plan_id, $subscription_plan_ids)) {
|
||||
$json['error']['subscription'] = $this->language->get('error_subscription');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$json['error']['warning'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->cart->add($product_id, $quantity, $option, $subscription_plan_id);
|
||||
|
||||
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id), $product_info['name'], $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language')));
|
||||
|
||||
// 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']);
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id, true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function edit(): void {
|
||||
$this->load->language('checkout/cart');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['key'])) {
|
||||
$key = (int)$this->request->post['key'];
|
||||
} else {
|
||||
$key = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['quantity'])) {
|
||||
$quantity = (int)$this->request->post['quantity'];
|
||||
} else {
|
||||
$quantity = 1;
|
||||
}
|
||||
|
||||
if (!$this->cart->has($key)) {
|
||||
$json['error'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Handles single item update
|
||||
$this->cart->update($key, $quantity);
|
||||
|
||||
if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
|
||||
$json['success'] = $this->language->get('text_edit');
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
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->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function remove(): void {
|
||||
$this->load->language('checkout/cart');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['key'])) {
|
||||
$key = (int)$this->request->post['key'];
|
||||
} else {
|
||||
$key = 0;
|
||||
}
|
||||
|
||||
if (!$this->cart->has($key)) {
|
||||
$json['error'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
// Remove
|
||||
if (!$json) {
|
||||
$this->cart->remove($key);
|
||||
|
||||
if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
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->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
86
catalog/controller/checkout/checkout.php
Normal file
86
catalog/controller/checkout/checkout.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class Checkout
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class Checkout extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
// 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', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$this->response->redirect($this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->language('checkout/checkout');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_cart'),
|
||||
'href' => $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
if (!$this->customer->isLogged()) {
|
||||
$data['register'] = $this->load->controller('checkout/register');
|
||||
} else {
|
||||
$data['register'] = '';
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() && $this->config->get('config_checkout_payment_address')) {
|
||||
$data['payment_address'] = $this->load->controller('checkout/payment_address');
|
||||
} else {
|
||||
$data['payment_address'] = '';
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() && $this->cart->hasShipping()) {
|
||||
$data['shipping_address'] = $this->load->controller('checkout/shipping_address');
|
||||
} else {
|
||||
$data['shipping_address'] = '';
|
||||
}
|
||||
|
||||
if ($this->cart->hasShipping()) {
|
||||
$data['shipping_method'] = $this->load->controller('checkout/shipping_method');
|
||||
} else {
|
||||
$data['shipping_method'] = '';
|
||||
}
|
||||
|
||||
$data['payment_method'] = $this->load->controller('checkout/payment_method');
|
||||
$data['confirm'] = $this->load->controller('checkout/confirm');
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
424
catalog/controller/checkout/confirm.php
Normal file
424
catalog/controller/checkout/confirm.php
Normal file
@ -0,0 +1,424 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class Confirm
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class Confirm extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('checkout/confirm');
|
||||
|
||||
// Order Totals
|
||||
$totals = [];
|
||||
$taxes = $this->cart->getTaxes();
|
||||
$total = 0;
|
||||
|
||||
$this->load->model('checkout/cart');
|
||||
|
||||
($this->model_checkout_cart->getTotals)($totals, $taxes, $total);
|
||||
|
||||
$status = ($this->customer->isLogged() || !$this->config->get('config_customer_price'));
|
||||
|
||||
// Validate customer data is set
|
||||
if (!isset($this->session->data['customer'])) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// 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'))) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->model_checkout_cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$status = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Shipping
|
||||
if ($this->cart->hasShipping()) {
|
||||
// Validate shipping address
|
||||
if (!isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// Validate shipping method
|
||||
if (!isset($this->session->data['shipping_method'])) {
|
||||
$status = false;
|
||||
}
|
||||
} else {
|
||||
unset($this->session->data['shipping_address']);
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
}
|
||||
|
||||
// Validate has payment address if required
|
||||
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// Validate payment methods
|
||||
if (!isset($this->session->data['payment_method'])) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// Validate checkout terms
|
||||
if ($this->config->get('config_checkout_id') && empty($this->session->data['agree'])) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// Generate order if payment method is set
|
||||
if ($status) {
|
||||
$order_data = [];
|
||||
|
||||
$order_data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
|
||||
|
||||
// Store Details
|
||||
$order_data['store_id'] = $this->config->get('config_store_id');
|
||||
$order_data['store_name'] = $this->config->get('config_name');
|
||||
$order_data['store_url'] = $this->config->get('config_url');
|
||||
|
||||
// Customer Details
|
||||
$order_data['customer_id'] = $this->session->data['customer']['customer_id'];
|
||||
$order_data['customer_group_id'] = $this->session->data['customer']['customer_group_id'];
|
||||
$order_data['firstname'] = $this->session->data['customer']['firstname'];
|
||||
$order_data['lastname'] = $this->session->data['customer']['lastname'];
|
||||
$order_data['email'] = $this->session->data['customer']['email'];
|
||||
$order_data['telephone'] = $this->session->data['customer']['telephone'];
|
||||
$order_data['custom_field'] = $this->session->data['customer']['custom_field'];
|
||||
|
||||
// Payment Details
|
||||
if ($this->config->get('config_checkout_payment_address')) {
|
||||
$order_data['payment_address_id'] = $this->session->data['payment_address']['address_id'];
|
||||
$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'] : [];
|
||||
} else {
|
||||
$order_data['payment_address_id'] = 0;
|
||||
$order_data['payment_firstname'] = '';
|
||||
$order_data['payment_lastname'] = '';
|
||||
$order_data['payment_company'] = '';
|
||||
$order_data['payment_address_1'] = '';
|
||||
$order_data['payment_address_2'] = '';
|
||||
$order_data['payment_city'] = '';
|
||||
$order_data['payment_postcode'] = '';
|
||||
$order_data['payment_zone'] = '';
|
||||
$order_data['payment_zone_id'] = 0;
|
||||
$order_data['payment_country'] = '';
|
||||
$order_data['payment_country_id'] = 0;
|
||||
$order_data['payment_address_format'] = '';
|
||||
$order_data['payment_custom_field'] = [];
|
||||
}
|
||||
|
||||
$order_data['payment_method'] = $this->session->data['payment_method'];
|
||||
|
||||
// Shipping Details
|
||||
if ($this->cart->hasShipping()) {
|
||||
$order_data['shipping_address_id'] = $this->session->data['shipping_address']['address_id'];
|
||||
$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'] : [];
|
||||
|
||||
$order_data['shipping_method'] = $this->session->data['shipping_method'];
|
||||
} else {
|
||||
$order_data['shipping_address_id'] = 0;
|
||||
$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'] = 0;
|
||||
$order_data['shipping_country'] = '';
|
||||
$order_data['shipping_country_id'] = 0;
|
||||
$order_data['shipping_address_format'] = '';
|
||||
$order_data['shipping_custom_field'] = [];
|
||||
|
||||
$order_data['shipping_method'] = [];
|
||||
}
|
||||
|
||||
if (isset($this->session->data['comment'])) {
|
||||
$order_data['comment'] = $this->session->data['comment'];
|
||||
} else {
|
||||
$order_data['comment'] = '';
|
||||
}
|
||||
|
||||
$total_data = [
|
||||
'totals' => $totals,
|
||||
'taxes' => $taxes,
|
||||
'total' => $total
|
||||
];
|
||||
|
||||
$order_data = array_merge($order_data, $total_data);
|
||||
|
||||
$order_data['affiliate_id'] = 0;
|
||||
$order_data['commission'] = 0;
|
||||
$order_data['marketing_id'] = 0;
|
||||
$order_data['tracking'] = '';
|
||||
|
||||
if (isset($this->session->data['tracking'])) {
|
||||
$subtotal = $this->cart->getSubTotal();
|
||||
|
||||
// Affiliate
|
||||
if ($this->config->get('config_affiliate_status')) {
|
||||
$this->load->model('account/affiliate');
|
||||
|
||||
$affiliate_info = $this->model_account_affiliate->getAffiliateByTracking($this->session->data['tracking']);
|
||||
|
||||
if ($affiliate_info) {
|
||||
$order_data['affiliate_id'] = $affiliate_info['customer_id'];
|
||||
$order_data['commission'] = ($subtotal / 100) * $affiliate_info['commission'];
|
||||
$order_data['tracking'] = $this->session->data['tracking'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('marketing/marketing');
|
||||
|
||||
$marketing_info = $this->model_marketing_marketing->getMarketingByCode($this->session->data['tracking']);
|
||||
|
||||
if ($marketing_info) {
|
||||
$order_data['marketing_id'] = $marketing_info['marketing_id'];
|
||||
$order_data['tracking'] = $this->session->data['tracking'];
|
||||
}
|
||||
}
|
||||
|
||||
$order_data['language_id'] = $this->config->get('config_language_id');
|
||||
$order_data['language_code'] = $this->config->get('config_language');
|
||||
|
||||
$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'] = '';
|
||||
}
|
||||
|
||||
// Products
|
||||
$order_data['products'] = [];
|
||||
|
||||
foreach ($products as $product) {
|
||||
$option_data = [];
|
||||
|
||||
foreach ($product['option'] as $option) {
|
||||
$option_data[] = [
|
||||
'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']
|
||||
];
|
||||
}
|
||||
|
||||
$subscription_data = [];
|
||||
|
||||
if ($product['subscription']) {
|
||||
$subscription_data = [
|
||||
'subscription_plan_id' => $product['subscription']['subscription_plan_id'],
|
||||
'name' => $product['subscription']['name'],
|
||||
'trial_price' => $product['subscription']['trial_price'],
|
||||
'trial_tax' => $this->tax->getTax($product['subscription']['trial_price'], $product['tax_class_id']),
|
||||
'trial_frequency' => $product['subscription']['trial_frequency'],
|
||||
'trial_cycle' => $product['subscription']['trial_cycle'],
|
||||
'trial_duration' => $product['subscription']['trial_duration'],
|
||||
'trial_remaining' => $product['subscription']['trial_remaining'],
|
||||
'trial_status' => $product['subscription']['trial_status'],
|
||||
'price' => $product['subscription']['price'],
|
||||
'tax' => $this->tax->getTax($product['subscription']['price'], $product['tax_class_id']),
|
||||
'frequency' => $product['subscription']['frequency'],
|
||||
'cycle' => $product['subscription']['cycle'],
|
||||
'duration' => $product['subscription']['duration']
|
||||
];
|
||||
}
|
||||
|
||||
$order_data['products'][] = [
|
||||
'product_id' => $product['product_id'],
|
||||
'master_id' => $product['master_id'],
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'option' => $option_data,
|
||||
'subscription' => $subscription_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'] = [];
|
||||
|
||||
if (!empty($this->session->data['vouchers'])) {
|
||||
$order_data['vouchers'] = $this->session->data['vouchers'];
|
||||
}
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
if (!isset($this->session->data['order_id'])) {
|
||||
$this->session->data['order_id'] = $this->model_checkout_order->addOrder($order_data);
|
||||
} else {
|
||||
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
|
||||
|
||||
if ($order_info && !$order_info['order_status_id']) {
|
||||
$this->model_checkout_order->editOrder($this->session->data['order_id'], $order_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display prices
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$price_status = true;
|
||||
} else {
|
||||
$price_status = false;
|
||||
}
|
||||
|
||||
$this->load->model('tool/upload');
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
foreach ($products as $product) {
|
||||
if ($product['option']) {
|
||||
foreach ($product['option'] as $key => $option) {
|
||||
$product['option'][$key]['value'] = (oc_strlen($option['value']) > 20 ? oc_substr($option['value'], 0, 20) . '..' : $option['value']);
|
||||
}
|
||||
}
|
||||
|
||||
$description = '';
|
||||
|
||||
if ($product['subscription']) {
|
||||
if ($product['subscription']['trial_status']) {
|
||||
$trial_price = $this->currency->format($this->tax->calculate($product['subscription']['trial_price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$trial_cycle = $product['subscription']['trial_cycle'];
|
||||
$trial_frequency = $this->language->get('text_' . $product['subscription']['trial_frequency']);
|
||||
$trial_duration = $product['subscription']['trial_duration'];
|
||||
|
||||
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
|
||||
}
|
||||
|
||||
$price = $this->currency->format($this->tax->calculate($product['subscription']['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$cycle = $product['subscription']['cycle'];
|
||||
$frequency = $this->language->get('text_' . $product['subscription']['frequency']);
|
||||
$duration = $product['subscription']['duration'];
|
||||
|
||||
if ($duration) {
|
||||
$description .= sprintf($this->language->get('text_subscription_duration'), $price_status ? $price : '', $cycle, $frequency, $duration);
|
||||
} else {
|
||||
$description .= sprintf($this->language->get('text_subscription_cancel'), $price_status ? $price : '', $cycle, $frequency);
|
||||
}
|
||||
}
|
||||
|
||||
$data['products'][] = [
|
||||
'cart_id' => $product['cart_id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'option' => $product['option'],
|
||||
'subscription' => $description,
|
||||
'quantity' => $product['quantity'],
|
||||
'price' => $price_status ? $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']) : '',
|
||||
'total' => $price_status ? $this->currency->format($this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']) : '',
|
||||
'reward' => $product['reward'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product['product_id'])
|
||||
];
|
||||
}
|
||||
|
||||
// Gift Voucher
|
||||
$data['vouchers'] = [];
|
||||
|
||||
$vouchers = $this->model_checkout_cart->getVouchers();
|
||||
|
||||
foreach ($vouchers as $voucher) {
|
||||
$data['vouchers'][] = [
|
||||
'description' => $voucher['description'],
|
||||
'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['totals'] = [];
|
||||
|
||||
foreach ($totals as $total) {
|
||||
$data['totals'][] = [
|
||||
'title' => $total['title'],
|
||||
'text' => $this->currency->format($total['value'], $this->session->data['currency'])
|
||||
];
|
||||
}
|
||||
|
||||
// Validate if payment method has been set.
|
||||
if (isset($this->session->data['payment_method'])) {
|
||||
$code = oc_substr($this->session->data['payment_method']['code'], 0, strpos($this->session->data['payment_method']['code'], '.'));
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
$extension_info = $this->model_setting_extension->getExtensionByCode('payment', $code);
|
||||
|
||||
if ($status && $extension_info) {
|
||||
$data['payment'] = $this->load->controller('extension/' . $extension_info['extension'] . '/payment/' . $extension_info['code']);
|
||||
} else {
|
||||
$data['payment'] = '';
|
||||
}
|
||||
|
||||
// Validate if payment method has been set.
|
||||
return $this->load->view('checkout/confirm', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(): void {
|
||||
$this->response->setOutput($this->index());
|
||||
}
|
||||
}
|
52
catalog/controller/checkout/failure.php
Normal file
52
catalog/controller/checkout/failure.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class Failure
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class Failure extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('checkout/failure');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_basket'),
|
||||
'href' => $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_checkout'),
|
||||
'href' => $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_failure'),
|
||||
'href' => $this->url->link('checkout/failure', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['text_message'] = sprintf($this->language->get('text_message'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
258
catalog/controller/checkout/payment_address.php
Normal file
258
catalog/controller/checkout/payment_address.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class PaymentAddress
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class PaymentAddress extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('checkout/payment_address');
|
||||
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size'));
|
||||
$data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024);
|
||||
|
||||
$data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$this->load->model('account/address');
|
||||
|
||||
$data['addresses'] = $this->model_account_address->getAddresses($this->customer->getId());
|
||||
|
||||
if (isset($this->session->data['payment_address']['address_id'])) {
|
||||
$data['address_id'] = $this->session->data['payment_address']['address_id'];
|
||||
} else {
|
||||
$data['address_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
// Custom Fields
|
||||
$data['custom_fields'] = [];
|
||||
|
||||
$this->load->model('account/custom_field');
|
||||
|
||||
$custom_fields = $this->model_account_custom_field->getCustomFields($this->customer->getGroupId());
|
||||
|
||||
foreach ($custom_fields as $custom_field) {
|
||||
if ($custom_field['location'] == 'address') {
|
||||
$data['custom_fields'][] = $custom_field;
|
||||
}
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('checkout/payment_address', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('checkout/payment_address');
|
||||
|
||||
$json = [];
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate if customer is logged in or customer session data is not set
|
||||
if (!$this->customer->isLogged() || !isset($this->session->data['customer'])) {
|
||||
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate if payment address is set if required in settings
|
||||
if (!$this->config->get('config_checkout_payment_address')) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$keys = [
|
||||
'firstname',
|
||||
'lastname',
|
||||
'company',
|
||||
'address_1',
|
||||
'address_2',
|
||||
'city',
|
||||
'postcode',
|
||||
'country_id',
|
||||
'zone_id',
|
||||
'custom_field'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['firstname']) < 1) || (oc_strlen($this->request->post['firstname']) > 32)) {
|
||||
$json['error']['firstname'] = $this->language->get('error_firstname');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['lastname']) < 1) || (oc_strlen($this->request->post['lastname']) > 32)) {
|
||||
$json['error']['lastname'] = $this->language->get('error_lastname');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['address_1']) < 3) || (oc_strlen($this->request->post['address_1']) > 128)) {
|
||||
$json['error']['address_1'] = $this->language->get('error_address_1');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['city']) < 2) || (oc_strlen($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((int)$this->request->post['country_id']);
|
||||
|
||||
if ($country_info && $country_info['postcode_required'] && (oc_strlen($this->request->post['postcode']) < 2 || oc_strlen($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 ($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->customer->getGroupId());
|
||||
|
||||
foreach ($custom_fields as $custom_field) {
|
||||
if ($custom_field['location'] == 'address') {
|
||||
if ($custom_field['required'] && empty($this->request->post['custom_field'][$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']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $this->request->post['custom_field'][$custom_field['custom_field_id']])) {
|
||||
$json['error']['custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// If no default address add it
|
||||
$address_id = $this->customer->getAddressId();
|
||||
|
||||
if (!$address_id) {
|
||||
$this->request->post['default'] = 1;
|
||||
}
|
||||
|
||||
$this->load->model('account/address');
|
||||
|
||||
$json['address_id'] = $this->model_account_address->addAddress($this->customer->getId(), $this->request->post);
|
||||
|
||||
$json['addresses'] = $this->model_account_address->getAddresses($this->customer->getId());
|
||||
|
||||
$this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getId(), $json['address_id']);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
// Clear payment and shipping 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']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function address(): void {
|
||||
$this->load->language('checkout/payment_address');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['address_id'])) {
|
||||
$address_id = (int)$this->request->get['address_id'];
|
||||
} else {
|
||||
$address_id = 0;
|
||||
}
|
||||
|
||||
if (!isset($this->session->data['customer'])) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate if customer is logged in or customer session data is not set
|
||||
if (!$this->customer->isLogged() || !isset($this->session->data['customer'])) {
|
||||
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate if payment address is set if required in settings
|
||||
if (!$this->config->get('config_checkout_payment_address')) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('account/address');
|
||||
|
||||
$address_info = $this->model_account_address->getAddress($this->customer->getId(), $address_id);
|
||||
|
||||
if (!$address_info) {
|
||||
$json['error'] = $this->language->get('error_address');
|
||||
|
||||
unset($this->session->data['payment_address']);
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['payment_address'] = $address_info;
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
// Clear payment and shipping 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']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
231
catalog/controller/checkout/payment_method.php
Normal file
231
catalog/controller/checkout/payment_method.php
Normal file
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class PaymentMethod
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class PaymentMethod extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('checkout/payment_method');
|
||||
|
||||
if (isset($this->session->data['payment_method'])) {
|
||||
$data['payment_method'] = $this->session->data['payment_method']['name'];
|
||||
$data['code'] = $this->session->data['payment_method']['code'];
|
||||
} else {
|
||||
$data['payment_method'] = '';
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['comment'])) {
|
||||
$data['comment'] = $this->session->data['comment'];
|
||||
} else {
|
||||
$data['comment'] = '';
|
||||
}
|
||||
|
||||
$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.info', 'language=' . $this->config->get('config_language') . '&information_id=' . $this->config->get('config_checkout_id')), $information_info['title']);
|
||||
} else {
|
||||
$data['text_agree'] = '';
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('checkout/payment_method', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function getMethods(): void {
|
||||
$this->load->language('checkout/payment_method');
|
||||
|
||||
$json = [];
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Validate if customer session data is set
|
||||
if (!isset($this->session->data['customer'])) {
|
||||
$json['error'] = $this->language->get('error_customer');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
|
||||
$json['error'] = $this->language->get('error_payment_address');
|
||||
}
|
||||
|
||||
// Validate shipping
|
||||
if ($this->cart->hasShipping()) {
|
||||
// Validate shipping address
|
||||
if (!isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$json['error'] = $this->language->get('error_shipping_address');
|
||||
}
|
||||
|
||||
// Validate shipping method
|
||||
if (!isset($this->session->data['shipping_method'])) {
|
||||
$json['error'] = $this->language->get('error_shipping_method');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$payment_address = [];
|
||||
|
||||
if ($this->config->get('config_checkout_payment_address') && isset($this->session->data['payment_address'])) {
|
||||
$payment_address = $this->session->data['payment_address'];
|
||||
} elseif ($this->config->get('config_checkout_shipping_address') && isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$payment_address = $this->session->data['shipping_address'];
|
||||
}
|
||||
|
||||
// Payment methods
|
||||
$this->load->model('checkout/payment_method');
|
||||
|
||||
$payment_methods = $this->model_checkout_payment_method->getMethods($payment_address);
|
||||
|
||||
if ($payment_methods) {
|
||||
$json['payment_methods'] = $this->session->data['payment_methods'] = $payment_methods;
|
||||
} else {
|
||||
$json['error'] = sprintf($this->language->get('error_no_payment'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('checkout/payment_method');
|
||||
|
||||
$json = [];
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Validate has payment address if required
|
||||
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
|
||||
$json['error'] = $this->language->get('error_payment_address');
|
||||
}
|
||||
|
||||
// Validate shipping
|
||||
if ($this->cart->hasShipping()) {
|
||||
// Validate shipping address
|
||||
if (!isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$json['error'] = $this->language->get('error_shipping_address');
|
||||
}
|
||||
|
||||
// Validate shipping method
|
||||
if (!isset($this->session->data['shipping_method'])) {
|
||||
$json['error'] = $this->language->get('error_shipping_method');
|
||||
}
|
||||
}
|
||||
|
||||
// Validate payment methods
|
||||
if (isset($this->request->post['payment_method']) && isset($this->session->data['payment_methods'])) {
|
||||
$payment = explode('.', $this->request->post['payment_method']);
|
||||
|
||||
if (!isset($payment[0]) || !isset($payment[1]) || !isset($this->session->data['payment_methods'][$payment[0]]['option'][$payment[1]])) {
|
||||
$json['error'] = $this->language->get('error_payment_method');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_payment_method');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['payment_method'] = $this->session->data['payment_methods'][$payment[0]]['option'][$payment[1]];
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function comment(): void {
|
||||
$this->load->language('checkout/payment_method');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->session->data['order_id'])) {
|
||||
$order_id = (int)$this->session->data['order_id'];
|
||||
} else {
|
||||
$order_id = 0;
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['comment'] = $this->request->post['comment'];
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($order_id);
|
||||
|
||||
if ($order_info) {
|
||||
$this->model_checkout_order->editComment($order_id, $this->request->post['comment']);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_comment');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function agree(): void {
|
||||
$this->load->language('checkout/payment_method');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['agree'])) {
|
||||
$this->session->data['agree'] = $this->request->post['agree'];
|
||||
} else {
|
||||
unset($this->session->data['agree']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
632
catalog/controller/checkout/register.php
Normal file
632
catalog/controller/checkout/register.php
Normal file
@ -0,0 +1,632 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class Register
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class Register extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('checkout/register');
|
||||
|
||||
$data['text_login'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', 'language=' . $this->config->get('config_language') . '&redirect=' . urlencode($this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'), true))));
|
||||
|
||||
$data['entry_newsletter'] = sprintf($this->language->get('entry_newsletter'), $this->config->get('config_name'));
|
||||
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size'));
|
||||
|
||||
$data['config_checkout_payment_address'] = $this->config->get('config_checkout_payment_address');
|
||||
$data['config_checkout_guest'] = ($this->config->get('config_checkout_guest') && !$this->config->get('config_customer_price') && !$this->cart->hasDownload() && !$this->cart->hasSubscription());
|
||||
$data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024);
|
||||
$data['config_telephone_display'] = $this->config->get('config_telephone_display');
|
||||
$data['config_telephone_required'] = $this->config->get('config_telephone_required');
|
||||
|
||||
$data['shipping_required'] = $this->cart->hasShipping();
|
||||
|
||||
$data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['customer_groups'] = [];
|
||||
|
||||
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['customer']['customer_id'])) {
|
||||
$data['account'] = $this->session->data['customer']['customer_id'];
|
||||
} else {
|
||||
$data['account'] = 1;
|
||||
}
|
||||
|
||||
if (isset($this->session->data['customer'])) {
|
||||
$data['customer_group_id'] = $this->session->data['customer']['customer_group_id'];
|
||||
$data['firstname'] = $this->session->data['customer']['firstname'];
|
||||
$data['lastname'] = $this->session->data['customer']['lastname'];
|
||||
$data['email'] = $this->session->data['customer']['email'];
|
||||
$data['telephone'] = $this->session->data['customer']['telephone'];
|
||||
$data['account_custom_field'] = $this->session->data['customer']['custom_field'];
|
||||
} else {
|
||||
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
|
||||
$data['firstname'] = '';
|
||||
$data['lastname'] = '';
|
||||
$data['email'] = '';
|
||||
$data['telephone'] = '';
|
||||
$data['account_custom_field'] = [];
|
||||
}
|
||||
|
||||
if (isset($this->session->data['payment_address'])) {
|
||||
$data['payment_firstname'] = $this->session->data['payment_address']['firstname'];
|
||||
$data['payment_lastname'] = $this->session->data['payment_address']['lastname'];
|
||||
$data['payment_company'] = $this->session->data['payment_address']['company'];
|
||||
$data['payment_address_1'] = $this->session->data['payment_address']['address_1'];
|
||||
$data['payment_address_2'] = $this->session->data['payment_address']['address_2'];
|
||||
$data['payment_postcode'] = $this->session->data['payment_address']['postcode'];
|
||||
$data['payment_city'] = $this->session->data['payment_address']['city'];
|
||||
$data['payment_country_id'] = (int)$this->session->data['payment_address']['country_id'];
|
||||
$data['payment_zone_id'] = $this->session->data['payment_address']['zone_id'];
|
||||
$data['payment_custom_field'] = $this->session->data['payment_address']['custom_field'];
|
||||
} else {
|
||||
$data['payment_firstname'] = '';
|
||||
$data['payment_lastname'] = '';
|
||||
$data['payment_company'] = '';
|
||||
$data['payment_address_1'] = '';
|
||||
$data['payment_address_2'] = '';
|
||||
$data['payment_postcode'] = '';
|
||||
$data['payment_city'] = '';
|
||||
$data['payment_country_id'] = $this->config->get('config_country_id');
|
||||
$data['payment_zone_id'] = '';
|
||||
$data['payment_custom_field'] = [];
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$data['shipping_firstname'] = $this->session->data['shipping_address']['firstname'];
|
||||
$data['shipping_lastname'] = $this->session->data['shipping_address']['lastname'];
|
||||
$data['shipping_company'] = $this->session->data['shipping_address']['company'];
|
||||
$data['shipping_address_1'] = $this->session->data['shipping_address']['address_1'];
|
||||
$data['shipping_address_2'] = $this->session->data['shipping_address']['address_2'];
|
||||
$data['shipping_postcode'] = $this->session->data['shipping_address']['postcode'];
|
||||
$data['shipping_city'] = $this->session->data['shipping_address']['city'];
|
||||
$data['shipping_country_id'] = (int)$this->session->data['shipping_address']['country_id'];
|
||||
$data['shipping_zone_id'] = $this->session->data['shipping_address']['zone_id'];
|
||||
$data['shipping_custom_field'] = $this->session->data['shipping_address']['custom_field'];
|
||||
} else {
|
||||
$data['shipping_firstname'] = '';
|
||||
$data['shipping_lastname'] = '';
|
||||
$data['shipping_company'] = '';
|
||||
$data['shipping_address_1'] = '';
|
||||
$data['shipping_address_2'] = '';
|
||||
|
||||
if (isset($this->session->data['shipping_address']['postcode'])) {
|
||||
$data['shipping_postcode'] = $this->session->data['shipping_address']['postcode'];
|
||||
} else {
|
||||
$data['shipping_postcode'] = '';
|
||||
}
|
||||
|
||||
$data['shipping_city'] = '';
|
||||
|
||||
if (isset($this->session->data['shipping_address']['country_id'])) {
|
||||
$data['shipping_country_id'] = $this->session->data['shipping_address']['country_id'];
|
||||
} else {
|
||||
$data['shipping_country_id'] = $this->config->get('config_country_id');
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_address']['zone_id'])) {
|
||||
$data['shipping_zone_id'] = $this->session->data['shipping_address']['zone_id'];
|
||||
} else {
|
||||
$data['shipping_zone_id'] = '';
|
||||
}
|
||||
|
||||
$data['shipping_custom_field'] = [];
|
||||
}
|
||||
|
||||
$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
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha'));
|
||||
|
||||
if ($extension_info && $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/' . $extension_info['extension'] . '/captcha/' . $extension_info['code']);
|
||||
} else {
|
||||
$data['captcha'] = '';
|
||||
}
|
||||
|
||||
$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.info', 'language=' . $this->config->get('config_language') . '&information_id=' . $this->config->get('config_account_id')), $information_info['title']);
|
||||
} else {
|
||||
$data['text_agree'] = '';
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('checkout/register', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('checkout/register');
|
||||
|
||||
$json = [];
|
||||
|
||||
$keys = [
|
||||
'account',
|
||||
'customer_group_id',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'email',
|
||||
'telephone',
|
||||
'payment_company',
|
||||
'payment_address_1',
|
||||
'payment_address_2',
|
||||
'payment_city',
|
||||
'payment_postcode',
|
||||
'payment_country_id',
|
||||
'payment_zone_id',
|
||||
'payment_custom_field',
|
||||
'address_match',
|
||||
'shipping_firstname',
|
||||
'shipping_lastname',
|
||||
'shipping_company',
|
||||
'shipping_address_1',
|
||||
'shipping_address_2',
|
||||
'shipping_city',
|
||||
'shipping_postcode',
|
||||
'shipping_country_id',
|
||||
'shipping_zone_id',
|
||||
'shipping_custom_field',
|
||||
'password',
|
||||
'agree'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Force account requires subscript or is a downloadable product.
|
||||
if ($this->cart->hasDownload() || $this->cart->hasSubscription()) {
|
||||
$this->request->post['account'] = 1;
|
||||
}
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// If not guest checkout disabled, login require price or cart has downloads
|
||||
if (!$this->request->post['account'] && (!$this->config->get('config_checkout_guest') || $this->config->get('config_customer_price'))) {
|
||||
$json['error']['warning'] = $this->language->get('error_guest');
|
||||
}
|
||||
|
||||
// Customer Group
|
||||
if ($this->request->post['customer_group_id']) {
|
||||
$customer_group_id = (int)$this->request->post['customer_group_id'];
|
||||
} else {
|
||||
$customer_group_id = (int)$this->config->get('config_customer_group_id');
|
||||
}
|
||||
|
||||
$this->load->model('account/customer_group');
|
||||
|
||||
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
|
||||
|
||||
if (!$customer_group_info || !in_array($customer_group_id, (array)$this->config->get('config_customer_group_display'))) {
|
||||
$json['error']['warning'] = $this->language->get('error_customer_group');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['firstname']) < 1) || (oc_strlen($this->request->post['firstname']) > 32)) {
|
||||
$json['error']['firstname'] = $this->language->get('error_firstname');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['lastname']) < 1) || (oc_strlen($this->request->post['lastname']) > 32)) {
|
||||
$json['error']['lastname'] = $this->language->get('error_lastname');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$json['error']['email'] = $this->language->get('error_email');
|
||||
}
|
||||
|
||||
$this->load->model('account/customer');
|
||||
|
||||
if ($this->request->post['account'] && $this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_exists');
|
||||
}
|
||||
|
||||
// Logged
|
||||
if ($this->customer->isLogged()) {
|
||||
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
|
||||
|
||||
if ($customer_info['customer_id'] != $this->customer->getId()) {
|
||||
$json['error']['warning'] = $this->language->get('error_exists');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config->get('config_telephone_required') && (oc_strlen($this->request->post['telephone']) < 3) || (oc_strlen($this->request->post['telephone']) > 32)) {
|
||||
$json['error']['telephone'] = $this->language->get('error_telephone');
|
||||
}
|
||||
|
||||
// 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['location'] == 'account') {
|
||||
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']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $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_regex'), $custom_field['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config->get('config_checkout_payment_address')) {
|
||||
if ((oc_strlen($this->request->post['payment_address_1']) < 3) || (oc_strlen($this->request->post['payment_address_1']) > 128)) {
|
||||
$json['error']['payment_address_1'] = $this->language->get('error_address_1');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['payment_city']) < 2) || (oc_strlen($this->request->post['payment_city']) > 128)) {
|
||||
$json['error']['payment_city'] = $this->language->get('error_city');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$payment_country_info = $this->model_localisation_country->getCountry((int)$this->request->post['payment_country_id']);
|
||||
|
||||
if ($payment_country_info && $payment_country_info['postcode_required'] && (oc_strlen($this->request->post['payment_postcode']) < 2 || oc_strlen($this->request->post['payment_postcode']) > 10)) {
|
||||
$json['error']['payment_postcode'] = $this->language->get('error_postcode');
|
||||
}
|
||||
|
||||
if ($this->request->post['payment_country_id'] == '') {
|
||||
$json['error']['payment_country'] = $this->language->get('error_country');
|
||||
}
|
||||
|
||||
if ($this->request->post['payment_zone_id'] == '') {
|
||||
$json['error']['payment_zone'] = $this->language->get('error_zone');
|
||||
}
|
||||
|
||||
// Custom field validation
|
||||
foreach ($custom_fields as $custom_field) {
|
||||
if ($custom_field['location'] == 'address') {
|
||||
if ($custom_field['required'] && empty($this->request->post['payment_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
|
||||
$json['error']['payment_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']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $this->request->post['payment_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
|
||||
$json['error']['payment_custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->cart->hasShipping() && !$this->request->post['address_match']) {
|
||||
// If payment address not required we need to use the firstname and lastname from the account.
|
||||
if ($this->config->get('config_checkout_payment_address')) {
|
||||
if ((oc_strlen($this->request->post['shipping_firstname']) < 1) || (oc_strlen($this->request->post['shipping_firstname']) > 32)) {
|
||||
$json['error']['shipping_firstname'] = $this->language->get('error_firstname');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['shipping_lastname']) < 1) || (oc_strlen($this->request->post['shipping_lastname']) > 32)) {
|
||||
$json['error']['shipping_lastname'] = $this->language->get('error_lastname');
|
||||
}
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['shipping_address_1']) < 3) || (oc_strlen($this->request->post['shipping_address_1']) > 128)) {
|
||||
$json['error']['shipping_address_1'] = $this->language->get('error_address_1');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['shipping_city']) < 2) || (oc_strlen($this->request->post['shipping_city']) > 128)) {
|
||||
$json['error']['shipping_city'] = $this->language->get('error_city');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$shipping_country_info = $this->model_localisation_country->getCountry((int)$this->request->post['shipping_country_id']);
|
||||
|
||||
if ($shipping_country_info && $shipping_country_info['postcode_required'] && (oc_strlen($this->request->post['shipping_postcode']) < 2 || oc_strlen($this->request->post['shipping_postcode']) > 10)) {
|
||||
$json['error']['shipping_postcode'] = $this->language->get('error_postcode');
|
||||
}
|
||||
|
||||
if ($this->request->post['shipping_country_id'] == '') {
|
||||
$json['error']['shipping_country'] = $this->language->get('error_country');
|
||||
}
|
||||
|
||||
if ($this->request->post['shipping_zone_id'] == '') {
|
||||
$json['error']['shipping_zone'] = $this->language->get('error_zone');
|
||||
}
|
||||
|
||||
// Custom field validation
|
||||
foreach ($custom_fields as $custom_field) {
|
||||
if ($custom_field['location'] == 'address') {
|
||||
if ($custom_field['required'] && empty($this->request->post['shipping_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
|
||||
$json['error']['shipping_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']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $this->request->post['shipping_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
|
||||
$json['error']['shipping_custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If account register password required
|
||||
if ($this->request->post['account'] && (oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (oc_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['account']) {
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
|
||||
|
||||
if ($information_info && !$this->request->post['agree']) {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
|
||||
}
|
||||
}
|
||||
|
||||
// Captcha
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
if (!$this->customer->isLogged()) {
|
||||
$extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha'));
|
||||
|
||||
if ($extension_info && $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/' . $extension_info['extension'] . '/captcha/' . $extension_info['code'] . '.validate');
|
||||
|
||||
if ($captcha) {
|
||||
$json['error']['captcha'] = $captcha;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Add customer details into session
|
||||
$customer_data = [
|
||||
'customer_id' => 0,
|
||||
'customer_group_id' => $customer_group_id,
|
||||
'firstname' => $this->request->post['firstname'],
|
||||
'lastname' => $this->request->post['lastname'],
|
||||
'email' => $this->request->post['email'],
|
||||
'telephone' => $this->request->post['telephone'],
|
||||
'custom_field' => isset($this->request->post['custom_field']) ? $this->request->post['custom_field'] : []
|
||||
];
|
||||
|
||||
// Register
|
||||
if ($this->request->post['account']) {
|
||||
$customer_data['customer_id'] = $this->model_account_customer->addCustomer($this->request->post);
|
||||
}
|
||||
|
||||
// Logged so edit customer details
|
||||
if ($this->customer->isLogged()) {
|
||||
$this->model_account_customer->editCustomer($this->customer->getId(), $this->request->post);
|
||||
}
|
||||
|
||||
// Check if current customer group requires approval
|
||||
if (!$customer_group_info['approval']) {
|
||||
$this->session->data['customer'] = $customer_data;
|
||||
}
|
||||
|
||||
$this->load->model('account/address');
|
||||
|
||||
// Payment Address
|
||||
if ($this->config->get('config_checkout_payment_address')) {
|
||||
if (isset($this->session->data['payment_address']['address_id'])) {
|
||||
$address_id = $this->session->data['payment_address']['address_id'];
|
||||
} else {
|
||||
$address_id = 0;
|
||||
}
|
||||
|
||||
if ($payment_country_info) {
|
||||
$country = $payment_country_info['name'];
|
||||
$iso_code_2 = $payment_country_info['iso_code_2'];
|
||||
$iso_code_3 = $payment_country_info['iso_code_3'];
|
||||
$address_format = $payment_country_info['address_format'];
|
||||
} else {
|
||||
$country = '';
|
||||
$iso_code_2 = '';
|
||||
$iso_code_3 = '';
|
||||
$address_format = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone_info = $this->model_localisation_zone->getZone($this->request->post['payment_zone_id']);
|
||||
|
||||
if ($zone_info) {
|
||||
$zone = $zone_info['name'];
|
||||
$zone_code = $zone_info['code'];
|
||||
} else {
|
||||
$zone = '';
|
||||
$zone_code = '';
|
||||
}
|
||||
|
||||
$payment_address_data = [
|
||||
'address_id' => $address_id,
|
||||
'firstname' => $this->request->post['firstname'],
|
||||
'lastname' => $this->request->post['lastname'],
|
||||
'company' => $this->request->post['payment_company'],
|
||||
'address_1' => $this->request->post['payment_address_1'],
|
||||
'address_2' => $this->request->post['payment_address_2'],
|
||||
'city' => $this->request->post['payment_city'],
|
||||
'postcode' => $this->request->post['payment_postcode'],
|
||||
'zone_id' => $this->request->post['payment_zone_id'],
|
||||
'zone' => $zone,
|
||||
'zone_code' => $zone_code,
|
||||
'country_id' => $this->request->post['payment_country_id'],
|
||||
'country' => $country,
|
||||
'iso_code_2' => $iso_code_2,
|
||||
'iso_code_3' => $iso_code_3,
|
||||
'address_format' => $address_format,
|
||||
'custom_field' => isset($this->request->post['payment_custom_field']) ? $this->request->post['payment_custom_field'] : []
|
||||
];
|
||||
|
||||
// Add
|
||||
if ($this->request->post['account']) {
|
||||
$payment_address_data['default'] = 1;
|
||||
|
||||
$payment_address_data['address_id'] = $this->model_account_address->addAddress($customer_data['customer_id'], $payment_address_data);
|
||||
}
|
||||
|
||||
// Edit
|
||||
if ($this->customer->isLogged() && $payment_address_data['address_id']) {
|
||||
$this->model_account_address->editAddress($payment_address_data['address_id'], $payment_address_data);
|
||||
}
|
||||
|
||||
// Requires Approval
|
||||
if (!$customer_group_info['approval']) {
|
||||
$this->session->data['payment_address'] = $payment_address_data;
|
||||
}
|
||||
}
|
||||
|
||||
// Shipping Address
|
||||
if ($this->cart->hasShipping()) {
|
||||
if (!$this->request->post['address_match']) {
|
||||
if (isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$address_id = $this->session->data['shipping_address']['address_id'];
|
||||
} else {
|
||||
$address_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->config->get('config_checkout_payment_address')) {
|
||||
$firstname = $this->request->post['firstname'];
|
||||
$lastname = $this->request->post['lastname'];
|
||||
} else {
|
||||
$firstname = $this->request->post['shipping_firstname'];
|
||||
$lastname = $this->request->post['shipping_lastname'];
|
||||
}
|
||||
|
||||
if ($shipping_country_info) {
|
||||
$country = $shipping_country_info['name'];
|
||||
$iso_code_2 = $shipping_country_info['iso_code_2'];
|
||||
$iso_code_3 = $shipping_country_info['iso_code_3'];
|
||||
$address_format = $shipping_country_info['address_format'];
|
||||
} else {
|
||||
$country = '';
|
||||
$iso_code_2 = '';
|
||||
$iso_code_3 = '';
|
||||
$address_format = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone_info = $this->model_localisation_zone->getZone($this->request->post['shipping_zone_id']);
|
||||
|
||||
if ($zone_info) {
|
||||
$zone = $zone_info['name'];
|
||||
$zone_code = $zone_info['code'];
|
||||
} else {
|
||||
$zone = '';
|
||||
$zone_code = '';
|
||||
}
|
||||
|
||||
$shipping_address_data = [
|
||||
'address_id' => $address_id,
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'company' => $this->request->post['shipping_company'],
|
||||
'address_1' => $this->request->post['shipping_address_1'],
|
||||
'address_2' => $this->request->post['shipping_address_2'],
|
||||
'city' => $this->request->post['shipping_city'],
|
||||
'postcode' => $this->request->post['shipping_postcode'],
|
||||
'zone_id' => $this->request->post['shipping_zone_id'],
|
||||
'zone' => $zone,
|
||||
'zone_code' => $zone_code,
|
||||
'country_id' => $this->request->post['shipping_country_id'],
|
||||
'country' => $country,
|
||||
'iso_code_2' => $iso_code_2,
|
||||
'iso_code_3' => $iso_code_3,
|
||||
'address_format' => $address_format,
|
||||
'custom_field' => isset($this->request->post['shipping_custom_field']) ? $this->request->post['shipping_custom_field'] : []
|
||||
];
|
||||
|
||||
// Add
|
||||
if ($this->request->post['account']) {
|
||||
if (!$this->config->get('config_checkout_payment_address')) {
|
||||
$shipping_address_data['default'] = 1;
|
||||
}
|
||||
|
||||
$shipping_address_data['address_id'] = $this->model_account_address->addAddress($customer_data['customer_id'], $shipping_address_data);
|
||||
}
|
||||
|
||||
// Edit
|
||||
if ($this->customer->isLogged() && $shipping_address_data['address_id']) {
|
||||
$this->model_account_address->editAddress($shipping_address_data['address_id'], $shipping_address_data);
|
||||
}
|
||||
|
||||
// Requires Approval
|
||||
if (!$customer_group_info['approval']) {
|
||||
$this->session->data['shipping_address'] = $shipping_address_data;
|
||||
}
|
||||
} elseif (!$customer_group_info['approval'] && $this->config->get('config_checkout_payment_address')) {
|
||||
$this->session->data['shipping_address'] = $this->session->data['payment_address'];
|
||||
|
||||
// Remove the address id so if the customer changes their mind and requires changing a different shipping address it will create a new address.
|
||||
$this->session->data['shipping_address']['address_id'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// If everything good login
|
||||
if (!$customer_group_info['approval']) {
|
||||
if ($this->request->post['account']) {
|
||||
$this->customer->login($this->request->post['email'], $this->request->post['password']);
|
||||
|
||||
// Create customer token
|
||||
$this->session->data['customer_token'] = oc_token(26);
|
||||
|
||||
$json['success'] = $this->language->get('text_success_add');
|
||||
} elseif ($this->customer->isLogged()) {
|
||||
$json['success'] = $this->language->get('text_success_edit');
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_success_guest');
|
||||
}
|
||||
} else {
|
||||
// If account needs approval we redirect to the account success / requires approval page.
|
||||
$json['redirect'] = $this->url->link('account/success', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
|
||||
// Clear any previous login attempts for unregistered accounts.
|
||||
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
265
catalog/controller/checkout/shipping_address.php
Normal file
265
catalog/controller/checkout/shipping_address.php
Normal file
@ -0,0 +1,265 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class ShippingAddress
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class ShippingAddress extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('checkout/shipping_address');
|
||||
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size'));
|
||||
$data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024);
|
||||
$data['payment_address_required'] = $this->config->get('config_checkout_payment_address');
|
||||
|
||||
$data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$this->load->model('account/address');
|
||||
|
||||
$data['addresses'] = $this->model_account_address->getAddresses($this->customer->getId());
|
||||
|
||||
if (isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$data['address_id'] = $this->session->data['shipping_address']['address_id'];
|
||||
} else {
|
||||
$data['address_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
if (isset($this->session->data['shipping_address'])) {
|
||||
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
|
||||
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
|
||||
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
|
||||
} else {
|
||||
$data['postcode'] = '';
|
||||
$data['country_id'] = (int)$this->config->get('config_country_id');
|
||||
$data['zone_id'] = '';
|
||||
}
|
||||
|
||||
// Custom Fields
|
||||
$data['custom_fields'] = [];
|
||||
|
||||
$this->load->model('account/custom_field');
|
||||
|
||||
$custom_fields = $this->model_account_custom_field->getCustomFields($this->customer->getGroupId());
|
||||
|
||||
foreach ($custom_fields as $custom_field) {
|
||||
if ($custom_field['location'] == 'address') {
|
||||
$data['custom_fields'][] = $custom_field;
|
||||
}
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('checkout/shipping_address', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('checkout/shipping_address');
|
||||
|
||||
$json = [];
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate if customer is logged in or customer session data is not set
|
||||
if (!$this->customer->isLogged() || !isset($this->session->data['customer'])) {
|
||||
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate if shipping not required
|
||||
if (!$this->cart->hasShipping()) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$keys = [
|
||||
'firstname',
|
||||
'lastname',
|
||||
'company',
|
||||
'address_1',
|
||||
'address_2',
|
||||
'city',
|
||||
'postcode',
|
||||
'country_id',
|
||||
'zone_id',
|
||||
'custom_field'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['firstname']) < 1) || (oc_strlen($this->request->post['firstname']) > 32)) {
|
||||
$json['error']['firstname'] = $this->language->get('error_firstname');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['lastname']) < 1) || (oc_strlen($this->request->post['lastname']) > 32)) {
|
||||
$json['error']['lastname'] = $this->language->get('error_lastname');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['address_1']) < 3) || (oc_strlen($this->request->post['address_1']) > 128)) {
|
||||
$json['error']['address_1'] = $this->language->get('error_address_1');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['city']) < 2) || (oc_strlen($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((int)$this->request->post['country_id']);
|
||||
|
||||
if ($country_info && $country_info['postcode_required'] && (oc_strlen($this->request->post['postcode']) < 2 || oc_strlen($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 ($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->customer->getGroupId());
|
||||
|
||||
foreach ($custom_fields as $custom_field) {
|
||||
if ($custom_field['location'] == 'address') {
|
||||
if ($custom_field['required'] && empty($this->request->post['custom_field'][$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']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $this->request->post['custom_field'][$custom_field['custom_field_id']])) {
|
||||
$json['error']['custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// If no default address add it
|
||||
$address_id = $this->customer->getAddressId();
|
||||
|
||||
if (!$address_id) {
|
||||
$this->request->post['default'] = 1;
|
||||
}
|
||||
|
||||
$this->load->model('account/address');
|
||||
|
||||
$json['address_id'] = $this->model_account_address->addAddress($this->customer->getId(), $this->request->post);
|
||||
|
||||
$json['addresses'] = $this->model_account_address->getAddresses($this->customer->getId());
|
||||
|
||||
$this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getId(), $json['address_id']);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
// Clear payment and shipping 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']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function address(): void {
|
||||
$this->load->language('checkout/shipping_address');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['address_id'])) {
|
||||
$address_id = (int)$this->request->get['address_id'];
|
||||
} else {
|
||||
$address_id = 0;
|
||||
}
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate if customer is logged in or customer session data is not set
|
||||
if (!$this->customer->isLogged() || !isset($this->session->data['customer'])) {
|
||||
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate if shipping is not required
|
||||
if (!$this->cart->hasShipping()) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('account/address');
|
||||
|
||||
$address_info = $this->model_account_address->getAddress($this->customer->getId(), $address_id);
|
||||
|
||||
if (!$address_info) {
|
||||
$json['error'] = $this->language->get('error_address');
|
||||
|
||||
unset($this->session->data['shipping_address']);
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['shipping_address'] = $address_info;
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
// Clear payment and shipping 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']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
150
catalog/controller/checkout/shipping_method.php
Normal file
150
catalog/controller/checkout/shipping_method.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class ShippingMethod
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class ShippingMethod extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('checkout/shipping_method');
|
||||
|
||||
if (isset($this->session->data['shipping_method'])) {
|
||||
$data['shipping_method'] = $this->session->data['shipping_method']['name'];
|
||||
$data['code'] = $this->session->data['shipping_method']['code'];
|
||||
} else {
|
||||
$data['shipping_method'] = '';
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('checkout/shipping_method', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function quote(): void {
|
||||
$this->load->language('checkout/shipping_method');
|
||||
|
||||
$json = [];
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Validate if customer data is set
|
||||
if (!isset($this->session->data['customer'])) {
|
||||
$json['error'] = $this->language->get('error_customer');
|
||||
}
|
||||
|
||||
// Validate if payment address is set if required in settings
|
||||
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
|
||||
$json['error'] = $this->language->get('error_payment_address');
|
||||
}
|
||||
|
||||
// Validate if shipping not required. If not the customer should not have reached this page.
|
||||
if ($this->cart->hasShipping() && !isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$json['error'] = $this->language->get('error_shipping_address');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Shipping methods
|
||||
$this->load->model('checkout/shipping_method');
|
||||
|
||||
$shipping_methods = $this->model_checkout_shipping_method->getMethods($this->session->data['shipping_address']);
|
||||
|
||||
if ($shipping_methods) {
|
||||
$json['shipping_methods'] = $this->session->data['shipping_methods'] = $shipping_methods;
|
||||
} else {
|
||||
$json['error'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('checkout/shipping_method');
|
||||
|
||||
$json = [];
|
||||
|
||||
// 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', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
// Validate minimum quantity requirements.
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product['minimum']) {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Validate if customer is logged in or customer session data is not set
|
||||
if (!isset($this->session->data['customer'])) {
|
||||
$json['error'] = $this->language->get('error_customer');
|
||||
}
|
||||
|
||||
// Validate if payment address is set if required in settings
|
||||
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
|
||||
$json['error'] = $this->language->get('error_payment_address');
|
||||
}
|
||||
|
||||
// Validate if shipping not required. If not the customer should not have reached this page.
|
||||
if ($this->cart->hasShipping() && !isset($this->session->data['shipping_address']['address_id'])) {
|
||||
$json['error'] = $this->language->get('error_shipping_address');
|
||||
}
|
||||
|
||||
if (isset($this->request->post['shipping_method'])) {
|
||||
$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'] = $this->language->get('error_shipping_method');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_shipping_method');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
// Clear payment 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));
|
||||
}
|
||||
}
|
72
catalog/controller/checkout/success.php
Normal file
72
catalog/controller/checkout/success.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class Success
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class Success extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('checkout/success');
|
||||
|
||||
if (isset($this->session->data['order_id'])) {
|
||||
$this->cart->clear();
|
||||
|
||||
unset($this->session->data['order_id']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['comment']);
|
||||
unset($this->session->data['agree']);
|
||||
unset($this->session->data['coupon']);
|
||||
unset($this->session->data['reward']);
|
||||
unset($this->session->data['voucher']);
|
||||
unset($this->session->data['vouchers']);
|
||||
}
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_basket'),
|
||||
'href' => $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_checkout'),
|
||||
'href' => $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_success'),
|
||||
'href' => $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$data['text_message'] = sprintf($this->language->get('text_customer'), $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']), $this->url->link('account/order', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']), $this->url->link('account/download', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
} else {
|
||||
$data['text_message'] = sprintf($this->language->get('text_guest'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
224
catalog/controller/checkout/voucher.php
Normal file
224
catalog/controller/checkout/voucher.php
Normal file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Checkout;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Checkout
|
||||
*/
|
||||
class Voucher extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('checkout/voucher');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (!isset($this->session->data['vouchers'])) {
|
||||
$this->session->data['vouchers'] = [];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_account'),
|
||||
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_voucher'),
|
||||
'href' => $this->url->link('checkout/voucher', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['help_amount'] = sprintf($this->language->get('help_amount'), $this->currency->format($this->config->get('config_voucher_min'), $this->session->data['currency']), $this->currency->format($this->config->get('config_voucher_max'), $this->session->data['currency']));
|
||||
|
||||
$this->session->data['voucher_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
|
||||
|
||||
$data['save'] = $this->url->link('checkout/voucher.add', 'language=' . $this->config->get('config_language') . '&voucher_token=' . $this->session->data['voucher_token']);
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$data['from_name'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
|
||||
} else {
|
||||
$data['from_name'] = '';
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$data['from_email'] = $this->customer->getEmail();
|
||||
} else {
|
||||
$data['from_email'] = '';
|
||||
}
|
||||
|
||||
$data['amount'] = $this->currency->format($this->config->get('config_voucher_min'), $this->config->get('config_currency'), false, false);
|
||||
|
||||
$this->load->model('checkout/voucher_theme');
|
||||
|
||||
$data['voucher_themes'] = $this->model_checkout_voucher_theme->getVoucherThemes();
|
||||
|
||||
$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/voucher', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function add(): void {
|
||||
$this->load->language('checkout/voucher');
|
||||
|
||||
$json = [];
|
||||
|
||||
$keys = [
|
||||
'to_name',
|
||||
'to_email',
|
||||
'from_name',
|
||||
'from_email',
|
||||
'voucher_theme_id',
|
||||
'amount',
|
||||
'agree'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['voucher_token']) || !isset($this->session->data['voucher_token']) || ($this->session->data['voucher_token'] != $this->request->get['voucher_token'])) {
|
||||
$json['redirect'] = $this->url->link('checkout/voucher', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['to_name']) < 1) || (oc_strlen($this->request->post['to_name']) > 64)) {
|
||||
$json['error']['to_name'] = $this->language->get('error_to_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['to_email']) > 96) || !filter_var($this->request->post['to_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$json['error']['to_email'] = $this->language->get('error_email');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['from_name']) < 1) || (oc_strlen($this->request->post['from_name']) > 64)) {
|
||||
$json['error']['from_name'] = $this->language->get('error_from_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['from_email']) > 96) || !filter_var($this->request->post['from_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$json['error']['from_email'] = $this->language->get('error_email');
|
||||
}
|
||||
|
||||
if (!$this->request->post['voucher_theme_id']) {
|
||||
$json['error']['theme'] = $this->language->get('error_theme');
|
||||
}
|
||||
|
||||
if (($this->currency->convert((int)$this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) {
|
||||
$json['error']['amount'] = sprintf($this->language->get('error_amount'), $this->currency->format($this->config->get('config_voucher_min'), $this->session->data['currency']), $this->currency->format($this->config->get('config_voucher_max'), $this->session->data['currency']));
|
||||
}
|
||||
|
||||
if (!isset($this->request->post['agree'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_agree');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$code = oc_token(10);
|
||||
|
||||
$this->session->data['vouchers'][] = [
|
||||
'code' => $code,
|
||||
'description' => sprintf($this->language->get('text_for'), $this->currency->format($this->request->post['amount'], $this->session->data['currency'], 1.0), $this->request->post['to_name']),
|
||||
'to_name' => $this->request->post['to_name'],
|
||||
'to_email' => $this->request->post['to_email'],
|
||||
'from_name' => $this->request->post['from_name'],
|
||||
'from_email' => $this->request->post['from_email'],
|
||||
'voucher_theme_id' => $this->request->post['voucher_theme_id'],
|
||||
'message' => $this->request->post['message'],
|
||||
'amount' => $this->currency->convert((int)$this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency'))
|
||||
];
|
||||
|
||||
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']);
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/voucher.success', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function remove(): void {
|
||||
$this->load->language('checkout/voucher');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['key'])) {
|
||||
$key = $this->request->get['key'];
|
||||
} else {
|
||||
$key = '';
|
||||
}
|
||||
|
||||
if (!isset($this->session->data['vouchers'][$key])) {
|
||||
$json['error'] = $this->language->get('error_voucher');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
unset($this->session->data['vouchers'][$key]);
|
||||
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->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function success(): void {
|
||||
$this->load->language('checkout/voucher');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('checkout/voucher', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['continue'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user