first commit

This commit is contained in:
sujan
2024-08-06 18:06:00 +05:45
commit a2fa49071a
2745 changed files with 391199 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Account
*
* @package Opencart\Catalog\Controller\Account
*/
class Account extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/account');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
$data['edit'] = $this->url->link('account/edit', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['password'] = $this->url->link('account/password', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['address'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['payment_method'] = $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['wishlist'] = $this->url->link('account/wishlist', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['order'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['subscription'] = $this->url->link('account/subscription', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['download'] = $this->url->link('account/download', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
if ($this->config->get('total_reward_status')) {
$data['reward'] = $this->url->link('account/reward', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
} else {
$data['reward'] = '';
}
$data['return'] = $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['transaction'] = $this->url->link('account/transaction', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['newsletter'] = $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
if ($this->config->get('config_affiliate_status')) {
$data['affiliate'] = $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$this->load->model('account/affiliate');
$affiliate_info = $this->model_account_affiliate->getAffiliate($this->customer->getId());
if ($affiliate_info) {
$data['tracking'] = $this->url->link('account/tracking', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
} else {
$data['tracking'] = '';
}
} else {
$data['affiliate'] = '';
}
$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('account/account', $data));
}
}

View File

@@ -0,0 +1,490 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Address
*
* @package Opencart\Catalog\Controller\Account
*/
class Address extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/address');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->document->setTitle($this->language->get('heading_title'));
$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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/address', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
$data['add'] = $this->url->link('account/address.form', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['list'] = $this->getList();
$data['language'] = $this->config->get('config_language');
$data['customer_token'] = $this->session->data['customer_token'];
$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('account/address', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('account/address');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
$data['addresses'] = [];
$this->load->model('account/address');
$results = $this->model_account_address->getAddresses($this->customer->getId());
foreach ($results as $result) {
$find = [
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
];
$replace = [
'firstname' => $result['firstname'],
'lastname' => $result['lastname'],
'company' => $result['company'],
'address_1' => $result['address_1'],
'address_2' => $result['address_2'],
'city' => $result['city'],
'postcode' => $result['postcode'],
'zone' => $result['zone'],
'zone_code' => $result['zone_code'],
'country' => $result['country']
];
$data['addresses'][] = [
'address_id' => $result['address_id'],
'address' => str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $result['address_format'])))),
'edit' => $this->url->link('account/address.form', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&address_id=' . $result['address_id']),
'delete' => $this->url->link('account/address.delete', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&address_id=' . $result['address_id'])
];
}
return $this->load->view('account/address_list', $data);
}
/**
* @return void
*/
public function form(): void {
$this->load->language('account/address');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->document->setTitle($this->language->get('heading_title'));
$data['text_address'] = !isset($this->request->get['address_id']) ? $this->language->get('text_address_add') : $this->language->get('text_address_edit');
$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['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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/address', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
if (!isset($this->request->get['address_id'])) {
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_address_add'),
'href' => $this->url->link('account/address.form', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
} else {
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_address_edit'),
'href' => $this->url->link('account/address.form', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&address_id=' . $this->request->get['address_id'])
];
}
if (!isset($this->request->get['address_id'])) {
$data['save'] = $this->url->link('account/address.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
} else {
$data['save'] = $this->url->link('account/address.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&address_id=' . $this->request->get['address_id']);
}
$data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language'));
if (isset($this->request->get['address_id'])) {
$this->load->model('account/address');
$address_info = $this->model_account_address->getAddress($this->customer->getId(), $this->request->get['address_id']);
}
if (!empty($address_info)) {
$data['firstname'] = $address_info['firstname'];
} else {
$data['firstname'] = '';
}
if (!empty($address_info)) {
$data['lastname'] = $address_info['lastname'];
} else {
$data['lastname'] = '';
}
if (!empty($address_info)) {
$data['company'] = $address_info['company'];
} else {
$data['company'] = '';
}
if (!empty($address_info)) {
$data['address_1'] = $address_info['address_1'];
} else {
$data['address_1'] = '';
}
if (!empty($address_info)) {
$data['address_2'] = $address_info['address_2'];
} else {
$data['address_2'] = '';
}
if (!empty($address_info)) {
$data['postcode'] = $address_info['postcode'];
} else {
$data['postcode'] = '';
}
if (!empty($address_info)) {
$data['city'] = $address_info['city'];
} else {
$data['city'] = '';
}
if (!empty($address_info)) {
$data['country_id'] = $address_info['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (!empty($address_info)) {
$data['zone_id'] = $address_info['zone_id'];
} else {
$data['zone_id'] = '';
}
$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;
}
}
if (!empty($address_info)) {
$data['address_custom_field'] = $address_info['custom_field'];
} else {
$data['address_custom_field'] = [];
}
if (isset($this->request->get['address_id'])) {
$data['default'] = $address_info['default'];
} else {
$data['default'] = false;
}
$data['back'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['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('account/address_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('account/address');
$json = [];
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$keys = [
'firstname',
'lastname',
'address_1',
'address_2',
'city',
'postcode',
'country_id',
'zone_id'
];
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 (isset($this->request->get['address_id']) && ($this->customer->getAddressId() == $this->request->get['address_id']) && !$this->request->post['default']) {
$json['error'] = $this->language->get('error_default');
}
}
if (!$json) {
$this->load->model('account/address');
// Add Address
if (!isset($this->request->get['address_id'])) {
$this->model_account_address->addAddress($this->customer->getId(), $this->request->post);
$this->session->data['success'] = $this->language->get('text_add');
}
// Edit Address
if (isset($this->request->get['address_id'])) {
$this->model_account_address->editAddress($this->request->get['address_id'], $this->request->post);
// If address is in session update it.
if (isset($this->session->data['shipping_address']) && ($this->session->data['shipping_address']['address_id'] == $this->request->get['address_id'])) {
$this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getId(), $this->request->get['address_id']);
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 address is in session update it.
if (isset($this->session->data['payment_address']) && ($this->session->data['payment_address']['address_id'] == $this->request->get['address_id'])) {
$this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getId(), $this->request->get['address_id']);
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->session->data['success'] = $this->language->get('text_edit');
}
$json['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('account/address');
$json = [];
if (isset($this->request->get['address_id'])) {
$address_id = $this->request->get['address_id'];
} else {
$address_id = 0;
}
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
if ($this->customer->getAddressId() == $address_id) {
$json['error'] = $this->language->get('error_default');
}
$this->load->model('account/address');
if ($this->model_account_address->getTotalAddresses($this->customer->getId()) == 1) {
$json['error'] = $this->language->get('error_delete');
}
$this->load->model('account/subscription');
$subscription_total = $this->model_account_subscription->getTotalSubscriptionByShippingAddressId($address_id);
if ($subscription_total) {
$json['error'] = sprintf($this->language->get('error_subscription'), $subscription_total);
}
$subscription_total = $this->model_account_subscription->getTotalSubscriptionByPaymentAddressId($address_id);
if ($subscription_total) {
$json['error'] = sprintf($this->language->get('error_subscription'), $subscription_total);
}
}
if (!$json) {
// Delete address from database.
$this->model_account_address->deleteAddress($address_id);
// Delete address from session.
if (isset($this->session->data['shipping_address']['address_id']) && ($this->session->data['shipping_address']['address_id'] == $address_id)) {
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']);
}
// Delete address from session.
if (isset($this->session->data['payment_address']['address_id']) && ($this->session->data['payment_address']['address_id'] == $address_id)) {
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']);
}
$json['success'] = $this->language->get('text_delete');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,265 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Affiliate
*
* @package Opencart\Catalog\Controller\Account
*/
class Affiliate extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/affiliate');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->customer->logout();
$this->session->data['redirect'] = $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->document->setTitle($this->language->get('heading_title'));
$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['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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_affiliate'),
'href' => $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['save'] = $this->url->link('account/affiliate.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language'));
$this->load->model('account/affiliate');
$affiliate_info = $this->model_account_affiliate->getAffiliate($this->customer->getId());
if (!empty($affiliate_info)) {
$data['company'] = $affiliate_info['company'];
} else {
$data['company'] = '';
}
if (!empty($affiliate_info)) {
$data['website'] = $affiliate_info['website'];
} else {
$data['website'] = '';
}
if (!empty($affiliate_info)) {
$data['tax'] = $affiliate_info['tax'];
} else {
$data['tax'] = '';
}
if (!empty($affiliate_info)) {
$data['payment_method'] = $affiliate_info['payment_method'];
} else {
$data['payment_method'] = 'cheque';
}
if (!empty($affiliate_info)) {
$data['cheque'] = $affiliate_info['cheque'];
} else {
$data['cheque'] = '';
}
if (!empty($affiliate_info)) {
$data['paypal'] = $affiliate_info['paypal'];
} else {
$data['paypal'] = '';
}
if (!empty($affiliate_info)) {
$data['bank_name'] = $affiliate_info['bank_name'];
} else {
$data['bank_name'] = '';
}
if (!empty($affiliate_info)) {
$data['bank_branch_number'] = $affiliate_info['bank_branch_number'];
} else {
$data['bank_branch_number'] = '';
}
if (!empty($affiliate_info)) {
$data['bank_swift_code'] = $affiliate_info['bank_swift_code'];
} else {
$data['bank_swift_code'] = '';
}
if (!empty($affiliate_info)) {
$data['bank_account_name'] = $affiliate_info['bank_account_name'];
} else {
$data['bank_account_name'] = '';
}
if (!empty($affiliate_info)) {
$data['bank_account_number'] = $affiliate_info['bank_account_number'];
} else {
$data['bank_account_number'] = '';
}
// Custom Fields
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields((int)$this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'affiliate') {
$data['custom_fields'][] = $custom_field;
}
}
if (!empty($affiliate_info)) {
$data['affiliate_custom_field'] = json_decode($affiliate_info['custom_field'], true);
} else {
$data['affiliate_custom_field'] = [];
}
$affiliate_info = $this->model_account_affiliate->getAffiliate($this->customer->getId());
if (!$affiliate_info && $this->config->get('config_affiliate_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_affiliate_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_affiliate_id')), $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
$data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['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('account/affiliate', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('account/affiliate');
$json = [];
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$this->config->get('config_affiliate_status')) {
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
$keys = [
'payment_method',
'cheque',
'paypal',
'bank_account_name',
'bank_account_number',
'agree'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
if (!$json) {
// Payment validation
if (empty($this->request->post['payment_method'])) {
$json['error']['payment_method'] = $this->language->get('error_payment_method');
}
if ($this->request->post['payment_method'] == 'cheque' && !$this->request->post['cheque']) {
$json['error']['cheque'] = $this->language->get('error_cheque');
} elseif ($this->request->post['payment_method'] == 'paypal' && ((oc_strlen($this->request->post['paypal']) > 96) || !filter_var($this->request->post['paypal'], FILTER_VALIDATE_EMAIL))) {
$json['error']['paypal'] = $this->language->get('error_paypal');
} elseif ($this->request->post['payment_method'] == 'bank') {
if ($this->request->post['bank_account_name'] == '') {
$json['error']['bank_account_name'] = $this->language->get('error_bank_account_name');
}
if ($this->request->post['bank_account_number'] == '') {
$json['error']['bank_account_number'] = $this->language->get('error_bank_account_number');
}
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields((int)$this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'affiliate') {
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']);
}
}
}
// Validate agree only if customer not already an affiliate
$this->load->model('account/affiliate');
$affiliate_info = $this->model_account_affiliate->getAffiliate($this->customer->getId());
if (!$affiliate_info) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_affiliate_id'));
if ($information_info && !$this->request->post['agree']) {
$json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
}
if (!$json) {
if (!$affiliate_info) {
$this->model_account_affiliate->addAffiliate($this->customer->getId(), $this->request->post);
} else {
$this->model_account_affiliate->editAffiliate($this->customer->getId(), $this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Custom Field
*
* @package Opencart\Catalog\Controller\Account
*/
class CustomField extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$json = [];
// Customer Group
if (isset($this->request->get['customer_group_id']) && in_array((int)$this->request->get['customer_group_id'], (array)$this->config->get('config_customer_group_display'))) {
$customer_group_id = (int)$this->request->get['customer_group_id'];
} else {
$customer_group_id = (int)$this->config->get('config_customer_group_id');
}
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = [
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
];
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,162 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Download
*
* @package Opencart\Catalog\Controller\Account
*/
class Download extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/download');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/download', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_downloads'),
'href' => $this->url->link('account/download', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$this->load->model('account/download');
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['downloads'] = [];
$download_total = $this->model_account_download->getTotalDownloads();
$results = $this->model_account_download->getDownloads(($page - 1) * $limit, $limit);
foreach ($results as $result) {
if (is_file(DIR_DOWNLOAD . $result['filename'])) {
$size = filesize(DIR_DOWNLOAD . $result['filename']);
$i = 0;
$suffix = [
'B',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
];
while (($size / 1024) > 1) {
$size = $size / 1024;
$i++;
}
$data['downloads'][] = [
'order_id' => $result['order_id'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'name' => $result['name'],
'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
'href' => $this->url->link('account/download.download', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&download_id=' . $result['download_id'])
];
}
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $download_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/download', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($download_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($download_total - $limit)) ? $download_total : ((($page - 1) * $limit) + $limit), $download_total, ceil($download_total / $limit));
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/download', $data));
}
/**
* @return void
*/
public function download(): void {
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/download', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->load->model('account/download');
if (isset($this->request->get['download_id'])) {
$download_id = (int)$this->request->get['download_id'];
} else {
$download_id = 0;
}
$download_info = $this->model_account_download->getDownload($download_id);
if ($download_info) {
$file = DIR_DOWNLOAD . $download_info['filename'];
$mask = basename($download_info['mask']);
if (!headers_sent()) {
if (is_file($file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
if (ob_get_level()) {
ob_end_clean();
}
readfile($file, 'rb');
$this->model_account_download->addReport($download_id, $this->request->server['REMOTE_ADDR']);
exit();
} else {
exit(sprintf($this->language->get('error_not_found'), basename($file)));
}
} else {
exit($this->language->get('error_headers_sent'));
}
} else {
$this->response->redirect($this->url->link('account/download', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
}
}
}

View File

@@ -0,0 +1,185 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Edit
*
* @package Opencart\Catalog\Controller\Account
*/
class Edit extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/edit');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/edit', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_edit'),
'href' => $this->url->link('account/edit', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$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['config_telephone_display'] = $this->config->get('config_telephone_display');
$data['config_telephone_required'] = $this->config->get('config_telephone_required');
$data['save'] = $this->url->link('account/edit.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language'));
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomer($this->customer->getId());
$data['firstname'] = $customer_info['firstname'];
$data['lastname'] = $customer_info['lastname'];
$data['email'] = $customer_info['email'];
$data['telephone'] = $customer_info['telephone'];
// 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'] == 'account') {
$data['custom_fields'][] = $custom_field;
}
}
if (isset($customer_info)) {
$data['account_custom_field'] = json_decode($customer_info['custom_field'], true);
} else {
$data['account_custom_field'] = [];
}
$data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['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('account/edit', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('account/edit');
$json = [];
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/edit', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$keys = [
'firstname',
'lastname',
'email',
'telephone'
];
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['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->customer->getEmail() != $this->request->post['email']) && $this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$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($this->customer->getGroupId());
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'account') {
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) {
// Update customer in db
$this->model_account_customer->editCustomer($this->customer->getId(), $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
// Update customer session details
$this->session->data['customer'] = [
'customer_id' => $this->customer->getId(),
'customer_group_id' => $this->customer->getGroupId(),
'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'] : []
];
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,239 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Forgotten
*
* @package Opencart\Catalog\Controller\Account
*/
class Forgotten extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/forgotten');
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_forgotten'),
'href' => $this->url->link('account/forgotten', 'language=' . $this->config->get('config_language'))
];
$data['confirm'] = $this->url->link('account/forgotten.confirm', 'language=' . $this->config->get('config_language'));
$data['back'] = $this->url->link('account/login', '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('account/forgotten', $data));
}
/**
* @return void
*/
public function confirm(): void {
$this->load->language('account/forgotten');
$json = [];
if ($this->customer->isLogged()) {
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
if (!$json) {
$keys = ['email'];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
if (!$customer_info) {
$json['error'] = $this->language->get('error_not_found');
}
}
if (!$json) {
$this->model_account_customer->editCode($this->request->post['email'], oc_token(40));
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function reset(): void {
$this->load->language('account/forgotten');
if (isset($this->request->get['email'])) {
$email = (string)$this->request->get['email'];
} else {
$email = '';
}
if (isset($this->request->get['code'])) {
$code = (string)$this->request->get['code'];
} else {
$code = '';
}
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
}
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomerByEmail($email);
if (!$customer_info || !$customer_info['code'] || $customer_info['code'] !== $code) {
$this->model_account_customer->editCode($email, '');
$this->session->data['error'] = $this->language->get('error_code');
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->document->setTitle($this->language->get('heading_reset'));
$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('heading_title'),
'href' => $this->url->link('account/forgotten.reset', 'language=' . $this->config->get('config_language'))
];
$this->session->data['reset_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
$data['save'] = $this->url->link('account/forgotten.password', 'language=' . $this->config->get('config_language') . '&email=' . urlencode($email) . '&code=' . $code . '&reset_token=' . $this->session->data['reset_token']);
$data['back'] = $this->url->link('account/login', '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('account/forgotten_reset', $data));
}
/**
* @return void
*/
public function password(): void {
$this->load->language('account/forgotten');
$json = [];
if (isset($this->request->get['email'])) {
$email = (string)$this->request->get['email'];
} else {
$email = '';
}
if (isset($this->request->get['code'])) {
$code = (string)$this->request->get['code'];
} else {
$code = '';
}
if ($this->customer->isLogged()) {
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
if (!isset($this->request->get['reset_token']) || !isset($this->session->data['reset_token']) || ($this->request->get['reset_token'] != $this->session->data['reset_token'])) {
$this->session->data['error'] = $this->language->get('error_session');
$json['redirect'] = $this->url->link('account/forgotten', 'language=' . $this->config->get('config_language'), true);
}
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomerByEmail($email);
if (!$customer_info || !$customer_info['code'] || $customer_info['code'] !== $code) {
// Reset token
$this->model_account_customer->editCode($email, '');
$this->session->data['error'] = $this->language->get('error_code');
$json['redirect'] = $this->url->link('account/forgotten', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$keys = [
'password',
'confirm'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
if ((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['confirm'] != $this->request->post['password']) {
$json['error']['confirm'] = $this->language->get('error_confirm');
}
}
if (!$json) {
$this->model_account_customer->editPassword($customer_info['email'], $this->request->post['password']);
$this->session->data['success'] = $this->language->get('text_success');
unset($this->session->data['reset_token']);
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,277 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Login
*
* @package Opencart\Catalog\Controller\Account
*/
class Login extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
// If already logged in and has matching token then redirect to account page
if ($this->customer->isLogged() && isset($this->request->get['customer_token']) && isset($this->session->data['customer_token']) && ($this->request->get['customer_token'] == $this->session->data['customer_token'])) {
$this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
}
$this->load->language('account/login');
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_login'),
'href' => $this->url->link('account/login', 'language=' . $this->config->get('config_language'))
];
// Check to see if user is using incorrect token
if (isset($this->session->data['customer_token'])) {
$data['error_warning'] = $this->language->get('error_token');
$this->customer->logout();
unset($this->session->data['customer']);
unset($this->session->data['shipping_address']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_address']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
unset($this->session->data['reward']);
unset($this->session->data['voucher']);
unset($this->session->data['vouchers']);
unset($this->session->data['customer_token']);
} elseif (isset($this->session->data['error'])) {
$data['error_warning'] = $this->session->data['error'];
unset($this->session->data['error']);
} else {
$data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
if (isset($this->session->data['redirect'])) {
$data['redirect'] = $this->session->data['redirect'];
unset($this->session->data['redirect']);
} elseif (isset($this->request->get['redirect'])) {
$data['redirect'] = urldecode($this->request->get['redirect']);
} else {
$data['redirect'] = '';
}
$this->session->data['login_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
$data['login'] = $this->url->link('account/login.login', 'language=' . $this->config->get('config_language') . '&login_token=' . $this->session->data['login_token']);
$data['register'] = $this->url->link('account/register', 'language=' . $this->config->get('config_language'));
$data['forgotten'] = $this->url->link('account/forgotten', '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('account/login', $data));
}
/**
* @return void
*/
public function login(): void {
$this->load->language('account/login');
$json = [];
$this->customer->logout();
if (!isset($this->request->get['login_token']) || !isset($this->session->data['login_token']) || ($this->request->get['login_token'] != $this->session->data['login_token'])) {
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$keys = [
'email',
'password',
'redirect'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
// Check how many login attempts have been made.
$this->load->model('account/customer');
$login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
if ($login_info && ($login_info['total'] >= $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
$json['error']['warning'] = $this->language->get('error_attempts');
}
// Check if customer has been approved.
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
if ($customer_info && !$customer_info['status']) {
$json['error']['warning'] = $this->language->get('error_approved');
} elseif (!$this->customer->login($this->request->post['email'], html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8'))) {
$json['error']['warning'] = $this->language->get('error_login');
$this->model_account_customer->addLoginAttempt($this->request->post['email']);
}
}
if (!$json) {
// Add customer details into session
$this->session->data['customer'] = [
'customer_id' => $customer_info['customer_id'],
'customer_group_id' => $customer_info['customer_group_id'],
'firstname' => $customer_info['firstname'],
'lastname' => $customer_info['lastname'],
'email' => $customer_info['email'],
'telephone' => $customer_info['telephone'],
'custom_field' => $customer_info['custom_field']
];
unset($this->session->data['order_id']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
// Wishlist
if (isset($this->session->data['wishlist']) && is_array($this->session->data['wishlist'])) {
$this->load->model('account/wishlist');
foreach ($this->session->data['wishlist'] as $key => $product_id) {
$this->model_account_wishlist->addWishlist($product_id);
unset($this->session->data['wishlist'][$key]);
}
}
// Log the IP info
$this->model_account_customer->addLogin($this->customer->getId(), $this->request->server['REMOTE_ADDR']);
// Create customer token
$this->session->data['customer_token'] = oc_token(26);
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
// Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false)) {
$json['redirect'] = str_replace('&amp;', '&', $this->request->post['redirect']) . '&customer_token=' . $this->session->data['customer_token'];
} else {
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function token(): void {
$this->load->language('account/login');
if (isset($this->request->get['email'])) {
$email = $this->request->get['email'];
} else {
$email = '';
}
if (isset($this->request->get['login_token'])) {
$token = $this->request->get['login_token'];
} else {
$token = '';
}
// Login override for admin users
$this->customer->logout();
$this->cart->clear();
unset($this->session->data['order_id']);
unset($this->session->data['payment_address']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['shipping_address']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['comment']);
unset($this->session->data['coupon']);
unset($this->session->data['reward']);
unset($this->session->data['voucher']);
unset($this->session->data['vouchers']);
unset($this->session->data['customer_token']);
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomerByEmail($email);
if ($customer_info && $customer_info['token'] && $customer_info['token'] == $token && $this->customer->login($customer_info['email'], '', true)) {
// Add customer details into session
$this->session->data['customer'] = [
'customer_id' => $customer_info['customer_id'],
'customer_group_id' => $customer_info['customer_group_id'],
'firstname' => $customer_info['firstname'],
'lastname' => $customer_info['lastname'],
'email' => $customer_info['email'],
'telephone' => $customer_info['telephone'],
'custom_field' => $customer_info['custom_field']
];
// Default Addresses
$this->load->model('account/address');
$address_info = $this->model_account_address->getAddress($this->customer->getId(), $this->customer->getAddressId());
if ($address_info) {
$this->session->data['shipping_address'] = $address_info;
}
if ($this->config->get('config_tax_customer') && $address_info) {
$this->session->data[$this->config->get('config_tax_customer') . '_address'] = $address_info;
}
$this->model_account_customer->editToken($email, '');
// Create customer token
$this->session->data['customer_token'] = oc_token(26);
$this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
} else {
$this->session->data['error'] = $this->language->get('error_login');
$this->model_account_customer->editToken($email, '');
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Logout
*
* @package Opencart\Catalog\Controller\Account
*/
class Logout extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
if ($this->customer->isLogged()) {
$this->customer->logout();
unset($this->session->data['customer']);
unset($this->session->data['shipping_address']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_address']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
unset($this->session->data['reward']);
unset($this->session->data['voucher']);
unset($this->session->data['vouchers']);
unset($this->session->data['customer_token']);
$this->response->redirect($this->url->link('account/logout', 'language=' . $this->config->get('config_language')));
}
$this->load->language('account/logout');
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_logout'),
'href' => $this->url->link('account/logout', '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));
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Newsletter
*
* @package Opencart\Catalog\Controller\Account
*/
class Newsletter extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/newsletter');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_newsletter'),
'href' => $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['save'] = $this->url->link('account/newsletter.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['newsletter'] = $this->customer->getNewsletter();
$data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/newsletter', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('account/newsletter');
$json = [];
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$this->load->model('account/customer');
$this->model_account_customer->editNewsletter($this->request->post['newsletter']);
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,531 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Order
*
* @package Opencart\Catalog\Controller\Account
*/
class Order extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/order');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->document->setTitle($this->language->get('heading_title'));
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/order', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
];
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['orders'] = [];
$this->load->model('account/order');
$this->load->model('localisation/order_status');
$order_total = $this->model_account_order->getTotalOrders();
$results = $this->model_account_order->getOrders(($page - 1) * $limit, $limit);
foreach ($results as $result) {
$order_status_info = $this->model_localisation_order_status->getOrderStatus($result['order_status_id']);
if ($order_status_info) {
$order_status = $order_status_info['name'];
} else {
$order_status = '';
}
$product_total = $this->model_account_order->getTotalProductsByOrderId($result['order_id']);
$voucher_total = $this->model_account_order->getTotalVouchersByOrderId($result['order_id']);
$data['orders'][] = [
'order_id' => $result['order_id'],
'name' => $result['firstname'] . ' ' . $result['lastname'],
'status' => $order_status,
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'products' => ($product_total + $voucher_total),
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'view' => $this->url->link('account/order.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $result['order_id']),
];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $order_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/order', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($order_total - $limit)) ? $order_total : ((($page - 1) * $limit) + $limit), $order_total, ceil($order_total / $limit));
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/order_list', $data));
}
/**
* @return object|\Opencart\System\Engine\Action|null
*/
public function info(): object|null {
$this->load->language('account/order');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
if (isset($this->request->get['order_id'])) {
$order_id = (int)$this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('account/order');
$order_info = $this->model_account_order->getOrder($order_id);
if ($order_info) {
$heading_title = sprintf($this->language->get('text_order'), $order_info['order_id']);
$this->document->setTitle($heading_title);
$data['heading_title'] = $heading_title;
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/order', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
];
$data['breadcrumbs'][] = [
'text' => $heading_title,
'href' => $this->url->link('account/order.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $order_id . $url)
];
if ($order_info['invoice_no']) {
$data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$data['invoice_no'] = '';
}
$data['order_id'] = $order_id;
$this->load->model('localisation/order_status');
$order_status_info = $this->model_localisation_order_status->getOrderStatus($order_info['order_status_id']);
if ($order_status_info) {
$data['order_status'] = $order_status_info['name'];
} else {
$data['order_status'] = '';
}
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
// Payment Address
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = [
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
];
$replace = [
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
];
$data['payment_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
$data['payment_method'] = $order_info['payment_method']['name'];
// Shipping Address
if ($order_info['shipping_method']) {
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = [
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
];
$replace = [
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
];
$data['shipping_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
$data['shipping_method'] = $order_info['shipping_method']['name'];
} else {
$data['shipping_address'] = '';
$data['shipping_method'] = '';
}
$this->load->model('account/subscription');
$this->load->model('catalog/product');
$this->load->model('tool/upload');
// Products
$data['products'] = [];
$products = $this->model_account_order->getProducts($order_id);
foreach ($products as $product) {
$option_data = [];
$options = $this->model_account_order->getOptions($order_id, $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = [
'name' => $option['name'],
'value' => (oc_strlen($value) > 20 ? oc_substr($value, 0, 20) . '..' : $value)
];
}
$description = '';
$subscription_info = $this->model_account_order->getSubscription($order_id, $product['order_product_id']);
if ($subscription_info) {
if ($subscription_info['trial_status']) {
$trial_price = $this->currency->format($subscription_info['trial_price'] + ($this->config->get('config_tax') ? $subscription_info['trial_tax'] : 0), $order_info['currency_code'], $order_info['currency_value']);
$trial_cycle = $subscription_info['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
$trial_duration = $subscription_info['trial_duration'];
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
}
$price = $this->currency->format($subscription_info['price'] + ($this->config->get('config_tax') ? $subscription_info['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']);
$cycle = $subscription_info['cycle'];
$frequency = $this->language->get('text_' . $subscription_info['frequency']);
$duration = $subscription_info['duration'];
if ($subscription_info['duration']) {
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
}
$subscription_info = $this->model_account_subscription->getSubscriptionByOrderProductId($order_id, $product['order_product_id']);
if ($subscription_info) {
$subscription = $this->url->link('account/subscription.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&subscription_id=' . $subscription_info['subscription_id']);
} else {
$subscription = '';
}
$product_info = $this->model_catalog_product->getProduct($product['product_id']);
if ($product_info) {
$reorder = $this->url->link('account/order.reorder', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $order_id . '&order_product_id=' . $product['order_product_id']);
} else {
$reorder = '';
}
$data['products'][] = [
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'subscription' => $subscription,
'subscription_description' => $description,
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product['product_id']),
'reorder' => $reorder,
'return' => $this->url->link('account/returns.add', 'language=' . $this->config->get('config_language') . '&order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'])
];
}
// Voucher
$data['vouchers'] = [];
$vouchers = $this->model_account_order->getVouchers($order_id);
foreach ($vouchers as $voucher) {
$data['vouchers'][] = [
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
];
}
// Totals
$data['totals'] = [];
$totals = $this->model_account_order->getTotals($order_id);
foreach ($totals as $total) {
$data['totals'][] = [
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
];
}
$data['comment'] = nl2br($order_info['comment']);
// History
$data['history'] = $this->getHistory($order_info['order_id']);
$data['continue'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/order_info', $data));
return null;
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
}
/**
* @return void
*/
public function history(): void {
$this->load->language('account/order');
$this->response->setOutput($this->getHistory());
}
/**
* @return string
*/
public function getHistory(): string {
if (isset($this->request->get['order_id'])) {
$order_id = (int)$this->request->get['order_id'];
} else {
$order_id = 0;
}
if (isset($this->request->get['page']) && $this->request->get['route'] == 'account/order.history') {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['histories'] = [];
$this->load->model('account/order');
$results = $this->model_account_order->getHistories($order_id, ($page - 1) * $limit, $limit);
foreach ($results as $result) {
$data['histories'][] = [
'status' => $result['status'],
'comment' => nl2br($result['comment']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
];
}
$order_total = $this->model_account_order->getTotalHistories($order_id);
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $order_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/order.history', 'customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $order_id . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($order_total - $limit)) ? $order_total : ((($page - 1) * $limit) + $limit), $order_total, ceil($order_total / $limit));
return $this->load->view('account/order_history', $data);
}
/**
* @return void
*/
public function reorder(): void {
$this->load->language('account/order');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
if (isset($this->request->get['order_id'])) {
$order_id = (int)$this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('account/order');
$order_info = $this->model_account_order->getOrder($order_id);
if ($order_info) {
if (isset($this->request->get['order_product_id'])) {
$order_product_id = (int)$this->request->get['order_product_id'];
} else {
$order_product_id = 0;
}
$order_product_info = $this->model_account_order->getProduct($order_id, $order_product_id);
if ($order_product_info) {
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($order_product_info['product_id']);
if ($product_info) {
$option_data = [];
$order_options = $this->model_account_order->getOptions($order_product_info['order_id'], $order_product_id);
foreach ($order_options as $order_option) {
if ($order_option['type'] == 'select' || $order_option['type'] == 'radio' || $order_option['type'] == 'image') {
$option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'checkbox') {
$option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'text' || $order_option['type'] == 'textarea' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
} elseif ($order_option['type'] == 'file') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
}
}
$subscription_info = $this->model_account_order->getSubscription($order_product_info['order_id'], $order_product_id);
if ($subscription_info) {
$subscription_id = $subscription_info['subscription_id'];
} else {
$subscription_id = 0;
}
$this->cart->add($order_product_info['product_id'], $order_product_info['quantity'], $option_data, $subscription_id);
$this->session->data['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_info['product_id']), $product_info['name'], $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language')));
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 {
$this->session->data['error'] = sprintf($this->language->get('error_reorder'), $order_product_info['name']);
}
}
}
$this->response->redirect($this->url->link('account/order.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $order_id));
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Password
*
* @package Opencart\Catalog\Controller\Account
*/
class Password extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/password');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/password', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['save'] = $this->url->link('account/password.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/password', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('account/password');
$json = [];
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/password', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$keys = [
'password',
'confirm'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
if ((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['confirm'] != $this->request->post['password']) {
$json['error']['confirm'] = $this->language->get('error_confirm');
}
}
if (!$json) {
$this->load->model('account/customer');
$this->model_account_customer->editPassword($this->customer->getEmail(), $this->request->post['password']);
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,164 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Payment Method
*
* @package Opencart\Catalog\Controller\Account
*/
class PaymentMethod extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/payment_method');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->document->setTitle($this->language->get('heading_title'));
$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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
$data['list'] = $this->getList();
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['language'] = $this->config->get('config_language');
$data['customer_token'] = $this->session->data['customer_token'];
$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('account/payment_method', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('account/payment_method');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
$data['payment_methods'] = [];
$this->load->model('account/payment_method');
$this->load->model('setting/extension');
$results = $this->model_setting_extension->getExtensionsByType('payment');
foreach ($results as $result) {
if ($this->config->get('payment_' . $result['code'] . '_status')) {
$this->load->model('extension/' . $result['extension'] . '/payment/' . $result['code']);
//$payment_method = $this->{'model_extension_' . $result['extension'] . '_payment_' . $result['code']}->getMethods($payment_address);
if ($payment_method) {
$method_data[$result['code']] = $payment_method;
}
}
}
foreach ($results as $result) {
$data['payment_methods'][] = [
'code' => $result['code'],
'name' => $result['name'],
'image' => $result['image'],
'type' => $result['type'],
'date_expire' => date('m-Y', strtotime($result['date_expire'])),
'delete' => $this->url->link('account/payment_method.delete', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&customer_payment_id=' . $result['customer_payment_id'])
];
}
return $this->load->view('account/payment_method_list', $data);
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('account/payment_method');
$json = [];
if (isset($this->request->get['customer_payment_id'])) {
$customer_payment_id = (int)$this->request->get['customer_payment_id'];
} else {
$customer_payment_id = 0;
}
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$this->load->model('account/payment_method');
$payment_method_info = $this->model_account_payment_method->getPaymentMethod($this->customer->getId(), $customer_payment_id);
if (!$payment_method_info) {
$json['error'] = $this->language->get('error_payment_method');
}
}
if (!$json) {
$this->load->model('extension/' . $payment_method_info['extension'] . '/payment/' . $payment_method_info['code']);
if ($this->{'model_extension_' . $payment_method_info['extension'] . '_payment_' . $payment_method_info['code']}->delete($customer_payment_id)) {
}
// Delete payment method from database.
$this->model_account_payment_method->deletePaymentMethod($customer_payment_id);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,264 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Register
*
* @package Opencart\Catalog\Controller\Account
*/
class Register extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
}
$this->load->language('account/register');
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_register'),
'href' => $this->url->link('account/register', 'language=' . $this->config->get('config_language'))
];
$data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('account/login', 'language=' . $this->config->get('config_language')));
$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['config_telephone_display'] = $this->config->get('config_telephone_display');
$data['config_telephone_required'] = $this->config->get('config_telephone_required');
$this->session->data['register_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
$data['register'] = $this->url->link('account/register.register', 'language=' . $this->config->get('config_language') . '&register_token=' . $this->session->data['register_token']);
$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;
}
}
}
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
// Custom Fields
$data['custom_fields'] = [];
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields();
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'account') {
$data['custom_fields'][] = $custom_field;
}
}
// 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');
$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('account/register', $data));
}
/**
* @return void
*/
public function register(): void {
$this->load->language('account/register');
$json = [];
$keys = [
'customer_group_id',
'firstname',
'lastname',
'email',
'telephone',
'custom_field',
'password',
'confirm',
'agree'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
if (!isset($this->request->get['register_token']) || !isset($this->session->data['register_token']) || ($this->session->data['register_token'] != $this->request->get['register_token'])) {
$json['redirect'] = $this->url->link('account/register', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
// 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->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$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['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 ((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');
}
// 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'))) {
$captcha = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code'] . '.validate');
if ($captcha) {
$json['error']['captcha'] = $captcha;
}
}
// Agree to terms
$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']);
}
}
if (!$json) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Login if requires approval
if (!$customer_group_info['approval']) {
$this->customer->login($this->request->post['email'], html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8'));
// Add customer details into session
$this->session->data['customer'] = [
'customer_id' => $customer_id,
'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' => $this->request->post['custom_field']
];
// Log the IP info
$this->model_account_customer->addLogin($this->customer->getId(), $this->request->server['REMOTE_ADDR']);
// Create customer token
$this->session->data['customer_token'] = oc_token(26);
}
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
unset($this->session->data['guest']);
unset($this->session->data['register_token']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
$json['redirect'] = $this->url->link('account/success', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''), true);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,454 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Returns
*
* @package Opencart\Catalog\Controller\Account
*/
class Returns extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/returns');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/returns', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
];
$data['returns'] = [];
$this->load->model('account/returns');
$return_total = $this->model_account_returns->getTotalReturns();
$results = $this->model_account_returns->getReturns(($page - 1) * $limit, $limit);
foreach ($results as $result) {
$data['returns'][] = [
'return_id' => $result['return_id'],
'order_id' => $result['order_id'],
'name' => $result['firstname'] . ' ' . $result['lastname'],
'status' => $result['status'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'href' => $this->url->link('account/returns.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&return_id=' . $result['return_id'] . $url)
];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $return_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($return_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($return_total - $limit)) ? $return_total : ((($page - 1) * $limit) + $limit), $return_total, ceil($return_total / $limit));
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/returns_list', $data));
}
/**
* @return void
*/
public function info(): object|null {
$this->load->language('account/returns');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/returns.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
if (isset($this->request->get['return_id'])) {
$return_id = (int)$this->request->get['return_id'];
} else {
$return_id = 0;
}
$this->load->model('account/returns');
$return_info = $this->model_account_returns->getReturn($return_id);
if ($return_info) {
$this->document->setTitle($this->language->get('text_return'));
$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') . '&customer_token=' . $this->session->data['customer_token'])
];
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_return'),
'href' => $this->url->link('account/returns.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&return_id=' . $this->request->get['return_id'] . $url)
];
$data['return_id'] = $return_info['return_id'];
$data['order_id'] = $return_info['order_id'];
$data['date_ordered'] = date($this->language->get('date_format_short'), strtotime($return_info['date_ordered']));
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($return_info['date_added']));
$data['firstname'] = $return_info['firstname'];
$data['lastname'] = $return_info['lastname'];
$data['email'] = $return_info['email'];
$data['telephone'] = $return_info['telephone'];
$data['product'] = $return_info['product'];
$data['model'] = $return_info['model'];
$data['quantity'] = $return_info['quantity'];
$data['reason'] = $return_info['reason'];
$data['opened'] = $return_info['opened'] ? $this->language->get('text_yes') : $this->language->get('text_no');
$data['comment'] = nl2br($return_info['comment']);
$data['action'] = $return_info['action'];
$data['histories'] = [];
$results = $this->model_account_returns->getHistories($this->request->get['return_id']);
foreach ($results as $result) {
$data['histories'][] = [
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'status' => $result['status'],
'comment' => nl2br($result['comment'])
];
}
$data['continue'] = $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . $url);
$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('account/returns_info', $data));
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
return null;
}
/**
* @return void
*/
public function add(): void {
$this->load->language('account/returns');
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/returns.add', 'language=' . $this->config->get('config_language'))
];
$this->session->data['return_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
$data['save'] = $this->url->link('account/returns.save', 'language=' . $this->config->get('config_language') . '&return_token=' . $this->session->data['return_token']);
$this->load->model('account/order');
if (isset($this->request->get['order_id'])) {
$order_info = $this->model_account_order->getOrder($this->request->get['order_id']);
}
$this->load->model('catalog/product');
if (isset($this->request->get['product_id'])) {
$product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
}
if (!empty($order_info)) {
$data['order_id'] = $order_info['order_id'];
} else {
$data['order_id'] = '';
}
if (!empty($product_info)) {
$data['product_id'] = $product_info['product_id'];
} else {
$data['product_id'] = '';
}
if (!empty($order_info)) {
$data['date_ordered'] = date('Y-m-d', strtotime($order_info['date_added']));
} else {
$data['date_ordered'] = '';
}
if (!empty($order_info)) {
$data['firstname'] = $order_info['firstname'];
} else {
$data['firstname'] = $this->customer->getFirstName();
}
if (!empty($order_info)) {
$data['lastname'] = $order_info['lastname'];
} else {
$data['lastname'] = $this->customer->getLastName();
}
if (!empty($order_info)) {
$data['email'] = $order_info['email'];
} else {
$data['email'] = $this->customer->getEmail();
}
if (!empty($order_info)) {
$data['telephone'] = $order_info['telephone'];
} else {
$data['telephone'] = $this->customer->getTelephone();
}
if (!empty($product_info)) {
$data['product'] = $product_info['name'];
} else {
$data['product'] = '';
}
if (!empty($product_info)) {
$data['model'] = $product_info['model'];
} else {
$data['model'] = '';
}
$this->load->model('localisation/return_reason');
$data['return_reasons'] = $this->model_localisation_return_reason->getReturnReasons();
// 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('returns', (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_return_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_return_id')), $information_info['title']);
} else {
$data['text_agree'] = '';
}
$data['back'] = $this->url->link('account/account', '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('account/returns_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('account/returns');
$json = [];
if (!isset($this->request->get['return_token']) || !isset($this->session->data['return_token']) || ($this->request->get['return_token'] != $this->session->data['return_token'])) {
$json['redirect'] = $this->url->link('account/returns.add', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$keys = [
'order_id',
'firstname',
'lastname',
'email',
'telephone',
'product',
'model',
'reason',
'agree'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
if (!$this->request->post['order_id']) {
$json['error']['order_id'] = $this->language->get('error_order_id');
}
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');
}
if ((oc_strlen($this->request->post['telephone']) < 3) || (oc_strlen($this->request->post['telephone']) > 32)) {
$json['error']['telephone'] = $this->language->get('error_telephone');
}
if ((oc_strlen($this->request->post['product']) < 1) || (oc_strlen($this->request->post['product']) > 255)) {
$json['error']['product'] = $this->language->get('error_product');
}
if ((oc_strlen($this->request->post['model']) < 1) || (oc_strlen($this->request->post['model']) > 64)) {
$json['error']['model'] = $this->language->get('error_model');
}
if (empty($this->request->post['return_reason_id'])) {
$json['error']['reason'] = $this->language->get('error_reason');
}
// 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('return', (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 ($this->config->get('config_return_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_return_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
}
if (!$json) {
$this->load->model('account/returns');
$this->model_account_returns->addReturn($this->request->post);
$json['redirect'] = $this->url->link('account/returns.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 success(): void {
$this->load->language('account/returns');
$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('account/returns.add', '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));
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Reward
*
* @package Opencart\Catalog\Controller\Account
*/
class Reward extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/reward');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/reward', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_reward'),
'href' => $this->url->link('account/reward', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$this->load->model('account/reward');
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['rewards'] = [];
$filter_data = [
'sort' => 'date_added',
'order' => 'DESC',
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$reward_total = $this->model_account_reward->getTotalRewards();
$results = $this->model_account_reward->getRewards($filter_data);
foreach ($results as $result) {
$data['rewards'][] = [
'order_id' => $result['order_id'],
'points' => $result['points'],
'description' => $result['description'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'href' => $this->url->link('account/order.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $result['order_id'])
];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $reward_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/reward', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($reward_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($reward_total - $limit)) ? $reward_total : ((($page - 1) * $limit) + $limit), $reward_total, ceil($reward_total / $limit));
$data['total'] = (int)$this->customer->getRewardPoints();
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/reward', $data));
}
}

View File

@@ -0,0 +1,509 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Subscription
*
* @package Opencart\Catalog\Controller\Account
*/
class Subscription extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/subscription');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/subscription', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$this->document->setTitle($this->language->get('heading_title'));
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/subscription', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
];
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['subscriptions'] = [];
$this->load->model('account/subscription');
$this->load->model('account/order');
$this->load->model('catalog/product');
$this->load->model('localisation/currency');
$this->load->model('localisation/subscription_status');
$subscription_total = $this->model_account_subscription->getTotalSubscriptions();
$results = $this->model_account_subscription->getSubscriptions(($page - 1) * $limit, $limit);
foreach ($results as $result) {
$product_info = $this->model_catalog_product->getProduct($result['product_id']);
if ($product_info) {
$currency_info = $this->model_localisation_currency->getCurrency($result['currency_id']);
if ($currency_info) {
$currency = $currency_info['code'];
} else {
$currency = $this->config->get('config_currency');
}
$description = '';
if ($result['trial_status']) {
$trial_price = $this->currency->format($this->tax->calculate($result['trial_price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $currency);
$trial_cycle = $result['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $result['trial_frequency']);
$trial_duration = $result['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($result['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $currency);
$cycle = $result['cycle'];
$frequency = $this->language->get('text_' . $result['frequency']);
$duration = $result['duration'];
if ($duration) {
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
$subscription_status_info = $this->model_localisation_subscription_status->getSubscriptionStatus($result['subscription_status_id']);
if ($subscription_status_info) {
$subscription_status = $subscription_status_info['name'];
} else {
$subscription_status = '';
}
$data['subscriptions'][] = [
'subscription_id' => $result['subscription_id'],
'product_id' => $result['product_id'],
'product_name' => $product_info['name'],
'description' => $description,
'product' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id']),
'status' => $subscription_status,
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'view' => $this->url->link('account/subscription.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&subscription_id=' . $result['subscription_id'])
];
}
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $subscription_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/subscription', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($subscription_total - $limit)) ? $subscription_total : ((($page - 1) * $limit) + $limit), $subscription_total, ceil($subscription_total / $limit));
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/subscription_list', $data));
}
/**
* @return void
*/
public function info(): object|null {
$this->load->language('account/subscription');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/subscription', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
if (isset($this->request->get['subscription_id'])) {
$subscription_id = (int)$this->request->get['subscription_id'];
} else {
$subscription_id = 0;
}
$this->load->model('account/subscription');
$subscription_info = $this->model_account_subscription->getSubscription($subscription_id);
if ($subscription_info) {
$heading_title = sprintf($this->language->get('text_subscription'), $subscription_info['subscription_id']);
$this->document->setTitle($heading_title);
$data['heading_title'] = $heading_title;
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$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') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/subscription', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
];
$data['breadcrumbs'][] = [
'text' => $heading_title,
'href' => $this->url->link('account/subscription.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&subscription_id=' . $this->request->get['subscription_id'] . $url)
];
$data['subscription_id'] = $subscription_info['subscription_id'];
$data['order_id'] = $subscription_info['order_id'];
$this->load->model('localisation/subscription_status');
$subscription_status_info = $this->model_localisation_subscription_status->getSubscriptionStatus($subscription_info['subscription_status_id']);
if ($subscription_status_info) {
$data['subscription_status'] = $subscription_status_info['name'];
} else {
$data['subscription_status'] = '';
}
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($subscription_info['date_added']));
// Payment Address
if ($subscription_info['payment_address_id']) {
$payment_address_id = $subscription_info['payment_address_id'];
} else {
$payment_address_id = 0;
}
$this->load->model('account/address');
$address_info = $this->model_account_address->getAddress($this->customer->getId(), $payment_address_id);
if ($address_info) {
if ($address_info['address_format']) {
$format = $address_info['address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = [
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
];
$replace = [
'firstname' => $address_info['firstname'],
'lastname' => $address_info['lastname'],
'company' => $address_info['company'],
'address_1' => $address_info['address_1'],
'address_2' => $address_info['address_2'],
'city' => $address_info['city'],
'postcode' => $address_info['postcode'],
'zone' => $address_info['zone'],
'zone_code' => $address_info['zone_code'],
'country' => $address_info['country']
];
$data['payment_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
} else {
$data['payment_address'] = '';
}
// Shipping Address
if ($subscription_info['shipping_address_id']) {
$shipping_address_id = $subscription_info['shipping_address_id'];
} else {
$shipping_address_id = 0;
}
$this->load->model('account/address');
$address_info = $this->model_account_address->getAddress($this->customer->getId(), $shipping_address_id);
if ($address_info) {
if ($address_info['address_format']) {
$format = $address_info['address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = [
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
];
$replace = [
'firstname' => $address_info['firstname'],
'lastname' => $address_info['lastname'],
'company' => $address_info['company'],
'address_1' => $address_info['address_1'],
'address_2' => $address_info['address_2'],
'city' => $address_info['city'],
'postcode' => $address_info['postcode'],
'zone' => $address_info['zone'],
'zone_code' => $address_info['zone_code'],
'country' => $address_info['country']
];
$data['shipping_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
} else {
$data['shipping_address'] = '';
}
if ($subscription_info['shipping_method']) {
$data['shipping_method'] = $subscription_info['shipping_method']['name'];
} else {
$data['shipping_method'] = '';
}
if ($subscription_info['payment_method']) {
$data['payment_method'] = $subscription_info['payment_method']['name'];
} else {
$data['payment_method'] = '';
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($subscription_info['product_id']);
if ($product_info) {
$data['name'] = $product_info['name'];
} else {
$data['name'] = '';
}
$data['quantity'] = $subscription_info['quantity'];
$currency_info = $this->model_localisation_currency->getCurrency($subscription_info['currency_id']);
if ($currency_info) {
$currency = $currency_info['code'];
} else {
$currency = $this->config->get('config_currency');
}
$this->load->model('localisation/subscription_status');
$subscription_status_info = $this->model_localisation_subscription_status->getSubscriptionStatus($subscription_info['subscription_status_id']);
if ($subscription_status_info) {
$data['subscription_status'] = $subscription_status_info['name'];
} else {
$data['subscription_status'] = '';
}
$data['description'] = '';
if ($subscription_info['trial_status']) {
$trial_price = $this->currency->format($this->tax->calculate($subscription_info['trial_price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $currency);
$trial_cycle = $subscription_info['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
$trial_duration = $subscription_info['trial_duration'];
$data['description'] .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
}
$price = $this->currency->format($this->tax->calculate($subscription_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $currency);
$cycle = $subscription_info['cycle'];
$frequency = $this->language->get('text_' . $subscription_info['frequency']);
$duration = $subscription_info['duration'];
if ($duration) {
$data['description'] .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
} else {
$data['description'] .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
// Orders
$data['history'] = $this->getHistory();
$data['order'] = $this->getOrder();
//$data['order'] = $this->url->link('account/order.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $subscription_info['order_id']);
$data['product'] = $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&product_id=' . $subscription_info['product_id']);
$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('account/subscription_info', $data));
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
return null;
}
/**
* @return void
*/
public function history(): void {
$this->load->language('account/subscription');
$this->response->setOutput($this->getHistory());
}
/**
* @return string
*/
public function getHistory(): string {
if (isset($this->request->get['subscription_id'])) {
$subscription_id = (int)$this->request->get['subscription_id'];
} else {
$subscription_id = 0;
}
if (isset($this->request->get['page']) && $this->request->get['route'] == 'account/subscription.history') {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['histories'] = [];
$this->load->model('account/subscription');
$results = $this->model_account_subscription->getHistories($subscription_id, ($page - 1) * $limit, $limit);
foreach ($results as $result) {
$data['histories'][] = [
'status' => $result['status'],
'comment' => nl2br($result['comment']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
];
}
$subscription_total = $this->model_account_subscription->getTotalHistories($subscription_id);
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $subscription_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/subscription.history', 'customer_token=' . $this->session->data['customer_token'] . '&subscription_id=' . $subscription_id . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($subscription_total - $limit)) ? $subscription_total : ((($page - 1) * $limit) + $limit), $subscription_total, ceil($subscription_total / $limit));
return $this->load->view('account/subscription_history', $data);
}
/**
* @return void
*/
public function order(): void {
$this->load->language('account/subscription');
$this->response->setOutput($this->getOrder());
}
/**
* @return string
*/
public function getOrder(): string {
if (isset($this->request->get['subscription_id'])) {
$subscription_id = (int)$this->request->get['subscription_id'];
} else {
$subscription_id = 0;
}
if (isset($this->request->get['page']) && $this->request->get['route'] == 'account/subscription.order') {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['orders'] = [];
$this->load->model('account/order');
$results = $this->model_account_order->getOrdersBySubscriptionId($subscription_id, ($page - 1) * $limit, $limit);
foreach ($results as $result) {
$data['orders'][] = [
'order_id' => $result['order_id'],
'status' => $result['status'],
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'view' => $this->url->link('sale/subscription.order', 'customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $result['order_id'] . '&page={page}')
];
}
$order_total = $this->model_account_order->getTotalOrdersBySubscriptionId($subscription_id);
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $order_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('sale/subscription.order', 'customer_token=' . $this->session->data['customer_token'] . '&subscription_id=' . $subscription_id . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($order_total - $limit)) ? $order_total : ((($page - 1) * $limit) + $limit), $order_total, ceil($order_total / $limit));
return $this->load->view('account/subscription_order', $data);
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Success
*
* @package Opencart\Catalog\Controller\Account
*/
class Success extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/success');
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/success', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''))
];
if ($this->customer->isLogged()) {
$data['text_message'] = sprintf($this->language->get('text_success'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
} else {
$data['text_message'] = sprintf($this->language->get('text_approval'), $this->config->get('config_name'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
}
if ($this->cart->hasProducts()) {
$data['continue'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'));
} else {
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
}
$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));
}
}

View File

@@ -0,0 +1,118 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Tracking
*
* @package Opencart\Catalog\Controller\Account
*/
class Tracking extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/tracking', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
if (!$this->config->get('config_affiliate_status')) {
$this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
}
$this->load->model('account/affiliate');
$affiliate_info = $this->model_account_affiliate->getAffiliate($this->customer->getId());
if (!$affiliate_info) {
$this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']));
}
$this->load->language('account/tracking');
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/tracking', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['text_description'] = sprintf($this->language->get('text_description'), $this->config->get('config_name'));
$data['code'] = $affiliate_info['tracking'];
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['language'] = $this->config->get('config_language');
$data['customer_token'] = $this->session->data['customer_token'];
$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('account/tracking', $data));
}
/**
* @return void
*/
public function autocomplete(): void {
$json = [];
if (isset($this->request->get['search'])) {
$search = $this->request->get['search'];
} else {
$search = '';
}
if (isset($this->request->get['tracking'])) {
$tracking = $this->request->get['tracking'];
} else {
$tracking = '';
}
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/password', 'language=' . $this->config->get('config_language'));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}
if (!$json) {
$filter_data = [
'filter_search' => $search,
'start' => 0,
'limit' => 5
];
$this->load->model('catalog/product');
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
$json[] = [
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
'link' => str_replace('&amp;', '&', $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . '&tracking=' . $tracking))
];
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Transaction
*
* @package Opencart\Catalog\Controller\Account
*/
class Transaction extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/transaction');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/transaction', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_transaction'),
'href' => $this->url->link('account/transaction', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
];
$this->load->model('account/transaction');
$data['column_amount'] = sprintf($this->language->get('column_amount'), $this->config->get('config_currency'));
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['transactions'] = [];
$filter_data = [
'sort' => 'date_added',
'order' => 'DESC',
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$transaction_total = $this->model_account_transaction->getTotalTransactions();
$results = $this->model_account_transaction->getTransactions($filter_data);
foreach ($results as $result) {
$data['transactions'][] = [
'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')),
'description' => $result['description'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $transaction_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('account/transaction', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($transaction_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($transaction_total - $limit)) ? $transaction_total : ((($page - 1) * $limit) + $limit), $transaction_total, ceil($transaction_total / $limit));
$data['total'] = $this->currency->format($this->customer->getBalance(), $this->session->data['currency']);
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$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('account/transaction', $data));
}
}

View File

@@ -0,0 +1,215 @@
<?php
namespace Opencart\Catalog\Controller\Account;
/**
* Class Wish List
*
* @package Opencart\Catalog\Controller\Account
*/
class WishList extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('account/wishlist');
if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/wishlist', 'language=' . $this->config->get('config_language'));
$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language')));
}
$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_account'),
'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('account/wishlist', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''))
];
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
$data['list'] = $this->load->controller('account/wishlist.getList');
$data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$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('account/wishlist', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('account/wishlist');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
public function getList(): string {
$data['wishlist'] = $this->url->link('account/wishlist.list', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['add_to_cart'] = $this->url->link('checkout/cart.add', 'language=' . $this->config->get('config_language'));
$data['remove'] = $this->url->link('account/wishlist.remove', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['products'] = [];
$this->load->model('account/wishlist');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$results = $this->model_account_wishlist->getWishlist();
foreach ($results as $result) {
$product_info = $this->model_catalog_product->getProduct($result['product_id']);
if ($product_info) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize(html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_wishlist_width'), $this->config->get('config_image_wishlist_height'));
} else {
$image = false;
}
if ($product_info['quantity'] <= 0) {
$stock = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$stock = $product_info['quantity'];
} else {
$stock = $this->language->get('text_instock');
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$product_info['special']) {
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
$data['products'][] = [
'product_id' => $product_info['product_id'],
'thumb' => $image,
'name' => $product_info['name'],
'model' => $product_info['model'],
'stock' => $stock,
'price' => $price,
'special' => $special,
'minimum' => $product_info['minimum'] > 0 ? $product_info['minimum'] : 1,
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_info['product_id'])
];
} else {
$this->model_account_wishlist->deleteWishlist($result['product_id']);
}
}
return $this->load->view('account/wishlist_list', $data);
}
/**
* @return void
*/
public function add(): void {
$this->load->language('account/wishlist');
$json = [];
if (isset($this->request->post['product_id'])) {
$product_id = (int)$this->request->post['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if (!$product_info) {
$json['error'] = $this->language->get('error_product');
}
if (!$json) {
if (!isset($this->session->data['wishlist'])) {
$this->session->data['wishlist'] = [];
}
$this->session->data['wishlist'][] = $product_id;
$this->session->data['wishlist'] = array_unique($this->session->data['wishlist']);
// Store the
if ($this->customer->isLogged()) {
// Edit customers cart
$this->load->model('account/wishlist');
$this->model_account_wishlist->addWishlist($product_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('account/wishlist', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : '')));
$json['total'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());
} else {
$json['success'] = 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')), $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . (int)$product_id), $product_info['name'], $this->url->link('account/wishlist', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : '')));
$json['total'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function remove(): void {
$this->load->language('account/wishlist');
$json = [];
if (isset($this->request->post['product_id'])) {
$product_id = (int)$this->request->post['product_id'];
} else {
$product_id = 0;
}
if (!$json) {
if ($this->customer->isLogged()) {
$this->load->model('account/wishlist');
$this->model_account_wishlist->deleteWishlist($product_id);
$json['success'] = $this->language->get('text_remove');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace Opencart\Catalog\Controller\Api\Account;
/**
* Class Login
*
* @package Opencart\Catalog\Controller\Api\Account
*/
class Login extends \Opencart\System\Engine\Controller {
/*
* Opencart\Catalog\Controller\Api\Account\Login.Index
*
* @Example
*
* $url = 'https://www.yourdomain.com/index.php?route=api/account/login&language=en-gb&store_id=0';
*
* $request_data = [
* 'username' => 'Default',
* 'key' => ''
* ];
*
* $curl = curl_init();
*
* curl_setopt($curl, CURLOPT_URL, $url);
* curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
* curl_setopt($curl, CURLOPT_HEADER, false);
* curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
* curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
* curl_setopt($curl, CURLOPT_TIMEOUT, 30);
* curl_setopt($curl, CURLOPT_POST, 1);
* curl_setopt($curl, CURLOPT_POSTFIELDS, $request_data);
*
* $response = curl_exec($curl);
*
* $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
*
* curl_close($curl);
*
* if ($status == 200) {
* $api_token = json_decode($response, true);
*
* if (isset($api_token['api_token'])) {
*
* // You can now store the session cookie as a var in the your current session or some of persistent storage
* $session_id = $api_token['api_token'];
* }
* }
*
* $url = 'http://www.yourdomain.com/opencart-master/upload/index.php?route=api/sale/order.load&language=en-gb&store_id=0&order_id=1';
*
* $curl = curl_init();
*
* curl_setopt($curl, CURLOPT_URL, $url);
* curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
* curl_setopt($curl, CURLOPT_HEADER, false);
* curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
* curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
* curl_setopt($curl, CURLOPT_TIMEOUT, 30);
* curl_setopt($curl, CURLOPT_POST, 1);
* curl_setopt($curl, CURLOPT_POSTFIELDS, $request_data);
*
* // Add the session cookie so we don't have to login again.
* curl_setopt($curl, CURLOPT_COOKIE, 'OCSESSID=' . $session_id);
*
* $response = curl_exec($curl);
*
* curl_close($curl);
*
*/
public function index(): void {
$this->load->language('api/account/login');
$json = [];
$this->load->model('account/api');
// Login with API Key
if (!empty($this->request->post['username']) && !empty($this->request->post['key'])) {
$api_info = $this->model_account_api->login($this->request->post['username'], $this->request->post['key']);
} else {
$api_info = [];
}
if ($api_info) {
// Check if IP is allowed
$ip_data = [];
$results = $this->model_account_api->getIps($api_info['api_id']);
foreach ($results as $result) {
$ip_data[] = trim($result['ip']);
}
if (!in_array($this->request->server['REMOTE_ADDR'], $ip_data)) {
$json['error'] = sprintf($this->language->get('error_ip'), $this->request->server['REMOTE_ADDR']);
}
} else {
$json['error'] = $this->language->get('error_key');
}
if (!$json) {
$json['success'] = $this->language->get('text_success');
$session = new \Opencart\System\Library\Session($this->config->get('session_engine'), $this->registry);
$session->start();
$this->model_account_api->addSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']);
$session->data['api_id'] = $api_info['api_id'];
// Create Token
$json['api_token'] = $session->getId();
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Opencart\Catalog\Controller\Api\Localisation;
/**
* Class Currency
*
* @package Opencart\Catalog\Controller\Api\Localisation
*/
class Currency extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/localisation/currency');
$json = [];
if (isset($this->request->post['currency'])) {
$currency = (string)$this->request->post['currency'];
} else {
$currency = '';
}
$this->load->model('localisation/currency');
$currency_info = $this->model_localisation_currency->getCurrencyByCode($currency);
if (!$currency_info) {
$json['error'] = $this->language->get('error_currency');
}
if (!$json) {
$this->session->data['currency'] = $currency;
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Affiliate
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class Affiliate extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/affiliate');
$json = [];
if (isset($this->request->post['affiliate_id'])) {
$affiliate_id = (int)$this->request->post['affiliate_id'];
} else {
$affiliate_id = 0;
}
if ($affiliate_id) {
$this->load->model('account/affiliate');
$affiliate_info = $this->model_account_affiliate->getAffiliate($affiliate_id);
if (!$affiliate_info) {
$json['error'] = $this->language->get('error_affiliate');
}
}
if (!$json) {
if ($affiliate_id) {
$json['success'] = $this->language->get('text_success');
$this->session->data['affiliate_id'] = $affiliate_id;
} else {
$json['success'] = $this->language->get('text_remove');
unset($this->session->data['affiliate_id']);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,240 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Cart
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class Cart extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/cart');
$json = [];
// Stock
if (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
$json['error']['stock'] = $this->language->get('error_stock');
}
$totals = [];
$taxes = $this->cart->getTaxes();
$total = 0;
$this->load->model('checkout/cart');
($this->model_checkout_cart->getTotals)($totals, $taxes, $total);
$json['products'] = [];
$products = $this->model_checkout_cart->getProducts();
foreach ($products as $product) {
$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, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
}
$json['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'],
'stock' => $product['stock'],
'minimum' => $product['minimum'],
'reward' => $product['reward'],
'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']),
];
}
$json['vouchers'] = [];
$vouchers = $this->model_checkout_cart->getVouchers();
foreach ($vouchers as $key => $voucher) {
$json['vouchers'][] = [
'key' => $key,
'description' => sprintf($this->language->get('text_for'), $this->currency->format($voucher['amount'], $this->session->data['currency']), $voucher['to_name']),
'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency'])
];
}
$json['totals'] = [];
foreach ($totals as $total) {
$json['totals'][] = [
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $this->session->data['currency'])
];
}
$json['shipping_required'] = $this->cart->hasShipping();
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function add(): void {
$this->load->language('api/sale/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'];
}
// Merge variant code with options
foreach ($product_info['variant'] as $key => $value) {
$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 plan
$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'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function edit(): void {
$this->load->language('api/sale/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;
}
$this->cart->update($key, $quantity);
$json['success'] = $this->language->get('text_success');
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('api/sale/cart');
$json = [];
if (isset($this->request->post['key'])) {
$key = (int)$this->request->post['key'];
} else {
$key = 0;
}
// Remove
$this->cart->remove($key);
$json['success'] = $this->language->get('text_success');
unset($this->session->data['reward']);
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Coupon
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class Coupon extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/coupon');
$json = [];
if (isset($this->request->post['coupon'])) {
$coupon = (string)$this->request->post['coupon'];
} else {
$coupon = '';
}
if ($coupon) {
$this->load->model('marketing/coupon');
$coupon_info = $this->model_marketing_coupon->getCoupon($coupon);
if (!$coupon_info) {
$json['error'] = $this->language->get('error_coupon');
}
}
if (!$json) {
if ($coupon) {
$json['success'] = $this->language->get('text_success');
$this->session->data['coupon'] = $coupon;
} else {
$json['success'] = $this->language->get('text_remove');
unset($this->session->data['coupon']);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Customer
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class Customer extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/customer');
$json = [];
$keys = [
'customer_id',
'customer_group_id',
'firstname',
'lastname',
'email',
'telephone',
'account_custom_field'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
$this->load->model('account/customer');
if ($this->request->post['customer_id']) {
$customer_info = $this->model_account_customer->getCustomer($this->request->post['customer_id']);
if (!$customer_info) {
$json['error']['warning'] = $this->language->get('error_customer');
}
}
// 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) {
$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');
}
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((int)$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['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) {
$this->session->data['customer'] = [
'customer_id' => $this->request->post['customer_id'],
'customer_group_id' => $this->request->post['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' => !empty($this->request->post['custom_field']) && is_array($this->request->post['custom_field']) ? $this->request->post['custom_field'] : []
];
$json['success'] = $this->language->get('text_success');
unset($this->session->data['reward']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,609 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Order
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class Order extends \Opencart\System\Engine\Controller {
/*
* Loads order info
*/
/**
* @return void
*/
public function load(): void {
$this->load->language('api/sale/order');
$json = [];
if (isset($this->request->get['order_id'])) {
$order_id = (int)$this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);
if (!$order_info) {
$json['error'] = $this->language->get('error_order');
}
if (!$json) {
$this->session->data['order_id'] = $order_id;
// Customer Details
$this->session->data['customer'] = [
'customer_id' => $order_info['customer_id'],
'customer_group_id' => $order_info['customer_group_id'],
'firstname' => $order_info['firstname'],
'lastname' => $order_info['lastname'],
'email' => $order_info['email'],
'telephone' => $order_info['telephone'],
'custom_field' => $order_info['custom_field']
];
// Payment Details
if ($this->config->get('config_checkout_payment_address')) {
$this->session->data['payment_address'] = [
'address_id' => $order_info['payment_address_id'],
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'postcode' => $order_info['payment_postcode'],
'city' => $order_info['payment_city'],
'zone_id' => $order_info['payment_zone_id'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country_id' => $order_info['payment_country_id'],
'country' => $order_info['payment_country'],
'iso_code_2' => $order_info['payment_iso_code_2'],
'iso_code_3' => $order_info['payment_iso_code_3'],
'address_format' => $order_info['payment_address_format'],
'custom_field' => $order_info['payment_custom_field']
];
} else {
unset($this->session->data['payment_address']);
}
$this->session->data['payment_method'] = $order_info['payment_method'];
if ($order_info['shipping_method']) {
$this->session->data['shipping_address'] = [
'address_id' => $order_info['shipping_address_id'],
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'postcode' => $order_info['shipping_postcode'],
'city' => $order_info['shipping_city'],
'zone_id' => $order_info['shipping_zone_id'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country_id' => $order_info['shipping_country_id'],
'country' => $order_info['shipping_country'],
'iso_code_2' => $order_info['shipping_iso_code_2'],
'iso_code_3' => $order_info['shipping_iso_code_3'],
'address_format' => $order_info['shipping_address_format'],
'custom_field' => $order_info['shipping_custom_field']
];
$this->session->data['shipping_method'] = $order_info['shipping_method'];
}
if ($order_info['comment']) {
$this->session->data['comment'] = $order_info['comment'];
}
if ($order_info['currency_code']) {
$this->session->data['currency'] = $order_info['currency_code'];
}
$products = $this->model_checkout_order->getProducts($order_id);
foreach ($products as $product) {
$option_data = [];
$options = $this->model_checkout_order->getOptions($order_id, $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
$option_data[$option['product_option_id']] = $option['value'];
} elseif ($option['type'] == 'select' || $option['type'] == 'radio') {
$option_data[$option['product_option_id']] = $option['product_option_value_id'];
} elseif ($option['type'] == 'checkbox') {
$option_data[$option['product_option_id']][] = $option['product_option_value_id'];
}
}
$subscription_info = $this->model_checkout_order->getSubscription($order_id, $product['order_product_id']);
if ($subscription_info) {
$subscription_plan_id = $subscription_info['subscription_plan_id'];
} else {
$subscription_plan_id = 0;
}
$this->cart->add($product['product_id'], $product['quantity'], $option_data, $subscription_plan_id, true, $product['price']);
}
$this->session->data['vouchers'] = [];
$this->load->model('checkout/voucher');
$vouchers = $this->model_checkout_order->getVouchers($order_id);
foreach ($vouchers as $voucher) {
$this->session->data['vouchers'][] = [
'code' => $voucher['code'],
'description' => sprintf($this->language->get('text_for'), $this->currency->format($voucher['amount'], $this->session->data['currency'], 1.0), $voucher['to_name']),
'to_name' => $voucher['to_name'],
'to_email' => $voucher['to_email'],
'from_name' => $voucher['from_name'],
'from_email' => $voucher['from_email'],
'voucher_theme_id' => $voucher['voucher_theme_id'],
'message' => $voucher['message'],
'amount' => $this->currency->convert($voucher['amount'], $this->session->data['currency'], $this->config->get('config_currency'))
];
}
if ($order_info['affiliate_id']) {
$this->session->data['affiliate_id'] = $order_info['affiliate_id'];
}
// Coupon, Voucher, Reward
$order_totals = $this->model_checkout_order->getTotals($order_id);
foreach ($order_totals as $order_total) {
// If coupon, voucher or reward points
$start = strpos($order_total['title'], '(') + 1;
$end = strrpos($order_total['title'], ')');
if ($start && $end) {
$this->session->data[$order_total['code']] = substr($order_total['title'], $start, $end - $start);
}
}
$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('api/sale/order');
$json = [];
if (!isset($this->request->post['comment'])) {
$json['error'] = $this->language->get('error_comment');
}
if (!$json) {
$this->session->data['comment'] = $this->request->post['comment'];
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function confirm(): void {
$this->load->language('api/sale/order');
$json = [];
// Validate cart has products and has stock.
if (($this->cart->hasProducts() || !empty($this->session->data['vouchers']))) {
if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
$json['error']['stock'] = $this->language->get('error_stock');
}
} else {
$json['error']['product'] = $this->language->get('error_product');
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
if (!$product['minimum']) {
$json['error']['minimum'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
break;
}
}
// Customer
if (!isset($this->session->data['customer'])) {
$json['error']['customer'] = $this->language->get('error_customer');
}
// Payment Address
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
$json['error']['payment_address'] = $this->language->get('error_payment_address');
}
// Shipping
if ($this->cart->hasShipping()) {
// Shipping Address
if (!isset($this->session->data['shipping_address'])) {
$json['error']['shipping_address'] = $this->language->get('error_shipping_address');
}
// Validate shipping method
if (!isset($this->session->data['shipping_method'])) {
$json['error']['shipping_method'] = $this->language->get('error_shipping_method');
}
} else {
unset($this->session->data['shipping_address']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
}
// Payment Method
if (empty($this->session->data['payment_method'])) {
$json['error']['payment_method'] = $this->language->get('error_payment_method');
}
if (!$json) {
$order_data = [];
// Store Details
$order_data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
$order_data['store_id'] = $this->config->get('config_store_id');
$order_data['store_name'] = $this->config->get('config_name');
$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_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'] = [];
}
$points = 0;
// Products
$order_data['products'] = [];
foreach ($this->cart->getProducts() 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_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'],
'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']
];
$points += $product['reward'];
}
// Gift Voucher
$order_data['vouchers'] = [];
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $voucher) {
$order_data['vouchers'][] = [
'description' => $voucher['description'],
'code' => oc_token(10),
'to_name' => $voucher['to_name'],
'to_email' => $voucher['to_email'],
'from_name' => $voucher['from_name'],
'from_email' => $voucher['from_email'],
'voucher_theme_id' => $voucher['voucher_theme_id'],
'message' => $voucher['message'],
'amount' => $voucher['amount']
];
}
}
if (isset($this->session->data['comment'])) {
$order_data['comment'] = $this->session->data['comment'];
} else {
$order_data['comment'] = '';
}
// Order Totals
$totals = [];
$taxes = $this->cart->getTaxes();
$total = 0;
$this->load->model('checkout/cart');
($this->model_checkout_cart->getTotals)($totals, $taxes, $total);
$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['affiliate_id'])) {
$subtotal = $this->cart->getSubTotal();
// Affiliate
$this->load->model('account/affiliate');
$affiliate_info = $this->model_account_affiliate->getAffiliate($this->session->data['affiliate_id']);
if ($affiliate_info) {
$order_data['affiliate_id'] = $affiliate_info['customer_id'];
$order_data['commission'] = ($subtotal / 100) * $affiliate_info['commission'];
$order_data['tracking'] = $affiliate_info['tracking'];
}
}
// We use session to store language code for API access
$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'] = '';
}
$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) {
$this->model_checkout_order->editOrder($this->session->data['order_id'], $order_data);
}
}
$json['order_id'] = $this->session->data['order_id'];
// Set the order history
if (isset($this->request->post['order_status_id'])) {
$order_status_id = (int)$this->request->post['order_status_id'];
} else {
$order_status_id = $this->config->get('config_order_status_id');
}
$this->model_checkout_order->addHistory($json['order_id'], $order_status_id);
$json['success'] = $this->language->get('text_success');
$json['points'] = $points;
if (isset($order_data['affiliate_id'])) {
$json['commission'] = $this->currency->format($order_data['commission'], $this->config->get('config_currency'));
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('api/sale/order');
$json = [];
$selected = [];
if (isset($this->request->post['selected'])) {
$selected = $this->request->post['selected'];
}
if (isset($this->request->get['order_id'])) {
$selected[] = (int)$this->request->get['order_id'];
}
foreach ($selected as $order_id) {
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);
if ($order_info) {
$this->model_checkout_order->deleteOrder($order_id);
}
}
$json['success'] = $this->language->get('text_success');
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function addHistory(): void {
$this->load->language('api/sale/order');
$json = [];
// Add keys for missing post vars
$keys = [
'order_id',
'order_status_id',
'comment',
'notify',
'override'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder((int)$this->request->post['order_id']);
if (!$order_info) {
$json['error'] = $this->language->get('error_order');
}
if (!$json) {
$this->model_checkout_order->addHistory((int)$this->request->post['order_id'], (int)$this->request->post['order_status_id'], (string)$this->request->post['comment'], (bool)$this->request->post['notify'], (bool)$this->request->post['override']);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,134 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Payment Address
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class PaymentAddress extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/payment_address');
$json = [];
// Add keys for missing post vars
$keys = [
'firstname',
'lastname',
'company',
'address_1',
'address_2',
'postcode',
'city',
'zone_id',
'country_id'
];
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((int)$this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['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 ($country_info) {
$country = $country_info['name'];
$iso_code_2 = $country_info['iso_code_2'];
$iso_code_3 = $country_info['iso_code_3'];
$address_format = $country_info['address_format'];
} 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['zone_id']);
if ($zone_info) {
$zone = $zone_info['name'];
$zone_code = $zone_info['code'];
} else {
$zone = '';
$zone_code = '';
}
$this->session->data['payment_address'] = [
'address_id' => $this->request->post['payment_address_id'],
'firstname' => $this->request->post['firstname'],
'lastname' => $this->request->post['lastname'],
'company' => $this->request->post['company'],
'address_1' => $this->request->post['address_1'],
'address_2' => $this->request->post['address_2'],
'postcode' => $this->request->post['postcode'],
'city' => $this->request->post['city'],
'zone_id' => $this->request->post['zone_id'],
'zone' => $zone,
'zone_code' => $zone_code,
'country_id' => (int)$this->request->post['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['custom_field']) ? $this->request->post['custom_field'] : []
];
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Payment Method
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class PaymentMethod extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/payment_method');
$json = [];
if (!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) {
$json['error'] = $this->language->get('error_product');
}
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
$json['error'] = $this->language->get('error_payment_address');
}
if (!$json) {
$payment_address = [];
if (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'])) {
$payment_address = $this->session->data['shipping_address'];
}
$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'] = $this->language->get('error_no_payment');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('api/sale/payment_method');
$json = [];
// Payment Address
if ($this->config->get('config_checkout_payment_address') && !isset($this->session->data['payment_address'])) {
$json['error'] = $this->language->get('error_payment_address');
}
// Payment Method
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));
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Reward
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class Reward extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/reward');
$json = [];
if (isset($this->request->post['reward'])) {
$reward = abs((int)$this->request->post['reward']);
} else {
$reward = 0;
}
$available = $this->customer->getRewardPoints();
$points_total = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['points']) {
$points_total += $product['points'];
}
}
if ($reward) {
if ($reward > $available) {
$json['error'] = sprintf($this->language->get('error_points'), $this->request->post['reward']);
}
if ($reward > $points_total) {
$json['error'] = sprintf($this->language->get('error_maximum'), $points_total);
}
}
if (!$json) {
if ($reward) {
$json['success'] = $this->language->get('text_success');
$this->session->data['reward'] = $reward;
} else {
$json['success'] = $this->language->get('text_remove');
unset($this->session->data['reward']);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function maximum(): void {
$this->load->language('api/sale/reward');
$json = [];
$json['maximum'] = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['points']) {
$json['maximum'] += $product['points'];
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function available(): void {
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode(['points' => $this->customer->getRewardPoints()]));
}
}

View File

@@ -0,0 +1,138 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Shipping Address
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class ShippingAddress extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/shipping_address');
$json = [];
if ($this->cart->hasShipping()) {
// Add keys for missing post vars
$keys = [
'firstname',
'lastname',
'company',
'address_1',
'address_2',
'postcode',
'city',
'zone_id',
'country_id'
];
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((int)$this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['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']);
}
}
}
} else {
$json['error']['warning'] = $this->language->get('error_shipping');
}
if (!$json) {
if ($country_info) {
$country = $country_info['name'];
$iso_code_2 = $country_info['iso_code_2'];
$iso_code_3 = $country_info['iso_code_3'];
$address_format = $country_info['address_format'];
} 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['zone_id']);
if ($zone_info) {
$zone = $zone_info['name'];
$zone_code = $zone_info['code'];
} else {
$zone = '';
$zone_code = '';
}
$this->session->data['shipping_address'] = [
'address_id' => $this->request->post['shipping_address_id'],
'firstname' => $this->request->post['firstname'],
'lastname' => $this->request->post['lastname'],
'company' => $this->request->post['company'],
'address_1' => $this->request->post['address_1'],
'address_2' => $this->request->post['address_2'],
'postcode' => $this->request->post['postcode'],
'city' => $this->request->post['city'],
'zone_id' => $this->request->post['zone_id'],
'zone' => $zone,
'zone_code' => $zone_code,
'country_id' => (int)$this->request->post['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['custom_field']) ? $this->request->post['custom_field'] : []
];
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Shipping Method
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class ShippingMethod extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/shipping_method');
$json = [];
if ($this->cart->hasShipping()) {
if (!isset($this->session->data['shipping_address'])) {
$json['error'] = $this->language->get('error_shipping_address');
}
} else {
$json['error'] = $this->language->get('error_shipping');
}
if (!$json) {
$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'] = $this->language->get('error_no_shipping');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('api/sale/shipping_method');
$json = [];
if ($this->cart->hasShipping()) {
if (!isset($this->session->data['shipping_address'])) {
$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');
}
} else {
$json['error'] = $this->language->get('error_shipping');
}
if (!$json) {
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,147 @@
<?php
namespace Opencart\Catalog\Controller\Api\Sale;
/**
* Class Voucher
*
* @package Opencart\Catalog\Controller\Api\Sale
*/
class Voucher extends \Opencart\System\Engine\Controller {
// Apply voucher
/**
* @return void
*/
public function index(): void {
$this->load->language('api/sale/voucher');
$json = [];
if (isset($this->request->post['voucher'])) {
$voucher = (string)$this->request->post['voucher'];
} else {
$voucher = '';
}
if ($voucher) {
$this->load->model('checkout/voucher');
$voucher_info = $this->model_checkout_voucher->getVoucher($voucher);
if (!$voucher_info) {
$json['error'] = $this->language->get('error_voucher');
}
}
if (!$json) {
if ($voucher) {
$this->session->data['voucher'] = $this->request->post['voucher'];
$json['success'] = $this->language->get('text_success');
} else {
unset($this->session->data['voucher']);
$json['success'] = $this->language->get('text_remove');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function add(): void {
$this->load->language('api/sale/voucher');
$json = [];
// Add keys for missing post vars
$keys = [
'from_name',
'from_email',
'to_name',
'to_email',
'voucher_theme_id',
'message',
'amount'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
// Add a new voucher if set
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 ((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 (($this->request->post['amount'] < $this->config->get('config_voucher_min')) || ($this->request->post['amount'] > $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 (!$json) {
$code = oc_token();
$this->session->data['vouchers'][] = [
'code' => $code,
'description' => sprintf($this->language->get('text_for'), $this->currency->format($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')), $this->session->data['currency']), $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($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency'))
];
$json['success'] = $this->language->get('text_cart');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function remove(): void {
$this->load->language('api/sale/cart');
$json = [];
if (isset($this->request->post['key'])) {
$key = (int)$this->request->post['key'];
} else {
$key = '';
}
if (!isset($this->session->data['vouchers'][$key])) {
$json['error'] = $this->language->get('error_voucher');
}
// Remove
if (!$json) {
$json['success'] = $this->language->get('text_success');
unset($this->session->data['vouchers'][$key]);
unset($this->session->data['reward']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View 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));
}
}

View 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));
}
}

View 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());
}
}

View 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));
}
}

View 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));
}
}

View 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));
}
}

View 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));
}
}

View 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));
}
}

View 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));
}
}

View 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));
}
}

View 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));
}
}

View File

@@ -0,0 +1,453 @@
<?php
namespace Opencart\Catalog\Controller\Cms;
/**
* Class Blog
*
* @package Opencart\Catalog\Controller\Cms
*/
class Blog extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('cms/blog');
if (isset($this->request->get['search'])) {
$search = (string)$this->request->get['search'];
} else {
$search = '';
}
if (isset($this->request->get['topic_id'])) {
$topic_id = (int)$this->request->get['topic_id'];
} else {
$topic_id = 0;
}
if (isset($this->request->get['author'])) {
$author = (string)$this->request->get['author'];
} else {
$author = '';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
];
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . (string)$this->request->get['search'];
}
if (isset($this->request->get['author'])) {
$url .= '&author=' . (string)$this->request->get['author'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_blog'),
'href' => $this->url->link('cms/blog', 'language=' . $this->config->get('config_language') . $url)
];
$this->load->model('cms/topic');
$topic_info = $this->model_cms_topic->getTopic($topic_id);
if ($topic_info) {
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . (string)$this->request->get['search'];
}
if (isset($this->request->get['topic_id'])) {
$url .= '&topic_id=' . (int)$this->request->get['topic_id'];
}
if (isset($this->request->get['author'])) {
$url .= '&author=' . (string)$this->request->get['author'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'][] = [
'text' => $topic_info['name'],
'href' => $this->url->link('cms/blog', 'language=' . $this->config->get('config_language') . $url)
];
}
$this->load->model('tool/image');
if ($topic_info && is_file(DIR_IMAGE . html_entity_decode($topic_info['image'], ENT_QUOTES, 'UTF-8'))) {
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($topic_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_blog_width'), $this->config->get('config_image_blog_height'));
} else {
$data['thumb'] = '';
}
if ($topic_info) {
$this->document->setTitle($topic_info['meta_title']);
$this->document->setDescription($topic_info['meta_description']);
$this->document->setKeywords($topic_info['meta_keyword']);
$data['heading_title'] = $topic_info['name'];
} else {
$this->document->setTitle($this->language->get('heading_title'));
$data['heading_title'] = $this->language->get('heading_title');
}
if ($topic_info) {
$data['description'] = html_entity_decode($topic_info['description'], ENT_QUOTES, 'UTF-8');
} else {
$data['description'] = '';
}
$limit = 20;
$data['articles'] = [];
$filter_data = [
'filter_search' => $search,
'filter_topic_id' => $topic_id,
'filter_author' => $author,
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$this->load->model('cms/article');
$article_total = $this->model_cms_article->getTotalArticles($filter_data);
$results = $this->model_cms_article->getArticles($filter_data);
foreach ($results as $result) {
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_blog_width'), $this->config->get('config_image_blog_height'));
} else {
$image = '';
}
$data['articles'][] = [
'article_id' => $result['article_id'],
'image' => $image,
'name' => $result['name'],
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_article_description_length')) . '..',
'author' => $result['author'],
'comment_total' => $this->model_cms_article->getTotalComments($result['article_id']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'href' => $this->url->link('cms/blog.info', 'language=' . $this->config->get('config_language') . '&article_id=' . $result['article_id'] . $url)
];
}
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['topic_id'])) {
$url .= '&topic_id=' . $this->request->get['topic_id'];
}
if (isset($this->request->get['author'])) {
$url .= '&author=' . (string)$this->request->get['author'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $article_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('cms/blog', 'language=' . $this->config->get('config_language') . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($article_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($article_total - $limit)) ? $article_total : ((($page - 1) * $limit) + $limit), $article_total, ceil($article_total / $limit));
// http://googlewebmastercentral.articlespot.com/2011/09/pagination-with-relnext-and-relprev.html
if ($page == 1) {
$this->document->addLink($this->url->link('cms/blog', 'language=' . $this->config->get('config_language')), 'canonical');
} else {
$this->document->addLink($this->url->link('cms/blog', 'language=' . $this->config->get('config_language') . '&page='. $page), 'canonical');
}
if ($page > 1) {
$this->document->addLink($this->url->link('cms/blog', 'language=' . $this->config->get('config_language') . (($page - 2) ? '&page='. ($page - 1) : '')), 'prev');
}
if (ceil($article_total / $limit) > $page) {
$this->document->addLink($this->url->link('cms/blog', 'language=' . $this->config->get('config_language') . '&page='. ($page + 1)), 'next');
}
$data['search'] = $search;
$data['topic_id'] = $topic_id;
$data['topics'] = [];
$data['topics'][] = [
'name' => $this->language->get('text_all'),
'href' => $this->url->link('cms/blog', 'language=' . $this->config->get('config_language'))
];
$results = $this->model_cms_topic->getTopics();
foreach ($results as $result) {
$data['topics'][] = [
'name' => $result['name'],
'href' => $this->url->link('cms/blog', 'language=' . $this->config->get('config_language') . '&topic_id='. $result['topic_id'])
];
}
$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('cms/blog_list', $data));
}
public function info(): object|null {
$this->load->language('cms/blog');
if (isset($this->request->get['article_id'])) {
$article_id = (int)$this->request->get['article_id'];
} else {
$article_id = 0;
}
if (isset($this->request->get['topic_id'])) {
$topic_id = (int)$this->request->get['topic_id'];
} else {
$topic_id = 0;
}
$this->load->model('cms/article');
$article_info = $this->model_cms_article->getArticle($article_id);
if ($article_info) {
$this->document->setTitle($article_info['meta_title']);
$this->document->setDescription($article_info['meta_description']);
$this->document->setKeywords($article_info['meta_keyword']);
$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_blog'),
'href' => $this->url->link('cms/blog', 'language=' . $this->config->get('config_language'))
];
$url = '';
if (isset($this->request->get['topic_id'])) {
$url .= '&topic_id=' . $this->request->get['topic_id'];
}
if (isset($this->request->get['author'])) {
$url .= '&author=' . (string)$this->request->get['author'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->load->model('cms/topic');
$topic_info = $this->model_cms_topic->getTopic($topic_id);
if ($topic_info) {
$data['breadcrumbs'][] = [
'text' => $topic_info['name'],
'href' => $this->url->link('cms/article', 'language=' . $this->config->get('config_language') . $url)
];
}
$data['breadcrumbs'][] = [
'text' => $article_info['name'],
'href' => $this->url->link('cms/article.info', 'language=' . $this->config->get('config_language') . '&article_id=' . $article_id . $url)
];
$data['heading_title'] = $article_info['name'];
$data['description'] = html_entity_decode($article_info['description'], ENT_QUOTES, 'UTF-8');
$data['author'] = $article_info['author'];
$data['date_added'] = $article_info['date_added'];
$data['comment'] = $this->getComments();
$data['continue'] = $this->url->link('cms/article', 'language=' . $this->config->get('config_language') . $url);
$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('cms/blog_info', $data));
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
return null;
}
/**
* @return void
*/
public function comment() {
$this->load->language('cms/blog');
$this->response->setOutput($this->getComments());
}
/**
* @return string
*/
public function getComments(): string {
if (isset($this->request->get['article_id'])) {
$article_id = $this->request->get['article_id'];
} else {
$article_id = 0;
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$data['articles'] = [];
$this->load->model('cms/article');
$comment_total = $this->model_cms_article->getTotalComments($article_id);
$results = $this->model_cms_article->getComments($article_id, ($page - 1) * (int)$this->config->get('config_pagination_admin'), (int)$this->config->get('config_pagination_admin'));
foreach ($results as $result) {
$data['articles'][] = [
'text' => nl2br($result['text']),
'author' => $result['author'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $comment_total,
'page' => $page,
'limit' => 5,
'url' => $this->url->link('cms/blog.comment', 'language=' . $this->config->get('config_language') . '&article_id=' . $article_id . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($comment_total) ? (($page - 1) * 5) + 1 : 0, ((($page - 1) * 5) > ($comment_total - 5)) ? $comment_total : ((($page - 1) * 5) + 5), $comment_total, ceil($comment_total / 5));
return $this->load->view('cms/comment', $data);
}
public function addComment(): void {
$this->load->language('cms/article');
$json = array();
if (isset($this->request->get['article_id'])) {
$article_id = $this->request->get['article_id'];
} else {
$article_id = 0;
}
if (!isset($this->request->get['comment_token']) || !isset($this->session->data['comment_token']) || $this->request->get['comment_token'] != $this->session->data['comment_token']) {
$json['error']['warning'] = $this->language->get('error_token');
}
$keys = [
'comment',
'author'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
$this->load->model('cms/article');
$article_info = $this->model_cms_article->getArticle($article_id);
if (!$article_info) {
$json['error']['warning'] = $this->language->get('error_article');
}
if (!$this->customer->isLogged() && !$this->config->get('config_comment_guest')) {
$json['error']['warning'] = $this->language->get('error_guest');
}
if ((oc_strlen($this->request->post['author']) < 3) || (oc_strlen($this->request->post['author']) > 25)) {
$json['error']['author'] = $this->language->get('error_author');
}
if ((utf8_strlen($this->request->post['comment']) < 2) || (utf8_strlen($this->request->post['comment']) > 1000)) {
$json['error']['comment'] = $this->language->get('error_comment');
}
// 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('comment', (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) {
// Anti-Spam
$comment = str_replace(' ', '', $this->request->post['comment']);
$this->load->model('cms/antispam');
$spam = $this->model_cms_antispam->getSpam($comment);
if (!$this->customer->isCommentor() || $spam) {
$status = 0;
} else {
$status = 1;
}
$this->model_cms_article->addComment($article_id, $this->request->post + ['status' => $status]);
if (!$status) {
$json['success'] = $this->language->get('text_queue');
} else {
$json['success'] = $this->language->get('text_success');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,198 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Cart
*
* @package Opencart\Catalog\Controller\Common
*/
class Cart extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->language('common/cart');
$totals = [];
$taxes = $this->cart->getTaxes();
$total = 0;
$this->load->model('checkout/cart');
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
($this->model_checkout_cart->getTotals)($totals, $taxes, $total);
}
$data['text_items'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));
// Products
$data['products'] = [];
$products = $this->model_checkout_cart->getProducts();
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']);
}
}
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$unit_price = (float)$this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
$price = $this->currency->format($unit_price, $this->session->data['currency']);
$total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
} else {
$price = false;
$total = false;
}
$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);
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$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, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $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'],
'price' => $price,
'total' => $total,
'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 $key => $voucher) {
$data['vouchers'][] = [
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency'])
];
}
// Totals
$data['totals'] = [];
foreach ($totals as $total) {
$data['totals'][] = [
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $this->session->data['currency'])
];
}
$data['list'] = $this->url->link('common/cart.info', 'language=' . $this->config->get('config_language'));
$data['product_remove'] = $this->url->link('common/cart.removeProduct', 'language=' . $this->config->get('config_language'));
$data['voucher_remove'] = $this->url->link('common/cart.removeVoucher', 'language=' . $this->config->get('config_language'));
$data['cart'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'));
$data['checkout'] = $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'));
return $this->load->view('common/cart', $data);
}
/**
* @return void
*/
public function info(): void {
$this->response->setOutput($this->index());
}
/**
* @return void
*/
public function removeProduct(): 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');
}
if (!$json) {
$this->cart->remove($key);
$json['success'] = $this->language->get('text_remove');
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function removeVoucher(): void {
$this->load->language('checkout/cart');
$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) {
$json['success'] = $this->language->get('text_remove');
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));
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Column Left
*
* @package Opencart\Catalog\Controller\Common
*/
class ColumnLeft extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->model('design/layout');
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = 'common/home';
}
$layout_id = 0;
if ($route == 'product/category' && isset($this->request->get['path'])) {
$this->load->model('catalog/category');
$path = explode('_', (string)$this->request->get['path']);
$layout_id = $this->model_catalog_category->getLayoutId((int)end($path));
}
if ($route == 'product/product' && isset($this->request->get['product_id'])) {
$this->load->model('catalog/product');
$layout_id = $this->model_catalog_product->getLayoutId((int)$this->request->get['product_id']);
}
if ($route == 'product/manufacturer.info' && isset($this->request->get['manufacturer_id'])) {
$this->load->model('catalog/manufacturer');
$layout_id = $this->model_catalog_manufacturer->getLayoutId((int)$this->request->get['manufacturer_id']);
}
if ($route == 'information/information' && isset($this->request->get['information_id'])) {
$this->load->model('catalog/information');
$layout_id = $this->model_catalog_information->getLayoutId((int)$this->request->get['information_id']);
}
if ($route == 'cms/blog.info' && isset($this->request->get['blog_id'])) {
$this->load->model('cms/blog');
$layout_id = $this->model_cms_blog->getLayoutId((int)$this->request->get['blog_id']);
}
if (!$layout_id) {
$layout_id = $this->model_design_layout->getLayout($route);
}
if (!$layout_id) {
$layout_id = $this->config->get('config_layout_id');
}
$this->load->model('setting/module');
$data['modules'] = [];
$modules = $this->model_design_layout->getModules($layout_id, 'column_left');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
if (isset($part[1]) && $this->config->get('module_' . $part[1] . '_status')) {
$module_data = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1]);
if ($module_data) {
$data['modules'][] = $module_data;
}
}
if (isset($part[2])) {
$setting_info = $this->model_setting_module->getModule($part[2]);
if ($setting_info && $setting_info['status']) {
$output = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1], $setting_info);
if ($output) {
$data['modules'][] = $output;
}
}
}
}
return $this->load->view('common/column_left', $data);
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Column Right
*
* @package Opencart\Catalog\Controller\Common
*/
class ColumnRight extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->model('design/layout');
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = 'common/home';
}
$layout_id = 0;
if ($route == 'product/category' && isset($this->request->get['path'])) {
$this->load->model('catalog/category');
$path = explode('_', (string)$this->request->get['path']);
$layout_id = $this->model_catalog_category->getLayoutId((int)end($path));
}
if ($route == 'product/product' && isset($this->request->get['product_id'])) {
$this->load->model('catalog/product');
$layout_id = $this->model_catalog_product->getLayoutId((int)$this->request->get['product_id']);
}
if ($route == 'product/manufacturer.info' && isset($this->request->get['manufacturer_id'])) {
$this->load->model('catalog/manufacturer');
$layout_id = $this->model_catalog_manufacturer->getLayoutId((int)$this->request->get['manufacturer_id']);
}
if ($route == 'information/information' && isset($this->request->get['information_id'])) {
$this->load->model('catalog/information');
$layout_id = $this->model_catalog_information->getLayoutId((int)$this->request->get['information_id']);
}
if ($route == 'cms/blog.info' && isset($this->request->get['blog_id'])) {
$this->load->model('cms/blog');
$layout_id = $this->model_cms_blog->getLayoutId((int)$this->request->get['blog_id']);
}
if (!$layout_id) {
$layout_id = $this->model_design_layout->getLayout($route);
}
if (!$layout_id) {
$layout_id = $this->config->get('config_layout_id');
}
$this->load->model('setting/module');
$data['modules'] = [];
$modules = $this->model_design_layout->getModules($layout_id, 'column_right');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
if (isset($part[1]) && $this->config->get('module_' . $part[1] . '_status')) {
$module_data = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1]);
if ($module_data) {
$data['modules'][] = $module_data;
}
}
if (isset($part[2])) {
$setting_info = $this->model_setting_module->getModule($part[2]);
if ($setting_info && $setting_info['status']) {
$output = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1], $setting_info);
if ($output) {
$data['modules'][] = $output;
}
}
}
}
return $this->load->view('common/column_right', $data);
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Content Bottom
*
* @package Opencart\Catalog\Controller\Common
*/
class ContentBottom extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->model('design/layout');
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = 'common/home';
}
$layout_id = 0;
if ($route == 'product/category' && isset($this->request->get['path'])) {
$this->load->model('catalog/category');
$path = explode('_', (string)$this->request->get['path']);
$layout_id = $this->model_catalog_category->getLayoutId((int)end($path));
}
if ($route == 'product/product' && isset($this->request->get['product_id'])) {
$this->load->model('catalog/product');
$layout_id = $this->model_catalog_product->getLayoutId((int)$this->request->get['product_id']);
}
if ($route == 'product/manufacturer.info' && isset($this->request->get['manufacturer_id'])) {
$this->load->model('catalog/manufacturer');
$layout_id = $this->model_catalog_manufacturer->getLayoutId((int)$this->request->get['manufacturer_id']);
}
if ($route == 'information/information' && isset($this->request->get['information_id'])) {
$this->load->model('catalog/information');
$layout_id = $this->model_catalog_information->getLayoutId((int)$this->request->get['information_id']);
}
if ($route == 'cms/blog.info' && isset($this->request->get['blog_id'])) {
$this->load->model('cms/blog');
$layout_id = $this->model_cms_blog->getLayoutId((int)$this->request->get['blog_id']);
}
if (!$layout_id) {
$layout_id = $this->model_design_layout->getLayout($route);
}
if (!$layout_id) {
$layout_id = $this->config->get('config_layout_id');
}
$this->load->model('setting/module');
$data['modules'] = [];
$modules = $this->model_design_layout->getModules($layout_id, 'content_bottom');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
if (isset($part[1]) && $this->config->get('module_' . $part[1] . '_status')) {
$module_data = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1]);
if ($module_data) {
$data['modules'][] = $module_data;
}
}
if (isset($part[2])) {
$setting_info = $this->model_setting_module->getModule($part[2]);
if ($setting_info && $setting_info['status']) {
$output = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1], $setting_info);
if ($output) {
$data['modules'][] = $output;
}
}
}
}
return $this->load->view('common/content_bottom', $data);
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Content Top
*
* @package Opencart\Catalog\Controller\Common
*/
class ContentTop extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->model('design/layout');
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = 'common/home';
}
$layout_id = 0;
if ($route == 'product/category' && isset($this->request->get['path'])) {
$this->load->model('catalog/category');
$path = explode('_', (string)$this->request->get['path']);
$layout_id = $this->model_catalog_category->getLayoutId((int)end($path));
}
if ($route == 'product/product' && isset($this->request->get['product_id'])) {
$this->load->model('catalog/product');
$layout_id = $this->model_catalog_product->getLayoutId((int)$this->request->get['product_id']);
}
if ($route == 'product/manufacturer.info' && isset($this->request->get['manufacturer_id'])) {
$this->load->model('catalog/manufacturer');
$layout_id = $this->model_catalog_manufacturer->getLayoutId((int)$this->request->get['manufacturer_id']);
}
if ($route == 'information/information' && isset($this->request->get['information_id'])) {
$this->load->model('catalog/information');
$layout_id = $this->model_catalog_information->getLayoutId((int)$this->request->get['information_id']);
}
if ($route == 'cms/blog.info' && isset($this->request->get['blog_id'])) {
$this->load->model('cms/blog');
$layout_id = $this->model_cms_blog->getLayoutId((int)$this->request->get['blog_id']);
}
if (!$layout_id) {
$layout_id = $this->model_design_layout->getLayout($route);
}
if (!$layout_id) {
$layout_id = $this->config->get('config_layout_id');
}
$this->load->model('setting/module');
$data['modules'] = [];
$modules = $this->model_design_layout->getModules($layout_id, 'content_top');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
if (isset($part[1]) && $this->config->get('module_' . $part[1] . '_status')) {
$module_data = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1]);
if ($module_data) {
$data['modules'][] = $module_data;
}
}
if (isset($part[2])) {
$setting_info = $this->model_setting_module->getModule($part[2]);
if ($setting_info && $setting_info['status']) {
$output = $this->load->controller('extension/' . $part[0] . '/module/' . $part[1], $setting_info);
if ($output) {
$data['modules'][] = $output;
}
}
}
}
return $this->load->view('common/content_top', $data);
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Cookie
*
* @package Opencart\Catalog\Controller\Common
*/
class Cookie extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
if ($this->config->get('config_cookie_id') && !isset($this->request->cookie['policy'])) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_cookie_id'));
if ($information_info) {
$this->load->language('common/cookie');
$data['text_cookie'] = sprintf($this->language->get('text_cookie'), $this->url->link('information/information.info', 'language=' . $this->config->get('config_language') . '&information_id=' . $information_info['information_id']));
$data['agree'] = $this->url->link('common/cookie.confirm', 'language=' . $this->config->get('config_language') . '&agree=1');
$data['disagree'] = $this->url->link('common/cookie.confirm', 'language=' . $this->config->get('config_language') . '&agree=0');
return $this->load->view('common/cookie', $data);
}
}
return '';
}
/**
* @return void
*/
public function confirm(): void {
$json = [];
if ($this->config->get('config_cookie_id') && !isset($this->request->cookie['policy'])) {
$this->load->language('common/cookie');
if (isset($this->request->get['agree'])) {
$agree = (int)$this->request->get['agree'];
} else {
$agree = 0;
}
$option = [
'expires' => time() + 60 * 60 * 24 * 365,
'path' => $this->config->get('session_path'),
'SameSite' => $this->config->get('config_session_samesite')
];
setcookie('policy', $agree, $option);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Currency
*
* @package Opencart\Catalog\Controller\Common
*/
class Currency extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->language('common/currency');
$data['action'] = $this->url->link('common/currency.save', 'language=' . $this->config->get('config_language'));
$data['code'] = $this->session->data['currency'];
$url_data = $this->request->get;
if (isset($url_data['route'])) {
$route = $url_data['route'];
} else {
$route = $this->config->get('action_default');
}
unset($url_data['route']);
unset($url_data['_route_']);
$data['currencies'] = [];
$this->load->model('localisation/currency');
$results = $this->model_localisation_currency->getCurrencies();
foreach ($results as $result) {
if ($result['status']) {
$data['currencies'][] = [
'title' => $result['title'],
'code' => $result['code'],
'symbol_left' => $result['symbol_left'],
'symbol_right' => $result['symbol_right']
];
}
}
$url = '';
if ($url_data) {
$url .= '&' . urldecode(http_build_query($url_data, '', '&'));
}
$data['redirect'] = $this->url->link($route, $url);
return $this->load->view('common/currency', $data);
}
/**
* @return void
*/
public function save(): void {
if (isset($this->request->post['code'])) {
$this->session->data['currency'] = $this->request->post['code'];
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
}
$option = [
'expires' => time() + 60 * 60 * 24 * 30,
'path' => '/',
'SameSite' => 'Lax'
];
setcookie('currency', $this->session->data['currency'], $option);
if (isset($this->request->post['redirect']) && substr($this->request->post['redirect'], 0, strlen($this->config->get('config_url'))) == $this->config->get('config_url')) {
$this->response->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
} else {
$this->response->redirect($this->url->link($this->config->get('action_default')));
}
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Footer
*
* @package Opencart\Catalog\Controller\Common
*/
class Footer extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->language('common/footer');
$data['blog'] = $this->url->link('cms/blog', 'language=' . $this->config->get('config_language'));
$this->load->model('catalog/information');
$data['informations'] = [];
foreach ($this->model_catalog_information->getInformations() as $result) {
if ($result['bottom']) {
$data['informations'][] = [
'title' => $result['title'],
'href' => $this->url->link('information/information', 'language=' . $this->config->get('config_language') . '&information_id=' . $result['information_id'])
];
}
}
$data['contact'] = $this->url->link('information/contact', 'language=' . $this->config->get('config_language'));
$data['return'] = $this->url->link('account/returns.add', 'language=' . $this->config->get('config_language'));
if ($this->config->get('config_gdpr_id')) {
$data['gdpr'] = $this->url->link('information/gdpr', 'language=' . $this->config->get('config_language'));
} else {
$data['gdpr'] = '';
}
$data['sitemap'] = $this->url->link('information/sitemap', 'language=' . $this->config->get('config_language'));
$data['manufacturer'] = $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'));
$data['voucher'] = $this->url->link('checkout/voucher', 'language=' . $this->config->get('config_language'));
if ($this->config->get('config_affiliate_status')) {
$data['affiliate'] = $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
} else {
$data['affiliate'] = '';
}
$data['special'] = $this->url->link('product/special', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['account'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['order'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['wishlist'] = $this->url->link('account/wishlist', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['newsletter'] = $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['powered'] = sprintf($this->language->get('text_powered'), $this->config->get('config_name'), date('Y', time()));
// Who's Online
if ($this->config->get('config_customer_online')) {
$this->load->model('tool/online');
if (isset($this->request->server['HTTP_X_REAL_IP'])) {
$ip = $this->request->server['HTTP_X_REAL_IP'];
} elseif (isset($this->request->server['REMOTE_ADDR'])) {
$ip = $this->request->server['REMOTE_ADDR'];
} else {
$ip = '';
}
if (isset($this->request->server['HTTP_HOST']) && isset($this->request->server['REQUEST_URI'])) {
$url = ($this->request->server['HTTPS'] ? 'https://' : 'http://') . $this->request->server['HTTP_HOST'] . $this->request->server['REQUEST_URI'];
} else {
$url = '';
}
if (isset($this->request->server['HTTP_REFERER'])) {
$referer = $this->request->server['HTTP_REFERER'];
} else {
$referer = '';
}
$this->model_tool_online->addOnline($ip, $this->customer->getId(), $url, $referer);
}
$data['bootstrap'] = 'catalog/view/javascript/bootstrap/js/bootstrap.bundle.min.js';
$data['scripts'] = $this->document->getScripts('footer');
$data['cookie'] = $this->load->controller('common/cookie');
return $this->load->view('common/footer', $data);
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Header
*
* @package Opencart\Catalog\Controller\Common
*/
class Header extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
// Analytics
$data['analytics'] = [];
if (!$this->config->get('config_cookie_id') || (isset($this->request->cookie['policy']) && $this->request->cookie['policy'])) {
$this->load->model('setting/extension');
$analytics = $this->model_setting_extension->getExtensionsByType('analytics');
foreach ($analytics as $analytic) {
if ($this->config->get('analytics_' . $analytic['code'] . '_status')) {
$data['analytics'][] = $this->load->controller('extension/' . $analytic['extension'] . '/analytics/' . $analytic['code'], $this->config->get('analytics_' . $analytic['code'] . '_status'));
}
}
}
$data['lang'] = $this->language->get('code');
$data['direction'] = $this->language->get('direction');
$data['title'] = $this->document->getTitle();
$data['base'] = $this->config->get('config_url');
$data['description'] = $this->document->getDescription();
$data['keywords'] = $this->document->getKeywords();
// Hard coding css so they can be replaced via the event's system.
$data['bootstrap'] = 'catalog/view/stylesheet/bootstrap.css';
$data['icons'] = 'catalog/view/stylesheet/fonts/fontawesome/css/all.min.css';
$data['stylesheet'] = 'catalog/view/stylesheet/stylesheet.css';
// Hard coding scripts so they can be replaced via the event's system.
$data['jquery'] = 'catalog/view/javascript/jquery/jquery-3.7.1.min.js';
$data['links'] = $this->document->getLinks();
$data['styles'] = $this->document->getStyles();
$data['scripts'] = $this->document->getScripts('header');
$data['name'] = $this->config->get('config_name');
if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
$data['logo'] = $this->config->get('config_url') . 'image/' . $this->config->get('config_logo');
} else {
$data['logo'] = '';
}
$this->load->language('common/header');
// Wishlist
if ($this->customer->isLogged()) {
$this->load->model('account/wishlist');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());
} else {
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
}
$data['home'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
$data['wishlist'] = $this->url->link('account/wishlist', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
$data['logged'] = $this->customer->isLogged();
if (!$this->customer->isLogged()) {
$data['register'] = $this->url->link('account/register', 'language=' . $this->config->get('config_language'));
$data['login'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'));
} else {
$data['account'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['order'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['transaction'] = $this->url->link('account/transaction', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['download'] = $this->url->link('account/download', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
$data['logout'] = $this->url->link('account/logout', 'language=' . $this->config->get('config_language'));
}
$data['shopping_cart'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'));
$data['checkout'] = $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'));
$data['contact'] = $this->url->link('information/contact', 'language=' . $this->config->get('config_language'));
$data['telephone'] = $this->config->get('config_telephone');
$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');
$data['menu'] = $this->load->controller('common/menu');
return $this->load->view('common/header', $data);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Home
*
* @package Opencart\Catalog\Controller\Common
*/
class Home extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->document->setTitle($this->config->get('config_meta_title'));
$this->document->setDescription($this->config->get('config_meta_description'));
$this->document->setKeywords($this->config->get('config_meta_keyword'));
$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/home', $data));
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Language
*
* @package Opencart\Catalog\Controller\Common
*/
class Language extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->language('common/language');
$url_data = $this->request->get;
if (isset($url_data['route'])) {
$route = $url_data['route'];
} else {
$route = $this->config->get('action_default');
}
unset($url_data['route']);
unset($url_data['_route_']);
unset($url_data['language']);
$url = '';
if ($url_data) {
$url .= '&' . urldecode(http_build_query($url_data));
}
// Added so the correct SEO language URL is used.
$language_id = $this->config->get('config_language_id');
$data['languages'] = [];
$this->load->model('localisation/language');
$results = $this->model_localisation_language->getLanguages();
foreach ($results as $result) {
$this->config->set('config_language_id', $result['language_id']);
$data['languages'][] = [
'name' => $result['name'],
'code' => $result['code'],
'image' => $result['image'],
'href' => $this->url->link($route, 'language=' . $result['code'] . $url, true)
];
}
$this->config->set('config_language_id', $language_id);
$data['code'] = $this->config->get('config_language');
return $this->load->view('common/language', $data);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Maintenance
*
* @package Opencart\Catalog\Controller\Common
*/
class Maintenance extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('common/maintenance');
$this->document->setTitle($this->language->get('heading_title'));
if ($this->request->server['SERVER_PROTOCOL'] == 'HTTP/1.1') {
$this->response->addHeader('HTTP/1.1 503 Service Unavailable');
} else {
$this->response->addHeader('HTTP/1.0 503 Service Unavailable');
}
$this->response->addHeader('Retry-After: 3600');
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_maintenance'),
'href' => $this->url->link('common/maintenance', 'language=' . $this->config->get('config_language'))
];
$data['message'] = $this->language->get('text_message');
$data['header'] = $this->load->controller('common/header');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('common/maintenance', $data));
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Menu
*
* @package Opencart\Catalog\Controller\Common
*/
class Menu extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->language('common/menu');
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = [];
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = [];
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = [
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
];
$children_data[] = [
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category['category_id'] . '_' . $child['category_id'])
];
}
// Level 1
$data['categories'][] = [
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category['category_id'])
];
}
}
return $this->load->view('common/menu', $data);
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Pagination
*
* @package Opencart\Catalog\Controller\Common
*/
class Pagination extends \Opencart\System\Engine\Controller {
/**
* @param array $setting
*
* @return string
*/
public function index(array $setting): string {
if (isset($setting['total'])) {
$total = $setting['total'];
} else {
$total = 0;
}
if (isset($setting['page']) && $setting['page'] > 0) {
$page = (int)$setting['page'];
} else {
$page = 1;
}
if (isset($setting['limit']) && (int)$setting['limit']) {
$limit = (int)$setting['limit'];
} else {
$limit = 10;
}
if (isset($setting['url'])) {
$url = str_replace('%7Bpage%7D', '{page}', (string)$setting['url']);
} else {
$url = '';
}
$num_links = 8;
$num_pages = ceil($total / $limit);
if ($url && $page > 1 && $num_pages < $page) {
$back = true;
} else {
$back = false;
}
$data['page'] = $page;
if ($page > 1) {
$data['first'] = str_replace(['&amp;page={page}', '?page={page}', '&page={page}'], '', $url);
if ($page - 1 === 1) {
$data['prev'] = str_replace(['&amp;page={page}', '?page={page}', '&page={page}'], '', $url);
} else {
$data['prev'] = str_replace('{page}', $page - 1, $url);
}
} else {
$data['first'] = '';
$data['prev'] = '';
}
$data['links'] = [];
if ($num_pages > 1) {
if ($num_pages <= $num_links) {
$start = 1;
$end = $num_pages;
} else {
$start = $page - floor($num_links / 2);
$end = $page + floor($num_links / 2);
if ($start < 1) {
$end += abs($start) + 1;
$start = 1;
}
if ($end > $num_pages) {
$start -= ($end - $num_pages);
$end = $num_pages;
}
}
for ($i = $start; $i <= $end; $i++) {
$data['links'][] = [
'page' => $i,
'href' => str_replace('{page}', $i, $url)
];
}
}
if ($num_pages > $page) {
$data['next'] = str_replace('{page}', $page + 1, $url);
$data['last'] = str_replace('{page}', $num_pages, $url);
} else {
$data['next'] = '';
$data['last'] = '';
}
if ($num_pages > 1 || $back) {
return $this->load->view('common/pagination', $data);
} else {
return '';
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Opencart\Catalog\Controller\Common;
/**
* Class Search
*
* @package Opencart\Catalog\Controller\Common
*/
class Search extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->language('common/search');
$data['text_search'] = $this->language->get('text_search');
if (isset($this->request->get['search'])) {
$data['search'] = $this->request->get['search'];
} else {
$data['search'] = '';
}
$data['language'] = $this->config->get('config_language');
return $this->load->view('common/search', $data);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Opencart\Catalog\Controller\Cron;
/**
* Class Cron
*
* @package Opencart\Catalog\Controller\Cron
*/
class Cron extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$time = time();
$this->load->model('setting/cron');
$results = $this->model_setting_cron->getCrons();
foreach ($results as $result) {
if ($result['status'] && (strtotime('+1 ' . $result['cycle'], strtotime($result['date_modified'])) < ($time + 10))) {
$this->load->controller($result['action'], $result['cron_id'], $result['code'], $result['cycle'], $result['date_added'], $result['date_modified']);
$this->model_setting_cron->editCron($result['cron_id']);
}
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Opencart\Catalog\Controller\Cron;
/**
* Class Currency
*
* @package Opencart\Catalog\Controller\Cron
*/
class Currency extends \Opencart\System\Engine\Controller {
/**
* @param int $cron_id
* @param string $code
* @param string $cycle
* @param string $date_added
* @param string $date_modified
*
* @return void
*/
public function index(int $cron_id, string $code, string $cycle, string $date_added, string $date_modified): void {
$this->load->model('setting/extension');
$extension_info = $this->model_setting_extension->getExtensionByCode('currency', $this->config->get('config_currency_engine'));
if ($extension_info) {
$this->load->controller('extension/' . $extension_info['extension'] . '/currency/' . $extension_info['code'] . '.currency', $this->config->get('config_currency'));
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Opencart\Catalog\Controller\Cron;
/**
* Class Gdpr
*
* @package Opencart\Catalog\Controller\Cron
*/
class Gdpr extends \Opencart\System\Engine\Controller {
/**
* @param int $cron_id
* @param string $code
* @param string $cycle
* @param string $date_added
* @param string $date_modified
*
* @return void
*/
public function index(int $cron_id, string $code, string $cycle, string $date_added, string $date_modified): void {
$this->load->model('account/gdpr');
$this->load->model('account/customer');
$results = $this->model_account_gdpr->getExpires();
foreach ($results as $result) {
$this->model_account_gdpr->editStatus($result['gdpr_id'], 3);
$customer_info = $this->model_account_customer->getCustomerByEmail($result['email']);
if ($customer_info) {
$this->model_account_customer->deleteCustomer($customer_info['customer_id']);
}
}
}
}

View File

@@ -0,0 +1,480 @@
<?php
namespace Opencart\Catalog\Controller\Cron;
/**
* Class Subscription
*
* @package Opencart\Catalog\Controller\Cron
*/
class Subscription extends \Opencart\System\Engine\Controller {
/**
* Index
*
* @param int $cron_id
* @param string $code
* @param string $cycle
* @param string $date_added
* @param string $date_modified
*
* @return void
*/
public function index(int $cron_id, string $code, string $cycle, string $date_added, string $date_modified): void {
$this->load->language('cron/subscription');
// Check the there is an order and the order status is complete and subscription status is active
$filter_data = [
'filter_date_next' => date('Y-m-d H:i:s'),
'filter_subscription_status_id' => $this->config->get('config_subscription_active_status_id'),
'start' => 0,
'limit' => 10
];
// Get all
$this->load->model('checkout/subscription');
$this->load->model('checkout/order');
$results = $this->model_checkout_subscription->getSubscriptions($filter_data);
foreach ($results as $result) {
$order_info = $this->model_checkout_order->getOrder($result['order_id']);
// Check the there is an order and the order status is complete and subscription status is active
if ($order_info && in_array($order_info['order_status_id'], (array)$this->config->get('config_complete_status'))) {
$this->load->model('setting/store');
$error = '';
// 1. Language
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($result['language_id']);
if (!$language_info) {
$error = $this->language->get('error_language');
}
// 2. Currency
$this->load->model('localisation/currency');
$currency_info = $this->model_localisation_currency->getCurrency($result['currency_id']);
if (!$currency_info) {
$error = $this->language->get('error_currency');
}
// 3. Create new instance of a store
if (!$error) {
$store = $this->model_setting_store->createStoreInstance($result['store_id'], $language_info['code']);
// Login
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomer($result['customer_id']);
if ($customer_info && $this->customer->login($customer_info['email'], '', true)) {
// Add customer details into session
$store->session->data['customer'] = [
'customer_id' => $customer_info['customer_id'],
'customer_group_id' => $customer_info['customer_group_id'],
'firstname' => $customer_info['firstname'],
'lastname' => $customer_info['lastname'],
'email' => $customer_info['email'],
'telephone' => $customer_info['telephone'],
'custom_field' => $customer_info['custom_field']
];
} else {
$error = $this->language->get('error_customer');
}
}
// 4. Add product
if (!$error) {
$this->load->model('catalog/product');
$product_info = $this->model_checkout_order->getProduct($result['product_id']);
if ($product_info) {
$option_data = [];
$order_options = $this->model_account_order->getOptions($result['order_id'], $result['order_product_id']);
foreach ($order_options as $order_option) {
if ($order_option['type'] == 'select' || $order_option['type'] == 'radio' || $order_option['type'] == 'image') {
$option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'checkbox') {
$option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'text' || $order_option['type'] == 'textarea' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
} elseif ($order_option['type'] == 'file') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
}
}
$store->cart->add($result['product_id'], $result['quantity'], $option_data);
} else {
$error = $this->language->get('error_product');
}
}
// 5. Add Shipping Address
if (!$error && $store->cart->hasShipping()) {
$this->load->model('account/address');
$shipping_address_info = $this->model_account_address->getAddress($result['customer_id'], $result['shipping_address_id']);
if ($shipping_address_info) {
$store->session->data['shipping_address'] = $shipping_address_info;
} else {
$error = $this->language->get('error_shipping_address');
}
// 5. Shipping Methods
if (!$error) {
$this->load->model('checkout/shipping_method');
$shipping_methods = $this->model_checkout_shipping_method->getMethods($shipping_address_info);
// Validate shipping method
if (isset($order_info['shipping_method']['code']) && $shipping_methods) {
$shipping = explode('.', $order_info['shipping_method']['code']);
if (isset($shipping[0]) && isset($shipping[1]) && isset($shipping_methods[$shipping[0]]['quote'][$shipping[1]])) {
$store->session->data['shipping_method'] = $shipping_methods[$shipping[0]]['quote'][$shipping[1]];
} else {
$error = $this->language->get('error_shipping_method');
}
} else {
$error = $this->language->get('error_shipping_method');
}
}
}
// 6. Payment Address
$payment_address = [];
if (!$error && $this->config->get('config_checkout_payment_address')) {
$this->load->model('account/address');
$payment_address_info = $this->model_account_address->getAddress($order_info['customer_id'], $result['payment_address_id']);
if ($payment_address_info) {
$store->session->data['payment_address'] = $payment_address_info;
} else {
$error = $this->language->get('error_payment_address');
}
}
// 7. Payment Methods
if (!$error) {
$this->load->model('checkout/payment_method');
$payment_methods = $this->model_checkout_payment_method->getMethods($payment_address);
// Validate payment methods
if (isset($order_info['payment_method']['code']) && $payment_methods) {
$payment = explode('.', $order_info['payment_method']['code']);
if (isset($payment[0]) && isset($payment[1]) && isset($payment_methods[$payment[0]]['option'][$payment[1]])) {
$store->session->data['payment_method'] = $payment_methods[$payment[0]]['option'][$payment[1]];
} else {
$error = $this->language->get('error_payment_method');
}
} else {
$error = $this->language->get('error_payment_method');
}
}
if (!$error) {
$this->load->model('marketing/marketing');
$marketing_info = $this->model_marketing_marketing->getMarketingByCode($this->session->data['tracking']);
$order_data['language_id'] = $this->config->get('config_language_id');
}
if (!$error) {
// Subscription
$order_data['subscription_id'] = $order_info['subscription_id'];
// Store Details
$order_data['invoice_prefix'] = $order_info['invoice_prefix'];
$order_data['store_id'] = $order_info['store_id'];
$order_data['store_name'] = $order_info['store_name'];
$order_data['store_url'] = $order_info['store_url'];
// Customer Details
$order_data['customer_id'] = $customer_info['customer_id'];
$order_data['customer_group_id'] = $customer_info['customer_group_id'];
$order_data['firstname'] = $customer_info['firstname'];
$order_data['lastname'] = $customer_info['lastname'];
$order_data['email'] = $customer_info['email'];
$order_data['telephone'] = $customer_info['telephone'];
$order_data['custom_field'] = $customer_info['custom_field'];
// Payment Details
if ($payment_address_info) {
$order_data['payment_address_id'] = $payment_address_info['address_id'];
$order_data['payment_firstname'] = $payment_address_info['firstname'];
$order_data['payment_lastname'] = $payment_address_info['lastname'];
$order_data['payment_company'] = $payment_address_info['company'];
$order_data['payment_address_1'] = $payment_address_info['address_1'];
$order_data['payment_address_2'] = $payment_address_info['address_2'];
$order_data['payment_city'] = $payment_address_info['city'];
$order_data['payment_postcode'] = $payment_address_info['postcode'];
$order_data['payment_zone'] = $payment_address_info['zone'];
$order_data['payment_zone_id'] = $payment_address_info['zone_id'];
$order_data['payment_country'] = $payment_address_info['country'];
$order_data['payment_country_id'] = $payment_address_info['country_id'];
$order_data['payment_address_format'] = $payment_address_info['address_format'];
$order_data['payment_custom_field'] = $payment_address_info['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 ($store->cart->hasShipping()) {
$order_data['shipping_address_id'] = $shipping_address_info['address_id'];
$order_data['shipping_firstname'] = $shipping_address_info['firstname'];
$order_data['shipping_lastname'] = $shipping_address_info['lastname'];
$order_data['shipping_company'] = $shipping_address_info['company'];
$order_data['shipping_address_1'] = $shipping_address_info['address_1'];
$order_data['shipping_address_2'] = $shipping_address_info['address_2'];
$order_data['shipping_city'] = $shipping_address_info['city'];
$order_data['shipping_postcode'] = $shipping_address_info['postcode'];
$order_data['shipping_zone'] = $shipping_address_info['zone'];
$order_data['shipping_zone_id'] = $shipping_address_info['zone_id'];
$order_data['shipping_country'] = $shipping_address_info['country'];
$order_data['shipping_country_id'] = $shipping_address_info['country_id'];
$order_data['shipping_address_format'] = $shipping_address_info['address_format'];
$order_data['shipping_custom_field'] = $shipping_address_info['custom_field'];
$order_data['shipping_method'] = $payment_methods[$payment[0]]['option'][$payment[1]];
} 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'] = [];
}
// Products
$order_data['products'] = [];
$products = $this->model_checkout_cart->getProducts();
foreach ($products as $product) {
$order_data['products'][] = [
'product_id' => $product['product_id'],
'master_id' => $product['master_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $product['option'],
'subscription' => [],
'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']
];
}
// Vouchers can not be in subscriptions
$order_data['vouchers'] = [];
// Order Totals
$totals = [];
$taxes = $store->cart->getTaxes();
$total = 0;
$store->load->model('checkout/cart');
($store->model_checkout_cart->getTotals)($totals, $taxes, $total);
$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'];
}
}
// Language
$order_data['language_id'] = $language_info['language_id'];
$order_data['language_code'] = $language_info['code'];
// Currency
$order_data['currency_id'] = $currency_info['currency_id'];
$order_data['currency_code'] = $currency_info['code'];
$order_data['currency_value'] = $currency_info['value'];
$order_data['ip'] = $result['ip'];
$order_data['forwarded_ip'] = $result['forwarded_ip'];
$order_data['user_agent'] = $result['user_agent'];
$order_data['accept_language'] = $result['accept_language'];
}
if ($result['trial_status'] && (!$result['trial_duration'] || $result['trial_remaining'])) {
$amount = $result['trial_price'];
} elseif (!$result['duration'] || $result['remaining']) {
$amount = $result['price'];
}
$subscription_status_id = $this->config->get('config_subscription_status_id');
// Get the payment method used by the subscription
// Check payment status
//$this->load->model('extension/payment/' . $payment_info['code']);
/*
if ($product['subscription']) {
if ($product['subscription']['trial_duration'] && $product['subscription']['trial_remaining']) {
$date_next = date('Y-m-d', strtotime('+' . $product['subscription']['trial_cycle'] . ' ' . $product['subscription']['trial_frequency']));
} elseif ($product['subscription']['duration'] && $product['subscription']['remaining']) {
$date_next = date('Y-m-d', strtotime('+' . $product['subscription']['cycle'] . ' ' . $product['subscription']['frequency']));
}
$subscription_data = [
'subscription_plan_id' => $product['subscription']['subscription_plan_id'],
'name' => $product['subscription']['name'],
'trial_price' => $product['subscription']['trial_price'],
'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'],
'frequency' => $product['subscription']['frequency'],
'cycle' => $product['subscription']['cycle'],
'duration' => $product['subscription']['duration'],
'remaining' => $product['subscription']['duration'],
'date_next' => $date_next
];
}
*/
// Transaction
if ($this->config->get('config_subscription_active_status_id') == $subscription_status_id) {
if ($result['trial_duration'] && $result['trial_remaining']) {
$date_next = date('Y-m-d', strtotime('+' . $result['trial_cycle'] . ' ' . $result['trial_frequency']));
} elseif ($result['duration'] && $result['remaining']) {
$date_next = date('Y-m-d', strtotime('+' . $result['cycle'] . ' ' . $result['frequency']));
}
$filter_data = [
'filter_date_next' => $date_next,
'filter_subscription_status_id' => $subscription_status_id,
'start' => 0,
'limit' => 1
];
$subscriptions = $this->model_account_subscription->getSubscriptions($filter_data);
if ($subscriptions) {
// Only match the latest order ID of the same customer ID
// since new subscriptions cannot be re-added with the same
// order ID; only as a new order ID added by an extension
foreach ($subscriptions as $subscription) {
if ($subscription['customer_id'] == $result['customer_id'] && ($subscription['subscription_id'] != $result['subscription_id']) && ($subscription['order_id'] != $result['order_id']) && ($subscription['order_product_id'] != $result['order_product_id'])) {
$subscription_info = $this->model_account_subscription->getSubscription($subscription['subscription_id']);
if ($subscription_info) {
// $this->model_account_subscription->addTransaction($subscription['subscription_id'], $subscription['order_id'], $this->language->get('text_success'), $amount, $subscription_info['type'], $subscription_info['payment_method'], $subscription_info['payment_code']);
}
}
}
}
}
}
}
/*
// Failed if payment method does not have recurring payment method
$subscription_status_id = $this->config->get('config_subscription_failed_status_id');
$this->model_checkout_subscription->addHistory($result['subscription_id'], $subscription_status_id, $this->language->get('error_recurring'), true);
$subscription_status_id = $this->config->get('config_subscription_failed_status_id');
$this->model_checkout_subscription->addHistory($result['subscription_id'], $subscription_status_id, $this->language->get('error_extension'), true);
$this->model_checkout_subscription->addHistory($result['subscription_id'], $subscription_status_id, sprintf($this->language->get('error_payment'), ''), true);
// History
if ($result['subscription_status_id'] != $subscription_status_id) {
$this->model_checkout_subscription->addHistory($result['subscription_id'], $subscription_status_id, 'payment extension ' . $result['payment_code'] . ' could not be loaded', true);
}
// Success
if ($this->config->get('config_subscription_active_status_id') == $subscription_status_id) {
// Trial
if ($result['trial_status'] && (!$result['trial_duration'] || $result['trial_remaining'])) {
if ($result['trial_duration'] && $result['trial_remaining']) {
$this->model_account_subscription->editTrialRemaining($result['subscription_id'], $result['trial_remaining'] - 1);
}
} elseif (!$result['duration'] || $result['remaining']) {
// Subscription
if ($result['duration'] && $result['remaining']) {
$this->model_account_subscription->editRemaining($result['subscription_id'], $result['remaining'] - 1);
}
}
}
*/
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Opencart\Catalog\Controller\Error;
/**
* Class Exception
*
* @package Opencart\Catalog\Controller\Error
*/
class Exception extends \Opencart\System\Engine\Controller {
/**
* @param string $message
* @param string $code
* @param string $file
* @param string $line
*
* @return void
*/
public function index(string $message, string $code, string $file, string $line): void {
$this->load->language('error/exception');
$this->document->setTitle($this->language->get('heading_title'));
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('error/exception', 'user_token=' . $this->session->data['user_token'])
];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('error/exception', $data));
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Opencart\Catalog\Controller\Error;
/**
* Class Not Found
*
* @package Opencart\Catalog\Controller\Error
*/
class NotFound extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('error/not_found');
$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'))
];
if (isset($this->request->get['route'])) {
$url_data = $this->request->get;
$route = $url_data['route'];
unset($url_data['route']);
$url = '';
if ($url_data) {
$url .= '&' . urldecode(http_build_query($url_data, '', '&'));
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link($route, $url)
];
}
$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->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
$this->response->setOutput($this->load->view('error/not_found', $data));
}
}

View File

@@ -0,0 +1,349 @@
<?php
namespace Opencart\Catalog\Controller\Event;
/**
* Class Activity
*
* @package Opencart\Catalog\Controller\Event
*/
class Activity extends \Opencart\System\Engine\Controller {
// catalog/model/account/customer/addCustomer/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function addCustomer(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $output,
'name' => $args[0]['firstname'] . ' ' . $args[0]['lastname']
];
$this->model_account_activity->addActivity('register', $activity_data);
}
}
// catalog/model/account/customer/editCustomer/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function editCustomer(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $this->customer->getId(),
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
];
$this->model_account_activity->addActivity('edit', $activity_data);
}
}
// catalog/model/account/customer/editPassword/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function editPassword(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
if ($this->customer->isLogged()) {
$activity_data = [
'customer_id' => $this->customer->getId(),
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
];
$this->model_account_activity->addActivity('password', $activity_data);
} else {
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
if ($customer_info) {
$activity_data = [
'customer_id' => $customer_info['customer_id'],
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
];
$this->model_account_activity->addActivity('reset', $activity_data);
}
}
}
}
// catalog/model/account/customer/deleteLoginAttempts/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function login(string &$route, array &$args, mixed &$output): void {
if (isset($this->request->get['route']) && ($this->request->get['route'] == 'account/login' || $this->request->get['route'] == 'checkout/login.save') && $this->config->get('config_customer_activity')) {
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
if ($customer_info) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $customer_info['customer_id'],
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
];
$this->model_account_activity->addActivity('login', $activity_data);
}
}
}
// catalog/model/account/customer/editCode/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function forgotten(string &$route, array &$args, mixed &$output): void {
if (isset($this->request->get['route']) && $this->request->get['route'] == 'account/forgotten' && $this->config->get('config_customer_activity')) {
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
if ($customer_info) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $customer_info['customer_id'],
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
];
$this->model_account_activity->addActivity('forgotten', $activity_data);
}
}
}
// catalog/model/account/customer/addTransaction/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function addTransaction(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomer($args[0]);
if ($customer_info) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $customer_info['customer_id'],
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname'],
'order_id' => $args[3]
];
$this->model_account_activity->addActivity('transaction', $activity_data);
}
}
}
// catalog/model/account/affiliate/addAffiliate/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function addAffiliate(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $args[0],
'name' => $args[1]['firstname'] . ' ' . $args[1]['lastname']
];
$this->model_account_activity->addActivity('affiliate_add', $activity_data);
}
}
// catalog/model/account/affiliate/editAffiliate/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function editAffiliate(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $this->customer->getId(),
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
];
$this->model_account_activity->addActivity('affiliate_edit', $activity_data);
}
}
// catalog/model/account/address/addAddress/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function addAddress(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $this->customer->getId(),
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
];
$this->model_account_activity->addActivity('address_add', $activity_data);
}
}
// catalog/model/account/address/editAddress/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function editAddress(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $this->customer->getId(),
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
];
$this->model_account_activity->addActivity('address_edit', $activity_data);
}
}
// catalog/model/account/address/deleteAddress/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function deleteAddress(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity')) {
$this->load->model('account/activity');
$activity_data = [
'customer_id' => $this->customer->getId(),
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
];
$this->model_account_activity->addActivity('address_delete', $activity_data);
}
}
// catalog/model/account/returns/addReturn/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function addReturn(string &$route, array &$args, mixed &$output): void {
if ($this->config->get('config_customer_activity') && $output) {
$this->load->model('account/activity');
if ($this->customer->isLogged()) {
$activity_data = [
'customer_id' => $this->customer->getId(),
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(),
'return_id' => $output
];
$this->model_account_activity->addActivity('return_account', $activity_data);
} else {
$activity_data = [
'name' => $args[0]['firstname'] . ' ' . $args[0]['lastname'],
'return_id' => $output
];
$this->model_account_activity->addActivity('return_guest', $activity_data);
}
}
}
// catalog/model/checkout/order/addHistory/before
/**
* @param string $route
* @param array $args
*
* @return void
*/
public function addHistory(string &$route, array &$args): void {
if ($this->config->get('config_customer_activity')) {
// If the last order status id returns 0, and the new order status is not, then we record it as new order
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($args[0]);
if ($order_info && !$order_info['order_status_id'] && $args[1]) {
$this->load->model('account/activity');
if ($order_info['customer_id']) {
$activity_data = [
'customer_id' => $order_info['customer_id'],
'name' => $order_info['firstname'] . ' ' . $order_info['lastname'],
'order_id' => $args[0]
];
$this->model_account_activity->addActivity('order_account', $activity_data);
} else {
$activity_data = [
'name' => $order_info['firstname'] . ' ' . $order_info['lastname'],
'order_id' => $args[0]
];
$this->model_account_activity->addActivity('order_guest', $activity_data);
}
}
}
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Opencart\Catalog\Controller\Event;
/**
* Class Debug
*
* @package Opencart\Catalog\Controller\Event
*/
class Debug extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
*
* @return void
*/
public function index(string &$route, array &$args): void {
//echo $route;
}
/**
* @param string $route
* @param array $args
*
* @return void
*/
public function before(string &$route, array &$args): void {
// add the route you want to test
/*
if ($route == 'common/home') {
$this->session->data['debug'][$route] = microtime(true);
}
*/
}
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function after(string $route, array &$args, mixed &$output): void {
// add the route you want to test
/*
if ($route == 'common/home') {
if (isset($this->session->data['debug'][$route])) {
$log_data = [
'route' => $route,
'time' => microtime(true) - $this->session->data['debug'][$route]
];
$this->log->write($log_data);
}
}
*/
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Opencart\Catalog\Controller\Event;
/**
* Class Language
*
* @package Opencart\Catalog\Controller\Event
*/
class Language extends \Opencart\System\Engine\Controller {
// view/*/before
// Dump all the language vars into the template.
/**
* @param string $route
* @param array $args
*
* @return void
*/
public function index(string &$route, array &$args): void {
foreach ($this->language->all() as $key => $value) {
if (!isset($args[$key])) {
$args[$key] = $value;
}
}
}
// controller/*/before
// 1. Before controller load store all current loaded language data
/**
* @param string $route
* @param array $args
*
* @return void
*/
public function before(string &$route, array &$args): void {
$data = $this->language->all();
if ($data) {
$this->language->set('backup', json_encode($data));
}
}
// controller/*/after
// 2. After controller load restore old language data
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function after(string &$route, array &$args, mixed &$output): void {
$data = json_decode($this->language->get('backup'), true);
if (is_array($data)) {
$this->language->clear();
foreach ($data as $key => $value) {
$this->language->set($key, $value);
}
}
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace Opencart\Catalog\Controller\Event;
/**
* Class Statistics
*
* @package Opencart\Catalog\Controller\Event
*/
class Statistics extends \Opencart\System\Engine\Controller {
// catalog/model/catalog/review/addReview/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function addReview(string &$route, array &$args, mixed &$output): void {
$this->load->model('report/statistics');
$this->model_report_statistics->addValue('review', 1);
}
// catalog/model/account/returns/addReturn/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function addReturn(string &$route, array &$args, mixed &$output): void {
$this->load->model('report/statistics');
$this->model_report_statistics->addValue('returns', 1);
}
// catalog/model/checkout/order/addHistory/before
/**
* @param string $route
* @param array $args
*
* @return void
*/
public function addHistory(string &$route, array &$args): void {
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($args[0]);
if ($order_info) {
$this->load->model('report/statistics');
$old_status_id = $order_info['order_status_id'];
$new_status_id = $args[1];
$processing_status = (array)$this->config->get('config_processing_status');
$complete_status = (array)$this->config->get('config_complete_status');
$active_status = array_merge($processing_status, $complete_status);
// If order status in complete or processing add value to sale total
if (in_array($new_status_id, $active_status) && !in_array($old_status_id, $active_status)) {
$this->model_report_statistics->addValue('order_sale', $order_info['total']);
}
// If order status not in complete or processing remove value to sale total
if (!in_array($new_status_id, $active_status) && in_array($old_status_id, $active_status)) {
$this->model_report_statistics->removeValue('order_sale', $order_info['total']);
}
// Add to processing status if new status is in the array
if (in_array($new_status_id, $processing_status) && !in_array($old_status_id, $processing_status)) {
$this->model_report_statistics->addValue('order_processing', 1);
}
// Remove from processing status if new status is not array and old status is
if (!in_array($new_status_id, $processing_status) && in_array($old_status_id, $processing_status)) {
$this->model_report_statistics->removeValue('order_processing', 1);
}
// Add to complete status if new status is not array
if (in_array($new_status_id, $complete_status) && !in_array($old_status_id, $complete_status)) {
$this->model_report_statistics->addValue('order_complete', 1);
}
// Remove from complete status if new status is not array
if (!in_array($new_status_id, $complete_status) && in_array($old_status_id, $complete_status)) {
$this->model_report_statistics->removeValue('order_complete', 1);
}
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Opencart\Catalog\Controller\Event;
/**
* Class Theme
*
* @package Opencart\Catalog\Controller\Event
*/
class Theme extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param string $code
*
* @return void
*/
public function index(string &$route, array &$args, string &$code): void {
// If there is a theme override we should get it
$this->load->model('design/theme');
$theme_info = $this->model_design_theme->getTheme($route, $this->config->get('config_theme'));
if ($theme_info) {
$code = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Opencart\Catalog\Controller\Event;
/**
* Class Translation
*
* @package Opencart\Catalog\Controller\Event
*/
class Translation extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param string $prefix
*
* @return void
*/
public function index(string &$route, string &$prefix): void {
$this->load->model('design/translation');
$results = $this->model_design_translation->getTranslations($route);
foreach ($results as $result) {
if (!$prefix) {
$this->language->set($result['key'], html_entity_decode($result['value'], ENT_QUOTES, 'UTF-8'));
} else {
$this->language->set($prefix . '_' . $result['key'], html_entity_decode($result['value'], ENT_QUOTES, 'UTF-8'));
}
}
}
}

View File

@@ -0,0 +1,206 @@
<?php
namespace Opencart\Catalog\Controller\Information;
/**
* Class Contact
*
* @package Opencart\Catalog\Controller\Information
*/
class Contact extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('information/contact');
$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('information/contact', 'language=' . $this->config->get('config_language'))
];
$data['send'] = $this->url->link('information/contact.send', 'language=' . $this->config->get('config_language'));
$this->load->model('tool/image');
if ($this->config->get('config_image')) {
$data['image'] = $this->model_tool_image->resize(html_entity_decode($this->config->get('config_image'), ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_location_width'), $this->config->get('config_image_location_height'));
} else {
$data['image'] = false;
}
$data['store'] = $this->config->get('config_name');
$data['address'] = nl2br($this->config->get('config_address'));
$data['geocode'] = $this->config->get('config_geocode');
$data['geocode_hl'] = $this->config->get('config_language');
$data['telephone'] = $this->config->get('config_telephone');
$data['open'] = nl2br($this->config->get('config_open'));
$data['comment'] = nl2br($this->config->get('config_comment'));
$data['locations'] = [];
$this->load->model('localisation/location');
foreach ((array)$this->config->get('config_location') as $location_id) {
$location_info = $this->model_localisation_location->getLocation((int)$location_id);
if ($location_info) {
if (is_file(DIR_IMAGE . html_entity_decode($location_info['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($location_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_location_width'), $this->config->get('config_image_location_height'));
} else {
$image = '';
}
$data['locations'][] = [
'location_id' => $location_info['location_id'],
'name' => $location_info['name'],
'address' => nl2br($location_info['address']),
'geocode' => $location_info['geocode'],
'telephone' => $location_info['telephone'],
'image' => $image,
'open' => nl2br($location_info['open']),
'comment' => $location_info['comment']
];
}
}
$data['name'] = $this->customer->getFirstName();
$data['email'] = $this->customer->getEmail();
// 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('contact', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code']);
} else {
$data['captcha'] = '';
}
$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('information/contact', $data));
}
/**
* @return void
* @throws \Exception
*/
public function send(): void {
$this->load->language('information/contact');
$json = [];
$keys = [
'name',
'email',
'enquiry'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 32)) {
$json['error']['name'] = $this->language->get('error_name');
}
if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
$json['error']['email'] = $this->language->get('error_email');
}
if ((oc_strlen($this->request->post['enquiry']) < 10) || (oc_strlen($this->request->post['enquiry']) > 3000)) {
$json['error']['enquiry'] = $this->language->get('error_enquiry');
}
// 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('contact', (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) {
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($this->config->get('config_email'));
// Less spam and fix bug when using SMTP like sendgrid.
$mail->setFrom($this->config->get('config_email'));
$mail->setReplyTo($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->request->post['enquiry']);
$mail->send();
}
$json['redirect'] = $this->url->link('information/contact.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 success(): void {
$this->load->language('information/contact');
$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('information/contact', 'language=' . $this->config->get('config_language'))
];
$data['text_message'] = $this->language->get('text_message');
$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));
}
}

View File

@@ -0,0 +1,206 @@
<?php
namespace Opencart\Catalog\Controller\Information;
/**
* Class Gdpr
*
* @package Opencart\Catalog\Controller\Information
*/
class Gdpr extends \Opencart\System\Engine\Controller {
/**
* @return object|\Opencart\System\Engine\Action|null
*/
public function index(): object|null {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_gdpr_id'));
if ($information_info) {
$this->load->language('information/gdpr');
$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('information/gdpr', 'language=' . $this->config->get('config_language'))
];
$data['action'] = $this->url->link('information/gdpr.action', 'language=' . $this->config->get('config_language'));
$data['title'] = $information_info['title'];
$data['gdpr'] = $this->url->link('information/information', 'language=' . $this->config->get('config_language') . '&information_id=' . $information_info['information_id']);
$data['email'] = $this->customer->getEmail();
$data['store'] = $this->config->get('config_name');
$data['limit'] = $this->config->get('config_gdpr_limit');
$data['cancel'] = $this->url->link('account/account', '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('information/gdpr', $data));
return null;
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
}
/*
* Action Statuses
*
* EXPORT
*
* unverified = 0
* pending = 1
* complete = 3
*
* REMOVE
*
* unverified = 0
* pending = 1
* processing = 2
* delete = 3
*
* DENY
*
* unverified = 0
* pending = 1
* processing = 2
* denied = -1
*/
/**
* @return void
*/
public function action(): void {
$this->load->language('information/gdpr');
$json = [];
if (isset($this->request->post['email'])) {
$email = $this->request->post['email'];
} else {
$email = '';
}
if (isset($this->request->post['action'])) {
$action = $this->request->post['action'];
} else {
$action = '';
}
// Validate E-Mail
if ((oc_strlen($email) > 96) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$json['error']['email'] = $this->language->get('error_email');
}
// Validate Action
$allowed = [
'export',
'remove'
];
if (!in_array($action, $allowed)) {
$json['error']['action'] = $this->language->get('error_action');
}
if (!$json) {
// Added additional check so people are not spamming requests
$status = true;
$this->load->model('account/gdpr');
$results = $this->model_account_gdpr->getGdprsByEmail($email);
foreach ($results as $result) {
if ($result['action'] == $action) {
$status = false;
break;
}
}
if ($status) {
$this->model_account_gdpr->addGdpr(oc_token(32), $email, $action);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return object|\Opencart\System\Engine\Action|null
*/
public function success(): object|null {
if (isset($this->request->get['code'])) {
$code = (string)$this->request->get['code'];
} else {
$code = '';
}
$this->load->model('account/gdpr');
$gdpr_info = $this->model_account_gdpr->getGdprByCode($code);
if ($gdpr_info) {
$this->load->language('information/gdpr_success');
$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_account'),
'href' => $this->url->link('information/gdpr', 'language=' . $this->config->get('config_language'))
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/gdpr.success', 'language=' . $this->config->get('config_language'))
];
if ($gdpr_info['status'] == 0) {
$this->model_account_gdpr->editStatus($gdpr_info['gdpr_id'], 1);
}
if ($gdpr_info['action'] == 'export') {
$data['text_message'] = $this->language->get('text_export');
} else {
$data['text_message'] = sprintf($this->language->get('text_remove'), $this->config->get('config_gdpr_limit'));
}
$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));
return null;
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Opencart\Catalog\Controller\Information;
/**
* Class Information
*
* @package Opencart\Catalog\Controller\Information
*/
class Information extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): object|null {
$this->load->language('information/information');
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
} else {
$information_id = 0;
}
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$this->document->setTitle($information_info['meta_title']);
$this->document->setDescription($information_info['meta_description']);
$this->document->setKeywords($information_info['meta_keyword']);
$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' => $information_info['title'],
'href' => $this->url->link('information/information', 'language=' . $this->config->get('config_language') . '&information_id=' . $information_id)
];
$data['heading_title'] = $information_info['title'];
$data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
$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('information/information', $data));
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
return null;
}
/**
* @return void
*/
public function info(): void {
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
} else {
$information_id = 0;
}
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$data['title'] = $information_info['title'];
$data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
$this->response->addHeader('X-Robots-Tag: noindex');
$this->response->setOutput($this->load->view('information/information_info', $data));
}
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace Opencart\Catalog\Controller\Information;
/**
* Class Sitemap
*
* @package Opencart\Catalog\Controller\Information
*/
class Sitemap extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('information/sitemap');
$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('information/sitemap', 'language=' . $this->config->get('config_language'))
];
$this->load->model('catalog/category');
$data['categories'] = [];
$categories_1 = $this->model_catalog_category->getCategories(0);
foreach ($categories_1 as $category_1) {
$level_2_data = [];
$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);
foreach ($categories_2 as $category_2) {
$level_3_data = [];
$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);
foreach ($categories_3 as $category_3) {
$level_3_data[] = [
'name' => $category_3['name'],
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category_1['category_id'] . '_' . $category_2['category_id'] . '_' . $category_3['category_id'])
];
}
$level_2_data[] = [
'name' => $category_2['name'],
'children' => $level_3_data,
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category_1['category_id'] . '_' . $category_2['category_id'])
];
}
$data['categories'][] = [
'name' => $category_1['name'],
'children' => $level_2_data,
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category_1['category_id'])
];
}
$data['special'] = $this->url->link('product/special', 'language=' . $this->config->get('config_language'));
$data['account'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language'));
$data['edit'] = $this->url->link('account/edit', 'language=' . $this->config->get('config_language'));
$data['password'] = $this->url->link('account/password', 'language=' . $this->config->get('config_language'));
$data['address'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language'));
$data['history'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language'));
$data['download'] = $this->url->link('account/download', 'language=' . $this->config->get('config_language'));
$data['cart'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'));
$data['checkout'] = $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'));
$data['search'] = $this->url->link('product/search', 'language=' . $this->config->get('config_language'));
$data['contact'] = $this->url->link('information/contact', 'language=' . $this->config->get('config_language'));
$this->load->model('catalog/information');
$data['informations'] = [];
foreach ($this->model_catalog_information->getInformations() as $result) {
$data['informations'][] = [
'title' => $result['title'],
'href' => $this->url->link('information/information', 'language=' . $this->config->get('config_language') . '&information_id=' . $result['information_id'])
];
}
$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('information/sitemap', $data));
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Opencart\Catalog\Controller\Localisation;
/**
* Class Country
*
* @package Opencart\Catalog\Controller\Localisation
*/
class Country extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$json = [];
if (isset($this->request->get['country_id'])) {
$country_id = (int)$this->request->get['country_id'];
} else {
$country_id = 0;
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($country_id);
if ($country_info) {
$this->load->model('localisation/zone');
$json = [
'country_id' => $country_info['country_id'],
'name' => $country_info['name'],
'iso_code_2' => $country_info['iso_code_2'],
'iso_code_3' => $country_info['iso_code_3'],
'address_format' => $country_info['address_format'],
'postcode_required' => $country_info['postcode_required'],
'zone' => $this->model_localisation_zone->getZonesByCountryId($country_id),
'status' => $country_info['status']
];
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Affiliate
*
* @package Opencart\Catalog\Controller\Mail
*/
class Affiliate extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
$this->load->language('mail/affiliate');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$subject = sprintf($this->language->get('text_subject'), $store_name);
$data['text_welcome'] = sprintf($this->language->get('text_welcome'), $store_name);
$this->load->model('account/customer_group');
if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getGroupId();
} else {
$customer_group_id = $args[1]['customer_group_id'];
}
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
if ($customer_group_info) {
$data['approval'] = ($this->config->get('config_affiliate_approval') || $customer_group_info['approval']);
} else {
$data['approval'] = '';
}
$data['login'] = $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language'), true);
$data['store'] = $store_name;
$data['store_url'] = $this->config->get('config_url');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
if ($this->customer->isLogged()) {
$mail->setTo($this->customer->getEmail());
} else {
$mail->setTo($args[1]['email']);
}
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/affiliate', $data));
$mail->send();
}
}
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function alert(string &$route, array &$args, mixed &$output): void {
// Send to main admin email if new affiliate email is enabled
if (in_array('affiliate', (array)$this->config->get('config_mail_alert'))) {
$this->load->language('mail/affiliate');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$subject = $this->language->get('text_new_affiliate');
if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getGroupId();
$data['firstname'] = $this->customer->getFirstName();
$data['lastname'] = $this->customer->getLastName();
$data['email'] = $this->customer->getEmail();
$data['telephone'] = $this->customer->getTelephone();
} else {
$customer_group_id = $args[1]['customer_group_id'];
$data['firstname'] = $args[1]['firstname'];
$data['lastname'] = $args[1]['lastname'];
$data['email'] = $args[1]['email'];
$data['telephone'] = $args[1]['telephone'];
}
$data['website'] = html_entity_decode($args[1]['website'], ENT_QUOTES, 'UTF-8');
$data['company'] = $args[1]['company'];
$this->load->model('account/customer_group');
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
if ($customer_group_info) {
$data['customer_group'] = $customer_group_info['name'];
} else {
$data['customer_group'] = '';
}
$data['store'] = $store_name;
$data['store_url'] = $this->config->get('config_url');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/affiliate_alert', $data));
$mail->send();
// Send to additional alert emails if new affiliate email is enabled
$emails = explode(',', $this->config->get('config_mail_alert_email'));
foreach ($emails as $email) {
if (oc_strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->setTo(trim($email));
$mail->send();
}
}
}
}
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Forgotten
*
* @package Opencart\Catalog\Controller\Mail
*/
class Forgotten extends \Opencart\System\Engine\Controller {
// catalog/model/account/customer/editCode/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
if ($args[0] && $args[1]) {
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
if ($customer_info) {
$this->load->language('mail/forgotten');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$subject = sprintf($this->language->get('text_subject'), $store_name);
$data['text_greeting'] = sprintf($this->language->get('text_greeting'), $store_name);
$data['reset'] = $this->url->link('account/forgotten.reset', 'language=' . $this->config->get('config_language') . '&email=' . urlencode($args[0]) . '&code=' . $args[1], true);
$data['ip'] = $this->request->server['REMOTE_ADDR'];
$data['store'] = $store_name;
$data['store_url'] = $this->config->get('config_url');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($args[0]);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/forgotten', $data));
$mail->send();
}
}
}
}
}

View File

@@ -0,0 +1,192 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Gdpr
*
* @package Opencart\Catalog\Controller\Mail
*/
class Gdpr extends \Opencart\System\Engine\Controller {
// catalog/model/account/gdpr/addGdpr
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
// $args[0] $code
// $args[1] $email
// $args[2] $action
if (isset($args[0])) {
$code = $args[0];
} else {
$code = '';
}
if (isset($args[1])) {
$email = $args[1];
} else {
$email = '';
}
if (isset($args[2])) {
$action = $args[2];
} else {
$action = '';
}
$this->load->language('mail/gdpr');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
if ($this->config->get('config_logo')) {
$data['logo'] = $this->config->get('config_url') . 'image/' . html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
} else {
$data['logo'] = '';
}
$data['text_request'] = $this->language->get('text_' . $action);
$data['button_confirm'] = $this->language->get('button_' . $action);
$data['confirm'] = $this->url->link('information/gdpr.success', 'language=' . $this->config->get('config_language') . '&code=' . $code, true);
$data['ip'] = $this->request->server['REMOTE_ADDR'];
$data['store_name'] = $store_name;
$data['store_url'] = $this->config->get('config_url');
if ($this->config->get('config_mail_engine') && $email) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($email);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject(sprintf($this->language->get('text_subject'), $store_name));
$mail->setHtml($this->load->view('mail/gdpr', $data));
$mail->send();
}
}
// catalog/model/account/gdpr/editStatus/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function remove(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$gdpr_id = $args[0];
} else {
$gdpr_id = 0;
}
if (isset($args[1])) {
$status = $args[1];
} else {
$status = 0;
}
$this->load->model('account/gdpr');
$gdpr_info = $this->model_account_gdpr->getGdpr($gdpr_id);
if ($gdpr_info && $gdpr_info['action'] == 'remove' && $status == 3) {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_SERVER;
}
// Send the email in the correct language
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so that it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/gdpr_delete', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomerByEmail($gdpr_info['email']);
if ($customer_info) {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
} else {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
}
$data['store_name'] = $store_name;
$data['store_url'] = $store_url;
$data['contact'] = $store_url . 'index.php?route=information/contact';
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($gdpr_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/gdpr_delete', $data));
$mail->send();
}
}
}
}

View File

@@ -0,0 +1,638 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Order
*
* @package Opencart\Catalog\Controller\Mail
*/
class Order extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
*
* @return void
*/
public function index(string &$route, array &$args): void {
if (isset($args[0])) {
$order_id = $args[0];
} else {
$order_id = 0;
}
if (isset($args[1])) {
$order_status_id = $args[1];
} else {
$order_status_id = 0;
}
if (isset($args[2])) {
$comment = $args[2];
} else {
$comment = '';
}
if (isset($args[3])) {
$notify = $args[3];
} else {
$notify = '';
}
// We need to grab the old order status ID
$order_info = $this->model_checkout_order->getOrder($order_id);
if ($order_info) {
// If the order status returns 0, then it becomes greater than 0. Therefore, we send the default html email
if (!$order_info['order_status_id'] && $order_status_id) {
$this->add($order_info, $order_status_id, $comment, $notify);
}
// If the order status does not return 0, we send the update as a text email
if ($order_info['order_status_id'] && $order_status_id && $notify) {
$this->edit($order_info, $order_status_id, $comment, $notify);
}
}
}
/**
* @param array $order_info
* @param int $order_status_id
* @param string $comment
* @param bool $notify
*
* @return void
* @throws \Exception
*/
public function add(array $order_info, int $order_status_id, string $comment, bool $notify): void {
// Check for any downloadable products
$download_status = false;
$order_products = $this->model_checkout_order->getProducts($order_info['order_id']);
foreach ($order_products as $order_product) {
// Check if there are any linked downloads
$product_download_query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "product_to_download` WHERE `product_id` = '" . (int)$order_product['product_id'] . "'");
if ($product_download_query->row['total']) {
$download_status = true;
}
}
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
if (!defined('HTTP_CATALOG')) {
$store_url = HTTP_SERVER;
} else {
$store_url = HTTP_CATALOG;
}
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($order_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/order_add', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name, $order_info['order_id']);
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$data['title'] = sprintf($this->language->get('mail_text_subject'), $store_name, $order_info['order_id']);
$data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $order_info['store_name']);
$data['store'] = $store_name;
$data['store_url'] = $order_info['store_url'];
$data['customer_id'] = $order_info['customer_id'];
$data['link'] = $order_info['store_url'] . 'index.php?route=account/order.info&order_id=' . $order_info['order_id'];
if ($download_status) {
$data['download'] = $order_info['store_url'] . 'index.php?route=account/download';
} else {
$data['download'] = '';
}
$data['order_id'] = $order_info['order_id'];
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
$data['payment_method'] = $order_info['payment_method']['name'];
$data['shipping_method'] = $order_info['shipping_method']['name'];
$data['email'] = $order_info['email'];
$data['telephone'] = $order_info['telephone'];
$data['ip'] = $order_info['ip'];
$order_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$order_info['language_id'] . "'");
if ($order_status_query->num_rows) {
$data['order_status'] = $order_status_query->row['name'];
} else {
$data['order_status'] = '';
}
if ($comment) {
$data['comment'] = nl2br($comment);
} else {
$data['comment'] = '';
}
// Payment Address
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = [
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
];
$replace = [
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
];
$data['payment_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
// Shipping Address
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = [
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
];
$replace = [
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
];
$data['shipping_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
$this->load->model('tool/upload');
// Products
$data['products'] = [];
foreach ($order_products as $order_product) {
$option_data = [];
$order_options = $this->model_checkout_order->getOptions($order_info['order_id'], $order_product['order_product_id']);
foreach ($order_options as $order_option) {
if ($order_option['type'] != 'file') {
$value = $order_option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($order_option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = [
'name' => $order_option['name'],
'value' => (oc_strlen($value) > 20 ? oc_substr($value, 0, 20) . '..' : $value)
];
}
$description = '';
$this->load->model('checkout/order');
$subscription_info = $this->model_checkout_order->getSubscription($order_info['order_id'], $order_product['order_product_id']);
if ($subscription_info) {
if ($subscription_info['trial_status']) {
$trial_price = $this->currency->format($subscription_info['trial_price'] + ($this->config->get('config_tax') ? $subscription_info['trial_tax'] : 0), $order_info['currency_code'], $order_info['currency_value']);
$trial_cycle = $subscription_info['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
$trial_duration = $subscription_info['trial_duration'];
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
}
$price = $this->currency->format($subscription_info['price'] + ($this->config->get('config_tax') ? $subscription_info['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']);
$cycle = $subscription_info['cycle'];
$frequency = $this->language->get('text_' . $subscription_info['frequency']);
$duration = $subscription_info['duration'];
if ($duration) {
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
}
$data['products'][] = [
'name' => $order_product['name'],
'model' => $order_product['model'],
'option' => $option_data,
'subscription' => $description,
'quantity' => $order_product['quantity'],
'price' => $this->currency->format($order_product['price'] + ($this->config->get('config_tax') ? $order_product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($order_product['total'] + ($this->config->get('config_tax') ? ($order_product['tax'] * $order_product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
'reward' => $order_product['reward']
];
}
// Vouchers
$data['vouchers'] = [];
$order_vouchers = $this->model_checkout_order->getVouchers($order_info['order_id']);
foreach ($order_vouchers as $order_voucher) {
$data['vouchers'][] = [
'description' => $order_voucher['description'],
'amount' => $this->currency->format($order_voucher['amount'], $order_info['currency_code'], $order_info['currency_value']),
];
}
// Order Totals
$data['totals'] = [];
$order_totals = $this->model_checkout_order->getTotals($order_info['order_id']);
foreach ($order_totals as $order_total) {
$data['totals'][] = [
'title' => $order_total['title'],
'text' => $this->currency->format($order_total['value'], $order_info['currency_code'], $order_info['currency_value']),
];
}
$this->load->model('setting/setting');
$from = $this->model_setting_setting->getValue('config_email', $order_info['store_id']);
if (!$from) {
$from = $this->config->get('config_email');
}
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($order_info['email']);
$mail->setFrom($from);
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/order_invoice', $data));
$mail->send();
}
}
/**
* @param array $order_info
* @param int $order_status_id
* @param string $comment
* @param bool $notify
*
* @return void
* @throws \Exception
*/
public function edit(array $order_info, int $order_status_id, string $comment, bool $notify): void {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
if (!defined('HTTP_CATALOG')) {
$store_url = HTTP_SERVER;
} else {
$store_url = HTTP_CATALOG;
}
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($order_info['store_id']);
if ($store_info) {
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/order_edit', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name, $order_info['order_id']);
$data['order_id'] = $order_info['order_id'];
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
$order_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$order_info['language_id'] . "'");
if ($order_status_query->num_rows) {
$data['order_status'] = $order_status_query->row['name'];
} else {
$data['order_status'] = '';
}
if ($order_info['customer_id']) {
$data['link'] = $order_info['store_url'] . 'index.php?route=account/order.info&order_id=' . $order_info['order_id'];
} else {
$data['link'] = '';
}
$data['comment'] = strip_tags($comment);
$data['store'] = $store_name;
$data['store_url'] = $store_url;
$this->load->model('setting/setting');
$from = $this->model_setting_setting->getValue('config_email', $order_info['store_id']);
if (!$from) {
$from = $this->config->get('config_email');
}
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($order_info['email']);
$mail->setFrom($from);
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/order_history', $data));
$mail->send();
}
}
// catalog/model/checkout/order/addHistory/before
/**
* @param string $route
* @param array $args
*
* @return void
* @throws \Exception
*/
public function alert(string &$route, array &$args): void {
if (isset($args[0])) {
$order_id = $args[0];
} else {
$order_id = 0;
}
if (isset($args[1])) {
$order_status_id = $args[1];
} else {
$order_status_id = 0;
}
if (isset($args[2])) {
$comment = $args[2];
} else {
$comment = '';
}
if (isset($args[3])) {
$notify = $args[3];
} else {
$notify = '';
}
$order_info = $this->model_checkout_order->getOrder($order_id);
if ($order_info && !$order_info['order_status_id'] && $order_status_id && in_array('order', (array)$this->config->get('config_mail_alert'))) {
$this->load->language('mail/order_alert');
$subject = html_entity_decode(sprintf($this->language->get('text_subject'), $this->config->get('config_name'), $order_info['order_id']), ENT_QUOTES, 'UTF-8');
$data['order_id'] = $order_info['order_id'];
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
$order_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
if ($order_status_query->num_rows) {
$data['order_status'] = $order_status_query->row['name'];
} else {
$data['order_status'] = '';
}
$this->load->model('tool/upload');
$data['products'] = [];
$order_products = $this->model_checkout_order->getProducts($order_id);
foreach ($order_products as $order_product) {
$option_data = [];
$order_options = $this->model_checkout_order->getOptions($order_info['order_id'], $order_product['order_product_id']);
foreach ($order_options as $order_option) {
if ($order_option['type'] != 'file') {
$value = $order_option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($order_option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = [
'name' => $order_option['name'],
'value' => (oc_strlen($value) > 20 ? oc_substr($value, 0, 20) . '..' : $value)
];
}
$description = '';
$this->load->model('checkout/subscription');
$subscription_info = $this->model_checkout_order->getSubscription($order_info['order_id'], $order_product['order_product_id']);
if ($subscription_info) {
if ($subscription_info['trial_status']) {
$trial_price = $this->currency->format($subscription_info['trial_price'] + ($this->config->get('config_tax') ? $subscription_info['trial_tax'] : 0), $this->session->data['currency']);
$trial_cycle = $subscription_info['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
$trial_duration = $subscription_info['trial_duration'];
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
}
$price = $this->currency->format($subscription_info['price'] + ($this->config->get('config_tax') ? $subscription_info['tax'] : 0), $this->session->data['currency']);
$cycle = $subscription_info['cycle'];
$frequency = $this->language->get('text_' . $subscription_info['frequency']);
$duration = $subscription_info['duration'];
if ($duration) {
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
}
$data['products'][] = [
'name' => $order_product['name'],
'model' => $order_product['model'],
'quantity' => $order_product['quantity'],
'option' => $option_data,
'subscription' => $description,
'total' => html_entity_decode($this->currency->format($order_product['total'] + ($this->config->get('config_tax') ? $order_product['tax'] * $order_product['quantity'] : 0), $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8')
];
}
$data['vouchers'] = [];
$order_vouchers = $this->model_checkout_order->getVouchers($order_id);
foreach ($order_vouchers as $order_voucher) {
$data['vouchers'][] = [
'description' => $order_voucher['description'],
'amount' => html_entity_decode($this->currency->format($order_voucher['amount'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8')
];
}
$data['totals'] = [];
$order_totals = $this->model_checkout_order->getTotals($order_id);
foreach ($order_totals as $order_total) {
$data['totals'][] = [
'title' => $order_total['title'],
'value' => html_entity_decode($this->currency->format($order_total['value'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8')
];
}
$data['comment'] = nl2br($order_info['comment']);
$data['store'] = html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8');
$data['store_url'] = $order_info['store_url'];
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/order_alert', $data));
$mail->send();
// Send to additional alert emails
$emails = explode(',', $this->config->get('config_mail_alert_email'));
foreach ($emails as $email) {
if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->setTo(trim($email));
$mail->send();
}
}
}
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Register
*
* @package Opencart\Catalog\Controller\Mail
*/
class Register extends \Opencart\System\Engine\Controller {
// catalog/model/account/customer/addCustomer/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
$this->load->language('mail/register');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$subject = sprintf($this->language->get('text_subject'), $store_name);
$data['text_welcome'] = sprintf($this->language->get('text_welcome'), $store_name);
$this->load->model('account/customer_group');
if (isset($args[0]['customer_group_id'])) {
$customer_group_id = (int)$args[0]['customer_group_id'];
} else {
$customer_group_id = (int)$this->config->get('config_customer_group_id');
}
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
if ($customer_group_info) {
$data['approval'] = $customer_group_info['approval'];
} else {
$data['approval'] = '';
}
$data['login'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
$data['store'] = $store_name;
$data['store_url'] = $this->config->get('config_url');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($args[0]['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/register', $data));
$mail->send();
}
}
// catalog/model/account/customer/addCustomer/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function alert(string &$route, array &$args, mixed &$output): void {
// Send to main admin email if new account email is enabled
if (in_array('account', (array)$this->config->get('config_mail_alert'))) {
$this->load->language('mail/register');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$subject = $this->language->get('text_new_customer');
$data['firstname'] = $args[0]['firstname'];
$data['lastname'] = $args[0]['lastname'];
$data['login'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
$this->load->model('account/customer_group');
if (isset($args[0]['customer_group_id'])) {
$customer_group_id = (int)$args[0]['customer_group_id'];
} else {
$customer_group_id = (int)$this->config->get('config_customer_group_id');
}
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
if ($customer_group_info) {
$data['customer_group'] = $customer_group_info['name'];
} else {
$data['customer_group'] = '';
}
$data['email'] = $args[0]['email'];
$data['telephone'] = $args[0]['telephone'];
$data['store'] = $store_name;
$data['store_url'] = $this->config->get('config_url');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/register_alert', $data));
$mail->send();
// Send to additional alert emails if new account email is enabled
$emails = explode(',', (string)$this->config->get('config_mail_alert_email'));
foreach ($emails as $email) {
if (oc_strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->setTo(trim($email));
$mail->send();
}
}
}
}
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Review
*
* @package Opencart\Catalog\Controller\Mail
*/
class Review extends \Opencart\System\Engine\Controller {
// catalog/model/catalog/review/addReview/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
if (in_array('review', (array)$this->config->get('config_mail_alert'))) {
$this->load->language('mail/review');
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct((int)$args[0]);
if ($product_info) {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$subject = sprintf($this->language->get('text_subject'), $store_name);
$data['product'] = html_entity_decode($product_info['name'], ENT_QUOTES, 'UTF-8');
$data['reviewer'] = html_entity_decode($args[1]['name'], ENT_QUOTES, 'UTF-8');
$data['rating'] = (int)$args[1]['rating'];
$data['text'] = nl2br($args[1]['text']);
$data['store'] = $store_name;
$data['store_url'] = $this->config->get('config_url');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/review', $data));
$mail->send();
// Send to additional alert emails
$emails = explode(',', (string)$this->config->get('config_mail_alert_email'));
foreach ($emails as $email) {
if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->setTo(trim($email));
$mail->send();
}
}
}
}
}
}
}

View File

@@ -0,0 +1,376 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Subscription
*
* @package Opencart\Catalog\Controller\Mail
*/
class Subscription extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param $output
*
* @return void
*/
public function index(string &$route, array &$args, &$output): void {
if (isset($args[0])) {
$subscription_id = $args[0];
} else {
$subscription_id = 0;
}
if (isset($args[1]['subscription'])) {
$subscription = $args[1]['subscription'];
} else {
$subscription = [];
}
if (isset($args[2])) {
$comment = $args[2];
} else {
$comment = '';
}
if (isset($args[3])) {
$notify = $args[3];
} else {
$notify = '';
}
/*
$subscription['order_product_id']
$subscription['customer_id']
$subscription['order_id']
$subscription['subscription_plan_id']
$subscription['customer_payment_id'],
$subscription['name']
$subscription['description']
$subscription['trial_price']
$subscription['trial_frequency']
$subscription['trial_cycle']
$subscription['trial_duration']
$subscription['trial_remaining']
$subscription['trial_status']
$subscription['price']
$subscription['frequency']
$subscription['cycle']
$subscription['duration']
$subscription['remaining']
$subscription['date_next']
$subscription['status']
if ($subscription['trial_duration'] && $subscription['trial_remaining']) {
$date_next = date('Y-m-d', strtotime('+' . $subscription['trial_cycle'] . ' ' . $subscription['trial_frequency']));
} elseif ($subscription['duration'] && $subscription['remaining']) {
$date_next = date('Y-m-d', strtotime('+' . $subscription['cycle'] . ' ' . $subscription['frequency']));
}
// Subscription
$this->load->model('account/subscription');
$filter_data = [
'filter_subscription_id' => $subscription_id,
'filter_date_next' => $date_next,
'filter_subscription_status_id' => $this->config->get('config_subscription_active_status_id'),
'start' => 0,
'limit' => 1
];
$subscriptions = $this->model_account_subscription->getSubscriptions($filter_data);
if ($subscriptions) {
$this->load->language('mail/subscription');
foreach ($subscriptions as $value) {
// Only match the latest order ID of the same customer ID
// since new subscriptions cannot be re-added with the same
// order ID; only as a new order ID added by an extension
if ($value['customer_id'] == $subscription['customer_id'] && $value['order_id'] == $subscription['order_id']) {
// Payment Methods
$this->load->model('account/payment_method');
$payment_method = $this->model_account_payment_method->getPaymentMethod($value['customer_id'], $value['customer_payment_id']);
if ($payment_method) {
// Subscription
$this->load->model('checkout/subscription');
$subscription_order_product = $this->model_checkout_subscription->getSubscriptionByOrderProductId($value['order_product_id']);
if ($subscription_order_product) {
// Orders
$this->load->model('account/order');
// Order Products
$order_product = $this->model_account_order->getProduct($value['order_id'], $value['order_product_id']);
if ($order_product && $order_product['order_product_id'] == $subscription['order_product_id']) {
$products = $this->cart->getProducts();
$description = '';
foreach ($products as $product) {
if ($product['product_id'] == $order_product['product_id']) {
if ($product['subscription']['trial_status']) {
$trial_price = $this->currency->format($this->tax->calculate($value['trial_price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->config->get('config_currency'));
$trial_cycle = $value['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $value['trial_frequency']);
$trial_duration = $value['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($value['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->config->get('config_currency'));
$cycle = $value['cycle'];
$frequency = $this->language->get('text_' . $value['frequency']);
$duration = $value['duration'];
if ($duration) {
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
}
}
// Orders
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($value['order_id']);
if ($order_info) {
// Stores
$this->load->model('setting/store');
// Settings
$this->load->model('setting/setting');
$store_info = $this->model_setting_store->getStore($order_info['store_id']);
if ($store_info) {
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_SERVER;
}
// Subscription Status
$subscription_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$value['subscription_status_id'] . "' AND `language_id` = '" . (int)$order_info['language_id'] . "'");
if ($subscription_status_query->num_rows) {
$data['order_status'] = $subscription_status_query->row['name'];
} else {
$data['order_status'] = '';
}
// Languages
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
// We need to compare both language IDs as they both need to match.
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/order_add', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name, $order_info['order_id']);
// Image files
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$data['title'] = sprintf($this->language->get('mail_text_subject'), $store_name, $order_info['order_id']);
$data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $order_info['store_name']);
$data['store'] = $store_name;
$data['store_url'] = $order_info['store_url'];
$data['customer_id'] = $order_info['customer_id'];
$data['link'] = $order_info['store_url'] . 'index.php?route=account/subscription.info&subscription_id=' . $subscription_id;
$data['order_id'] = $order_info['order_id'];
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($value['date_added']));
$data['payment_method'] = $order_info['payment_method'];
$data['email'] = $order_info['email'];
$data['telephone'] = $order_info['telephone'];
$data['ip'] = $order_info['ip'];
// Order Totals
$data['totals'] = [];
$order_totals = $this->model_checkout_order->getTotals($subscription['order_id']);
foreach ($order_totals as $order_total) {
$data['totals'][] = [
'title' => $order_total['title'],
'text' => $this->currency->format($order_total['value'], $order_info['currency_code'], $order_info['currency_value']),
];
}
// Subscription
if ($comment && $notify) {
$data['comment'] = nl2br($comment);
} else {
$data['comment'] = '';
}
$data['description'] = $value['description'];
// Products
$data['name'] = $order_product['name'];
$data['quantity'] = $order_product['quantity'];
$data['price'] = $this->currency->format($order_product['price'], $order_info['currency_code'], $order_info['currency_value']);
$data['total'] = $this->currency->format($order_product['total'], $order_info['currency_code'], $order_info['currency_value']);
$data['order'] = $this->url->link('account/order.info', 'order_id=' . $value['order_id']);
$data['product'] = $this->url->link('product/product', 'product_id=' . $value['product_id']);
// Settings
$from = $this->model_setting_setting->getValue('config_email', $order_info['store_id']);
if (!$from) {
$from = $this->config->get('config_email');
}
if ($this->config->get('payment_' . $payment_info['code'] . '_status')) {
$this->load->model('extension/payment/' . $payment_info['code']);
// Promotion
if (isset($this->{'model_extension_payment_' . $payment_info['code']}->promotion)) {
$subscription_status_id = $this->{'model_extension_payment_' . $payment_info['code']}->promotion($value['subscription_id']);
if ($store_info) {
$config_subscription_active_status_id = $this->model_setting_setting->getValue('config_subscription_active_status_id', $store_info['store_id']);
} else {
$config_subscription_active_status_id = $this->config->get('config_subscription_active_status_id');
}
if ($config_subscription_active_status_id == $subscription_status_id) {
$subscription_info = $this->model_account_subscription->getSubscription($value['subscription_id']);
// Validate the latest subscription values with the ones edited
// by promotional extensions
if ($subscription_info && $subscription_info['status'] && $subscription_info['customer_id'] == $value['customer_id'] && $subscription_info['order_id'] == $value['order_id'] && $subscription_info['order_product_id'] == $value['order_product_id']) {
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomer($subscription_info['customer_id']);
$frequencies = [
'day',
'week',
'semi_month',
'month',
'year'
];
// We need to validate frequencies in compliance of the admin subscription plans
// as with the use of the APIs
if ($customer_info && (int)$subscription_info['cycle'] >= 0 && $subscription_info['cycle'] == $value['cycle'] && in_array($subscription_info['frequency'], $frequencies)) {
if ($subscription_info['frequency'] == 'semi_month') {
$period = strtotime("2 weeks");
} else {
$period = strtotime($subscription_info['cycle'] . ' ' . $subscription_info['frequency']);
}
// New customer once the trial period has ended
$customer_period = strtotime($customer_info['date_added']);
$trial_period = 0;
$validate_trial = 0;
// Trial
if ($subscription_info['trial_cycle'] && $subscription_info['trial_frequency'] && $subscription_info['trial_cycle'] == $value['trial_cycle'] && $subscription_info['trial_frequency'] == $value['trial_frequency']) {
if ($subscription_info['trial_frequency'] == 'semi_month') {
$trial_period = strtotime("2 weeks");
} else {
$trial_period = strtotime($subscription_info['trial_cycle'] . ' ' . $subscription_info['trial_frequency']);
}
$trial_period = ($trial_period - $customer_period);
$validate_trial = round($trial_period / (60 * 60 * 24));
}
// Calculates the remaining days between the subscription
// promotional period and the date added period
$period = ($period - $customer_period);
// Calculate remaining period of each features
$period = round($period / (60 * 60 * 24));
// Promotional features description must be identical
// until the time period has exceeded. Therefore, the current
// period must be matched as well
if (($period == 0 && ($validate_trial > 0 || !$validate_trial)) && $value['description'] == $description && $subscription_info['subscription_plan_id'] == $value['subscription_plan_id']) {
// Products
$this->load->model('catalog/product');
$product_subscription_info = $this->model_catalog_product->getSubscription($order_product['product_id'], $subscription_info['subscription_plan_id']);
if ($product_subscription_info) {
// For the next billing cycle
$this->model_account_subscription->addTransaction($value['subscription_id'], $value['order_id'], $this->language->get('text_promotion'), $subscription_info['amount'], $subscription_info['type'], $subscription_info['payment_method'], $subscription_info['payment_code']);
}
}
}
}
}
}
}
// Mail
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($order_info['email']);
$mail->setFrom($from);
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/subscription', $data));
$mail->send();
}
}
}
}
}
}
}
}
*/
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Transaction
*
* @package Opencart\Catalog\Controller\Mail
*/
class Transaction extends \Opencart\System\Engine\Controller {
// catalog/model/account/customer/addTransaction/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
$this->load->language('mail/transaction');
$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomer($args[0]);
if ($customer_info) {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
if ($store_info) {
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['store_url'];
} else {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = $this->config->get('config_url');
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/transaction', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$data['text_received'] = sprintf($this->language->get('mail_text_received'), $store_name);
$data['amount'] = $this->currency->format($args[2], $this->config->get('config_currency'));
$data['total'] = $this->currency->format($this->model_account_customer->getTransactionTotal($args[0]), $this->config->get('config_currency'));
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($customer_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/transaction', $data));
$mail->send();
}
}
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace Opencart\Catalog\Controller\Mail;
/**
* Class Voucher
*
* @package Opencart\Catalog\Controller\Mail
*/
class Voucher extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($args[0]);
// If order status in the complete range create any vouchers that where in the order need to be made available.
if ($order_info && in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) {
// Send out any gift voucher mails
$voucher_query = $this->db->query("SELECT *, vtd.name AS theme FROM `" . DB_PREFIX . "voucher` v LEFT JOIN `" . DB_PREFIX . "voucher_theme` vt ON (v.`voucher_theme_id` = vt.`voucher_theme_id`) LEFT JOIN `" . DB_PREFIX . "voucher_theme_description` vtd ON (vt.`voucher_theme_id` = vtd.`voucher_theme_id`) WHERE v.`order_id` = '" . (int)$order_info['order_id'] . "' AND vtd.`language_id` = '" . (int)$order_info['language_id'] . "'");
if ($voucher_query->num_rows) {
// Send the email in the correct language
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/voucher', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
foreach ($voucher_query->rows as $voucher) {
$from_name = html_entity_decode($voucher['from_name'], ENT_QUOTES, 'UTF-8');
// HTML Mail
$subject = sprintf($this->language->get('mail_text_subject'), $from_name);
$data['title'] = sprintf($this->language->get('mail_text_subject'), $from_name);
$data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']));
$data['text_from'] = sprintf($this->language->get('mail_text_from'), $from_name);
$data['text_redeem'] = sprintf($this->language->get('mail_text_redeem'), $voucher['code']);
if (is_file(DIR_IMAGE . $voucher['image'])) {
$data['image'] = $this->config->get('config_url') . 'image/' . $voucher['image'];
} else {
$data['image'] = '';
}
$data['message'] = nl2br($voucher['message']);
$data['store_name'] = $order_info['store_name'];
$data['store_url'] = $order_info['store_url'];
$mail->setTo($voucher['to_email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/voucher', $data));
$mail->send();
}
}
}
}
}
}

View File

@@ -0,0 +1,440 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Category
*
* @package Opencart\Catalog\Controller\Product
*/
class Category extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): object|null {
$this->load->language('product/category');
if (isset($this->request->get['path'])) {
$path = (string)$this->request->get['path'];
} else {
$path = '';
}
if (isset($this->request->get['filter'])) {
$filter = $this->request->get['filter'];
} else {
$filter = '';
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
$limit = (int)$this->request->get['limit'];
} else {
$limit = $this->config->get('config_pagination');
}
$parts = explode('_', $path);
$category_id = (int)array_pop($parts);
$this->load->model('catalog/category');
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$this->document->setTitle($category_info['meta_title']);
$this->document->setDescription($category_info['meta_description']);
$this->document->setKeywords($category_info['meta_keyword']);
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
];
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$path = '';
foreach ($parts as $path_id) {
if (!$path) {
$path = (int)$path_id;
} else {
$path .= '_' . (int)$path_id;
}
$category_info = $this->model_catalog_category->getCategory($path_id);
if ($category_info) {
$data['breadcrumbs'][] = [
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $path . $url)
];
}
}
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
// Set the last category breadcrumb
$data['breadcrumbs'][] = [
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . $url)
];
$data['heading_title'] = $category_info['name'];
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . html_entity_decode($category_info['image'], ENT_QUOTES, 'UTF-8'))) {
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($category_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
} else {
$data['thumb'] = '';
}
$data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
$url = '';
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['categories'] = [];
$this->load->model('catalog/product');
$results = $this->model_catalog_category->getCategories($category_id);
foreach ($results as $result) {
$filter_data = [
'filter_category_id' => $result['category_id'],
'filter_sub_category' => false
];
$data['categories'][] = [
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
];
}
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['products'] = [];
$filter_data = [
'filter_category_id' => $category_id,
'filter_sub_category' => false,
'filter_filter' => $filter,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
$product_data = [
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . $url)
];
$data['products'][] = $this->load->controller('product/thumb', $product_data);
}
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['sorts'] = [];
$data['sorts'][] = [
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.sort_order&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=DESC' . $url)
];
if ($this->config->get('config_review_status')) {
$data['sorts'][] = [
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=rating&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=rating&order=ASC' . $url)
];
}
$data['sorts'][] = [
'text' => $this->language->get('text_model_asc'),
'value' => 'p.model-ASC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_model_desc'),
'value' => 'p.model-DESC',
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=DESC' . $url)
];
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['limits'] = [];
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
sort($limits);
foreach ($limits as $value) {
$data['limits'][] = [
'text' => $value,
'value' => $value,
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . $url . '&limit=' . $value)
];
}
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $product_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
if ($page == 1) {
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path']), 'canonical');
} else {
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . '&page='. $page), 'canonical');
}
if ($page > 1) {
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . (($page - 2) ? '&page='. ($page - 1) : '')), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . '&page='. ($page + 1)), 'next');
}
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$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('product/category', $data));
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
return null;
}
}

View File

@@ -0,0 +1,214 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Compare
*
* @package Opencart\Catalog\Controller\Product
*/
class Compare extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('product/compare');
$this->load->model('catalog/product');
$this->load->model('catalog/manufacturer');
$this->load->model('localisation/stock_status');
$this->load->model('tool/image');
if (!isset($this->session->data['compare'])) {
$this->session->data['compare'] = [];
}
if (isset($this->request->get['remove'])) {
$key = array_search($this->request->get['remove'], $this->session->data['compare']);
if ($key !== false) {
unset($this->session->data['compare'][$key]);
$this->session->data['success'] = $this->language->get('text_remove');
}
$this->response->redirect($this->url->link('product/compare', 'language=' . $this->config->get('config_language')));
}
$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('product/compare', 'language=' . $this->config->get('config_language'))
];
$data['add_to_cart'] = $this->url->link('checkout/cart.add', 'language=' . $this->config->get('config_language'));
$data['cart'] = $this->url->link('common/cart.info', 'language=' . $this->config->get('config_language'));
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
$data['products'] = [];
$data['attribute_groups'] = [];
foreach ($this->session->data['compare'] as $key => $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if (is_file(DIR_IMAGE . html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_compare_width'), $this->config->get('config_image_compare_height'));
} else {
$image = false;
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$product_info['special']) {
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
if ($manufacturer_info) {
$manufacturer = $manufacturer_info['name'];
} else {
$manufacturer = '';
}
if ($product_info['quantity'] <= 0) {
$stock_status_info = $this->model_localisation_stock_status->getStockStatus($product_info['stock_status_id']);
if ($stock_status_info) {
$availability = $stock_status_info['name'];
} else {
$availability = '';
}
} elseif ($this->config->get('config_stock_display')) {
$availability = $product_info['quantity'];
} else {
$availability = $this->language->get('text_instock');
}
$attribute_data = [];
$attribute_groups = $this->model_catalog_product->getAttributes($product_id);
foreach ($attribute_groups as $attribute_group) {
foreach ($attribute_group['attribute'] as $attribute) {
$attribute_data[$attribute['attribute_id']] = $attribute['text'];
}
}
$data['products'][$product_id] = [
'product_id' => $product_info['product_id'],
'name' => $product_info['name'],
'thumb' => $image,
'price' => $price,
'special' => $special,
'description' => oc_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, 200) . '..',
'model' => $product_info['model'],
'manufacturer' => $manufacturer,
'availability' => $availability,
'minimum' => $product_info['minimum'] > 0 ? $product_info['minimum'] : 1,
'rating' => (int)$product_info['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
'weight' => $this->weight->format($product_info['weight'], $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
'length' => $this->length->format($product_info['length'], $product_info['length_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
'width' => $this->length->format($product_info['width'], $product_info['length_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
'height' => $this->length->format($product_info['height'], $product_info['length_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
'attribute' => $attribute_data,
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id),
'remove' => $this->url->link('product/compare', 'language=' . $this->config->get('config_language') . '&remove=' . $product_id)
];
foreach ($attribute_groups as $attribute_group) {
$data['attribute_groups'][$attribute_group['attribute_group_id']]['name'] = $attribute_group['name'];
foreach ($attribute_group['attribute'] as $attribute) {
$data['attribute_groups'][$attribute_group['attribute_group_id']]['attribute'][$attribute['attribute_id']]['name'] = $attribute['name'];
}
}
} else {
unset($this->session->data['compare'][$key]);
}
}
$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('product/compare', $data));
}
/**
* @return void
*/
public function add(): void {
$this->load->language('product/compare');
$json = [];
if (!isset($this->session->data['compare'])) {
$this->session->data['compare'] = [];
}
if (isset($this->request->post['product_id'])) {
$product_id = (int)$this->request->post['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if (!$product_info) {
$json['error'] = $this->language->get('error_product');
}
if (!$json) {
// If already in array remove the product_id so it will be added to the back of the array
$key = array_search($this->request->post['product_id'], $this->session->data['compare']);
if ($key !== false) {
unset($this->session->data['compare'][$key]);
}
// If we count a numeric value that is greater than 4 products, we remove the first one
if (count($this->session->data['compare']) >= 4) {
array_shift($this->session->data['compare']);
}
$this->session->data['compare'][] = $this->request->post['product_id'];
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare', 'language=' . $this->config->get('config_language')));
$json['total'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@@ -0,0 +1,353 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Manufacturer
*
* @package Opencart\Catalog\Controller\Product
*/
class Manufacturer extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('product/manufacturer');
$this->load->model('catalog/manufacturer');
$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_brand'),
'href' => $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'))
];
$data['categories'] = [];
$results = $this->model_catalog_manufacturer->getManufacturers();
foreach ($results as $result) {
if (is_numeric(oc_substr($result['name'], 0, 1))) {
$key = '0 - 9';
} else {
$key = oc_substr(oc_strtoupper($result['name']), 0, 1);
}
if (!isset($data['categories'][$key])) {
$data['categories'][$key]['name'] = $key;
$data['categories'][$key]['href'] = $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'));
}
$data['categories'][$key]['manufacturer'][] = [
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $result['manufacturer_id'])
];
}
$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('product/manufacturer_list', $data));
}
/**
* @return void
*/
public function info(): \Opencart\System\Engine\Action|null {
$this->load->language('product/manufacturer');
if (isset($this->request->get['manufacturer_id'])) {
$manufacturer_id = (int)$this->request->get['manufacturer_id'];
} else {
$manufacturer_id = 0;
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
$limit = (int)$this->request->get['limit'];
} else {
$limit = (int)$this->config->get('config_pagination');
}
$this->load->model('catalog/manufacturer');
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if ($manufacturer_info) {
$this->document->setTitle($manufacturer_info['name']);
$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_brand'),
'href' => $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'))
];
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $manufacturer_info['name'],
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
];
$data['heading_title'] = $manufacturer_info['name'];
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
$data['products'] = [];
$filter_data = [
'filter_manufacturer_id' => $manufacturer_id,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$this->load->model('catalog/product');
$this->load->model('tool/image');
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
$product_data = [
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'] . $url)
];
$data['products'][] = $this->load->controller('product/thumb', $product_data);
}
$url = '';
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['sorts'] = [];
$data['sorts'][] = [
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url)
];
if ($this->config->get('config_review_status')) {
$data['sorts'][] = [
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=ASC' . $url)
];
}
$data['sorts'][] = [
'text' => $this->language->get('text_model_asc'),
'value' => 'p.model-ASC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_model_desc'),
'value' => 'p.model-DESC',
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url)
];
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['limits'] = [];
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
sort($limits);
foreach ($limits as $value) {
$data['limits'][] = [
'text' => $value,
'value' => $value,
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $value)
];
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $product_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
if ($page == 1) {
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id']), 'canonical');
} else {
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&page=' . $page), 'canonical');
}
if ($page > 1) {
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . (($page - 2) ? '&page=' . ($page - 1) : '')), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&page=' . ($page + 1)), 'next');
}
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$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('product/manufacturer_info', $data));
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
return null;
}
}

View File

@@ -0,0 +1,524 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Product
*
* @package Opencart\Catalog\Controller\Product
*/
class Product extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): \Opencart\System\Engine\Action|null {
$this->load->language('product/product');
if (isset($this->request->get['product_id'])) {
$product_id = (int)$this->request->get['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$this->document->setTitle($product_info['meta_title']);
$this->document->setDescription($product_info['meta_description']);
$this->document->setKeywords($product_info['meta_keyword']);
$this->document->addLink($this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id), 'canonical');
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
];
$this->load->model('catalog/category');
if (isset($this->request->get['path'])) {
$path = '';
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
foreach ($parts as $path_id) {
if (!$path) {
$path = $path_id;
} else {
$path .= '_' . $path_id;
}
$category_info = $this->model_catalog_category->getCategory($path_id);
if ($category_info) {
$data['breadcrumbs'][] = [
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $path)
];
}
}
// Set the last category breadcrumb
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . $url)
];
}
}
$this->load->model('catalog/manufacturer');
if (isset($this->request->get['manufacturer_id'])) {
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_brand'),
'href' => $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'))
];
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
if ($manufacturer_info) {
$data['breadcrumbs'][] = [
'text' => $manufacturer_info['name'],
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
];
}
}
if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . $this->request->get['tag'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_search'),
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url)
];
}
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['manufacturer_id'])) {
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
}
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . $this->request->get['tag'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $product_info['name'],
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . $url . '&product_id=' . $product_id)
];
$this->document->setTitle($product_info['meta_title']);
$this->document->setDescription($product_info['meta_description']);
$this->document->setKeywords($product_info['meta_keyword']);
$this->document->addLink($this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id), 'canonical');
$this->document->addScript('catalog/view/javascript/jquery/magnific/jquery.magnific-popup.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/magnific/magnific-popup.css');
$data['heading_title'] = $product_info['name'];
$data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
$data['text_login'] = 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')));
$data['text_reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']);
$data['tab_review'] = sprintf($this->language->get('tab_review'), $product_info['reviews']);
$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'));
$data['product_id'] = $product_id;
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
if ($manufacturer_info) {
$data['manufacturer'] = $manufacturer_info['name'];
} else {
$data['manufacturer'] = '';
}
$data['manufacturers'] = $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $product_info['manufacturer_id']);
$data['model'] = $product_info['model'];
$data['reward'] = $product_info['reward'];
$data['points'] = $product_info['points'];
$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
if ($product_info['quantity'] <= 0) {
$this->load->model('localisation/stock_status');
$stock_status_info = $this->model_localisation_stock_status->getStockStatus($product_info['stock_status_id']);
if ($stock_status_info) {
$data['stock'] = $stock_status_info['name'];
} else {
$data['stock'] = '';
}
} elseif ($this->config->get('config_stock_display')) {
$data['stock'] = $product_info['quantity'];
} else {
$data['stock'] = $this->language->get('text_instock');
}
$data['rating'] = (int)$product_info['rating'];
$data['review_status'] = (int)$this->config->get('config_review_status');
$data['review'] = $this->load->controller('product/review');
$data['add_to_wishlist'] = $this->url->link('account/wishlist.add', 'language=' . $this->config->get('config_language'));
$data['add_to_compare'] = $this->url->link('product/compare.add', 'language=' . $this->config->get('config_language'));
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'))) {
$data['popup'] = $this->model_tool_image->resize(html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
} else {
$data['popup'] = '';
}
if (is_file(DIR_IMAGE . html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'))) {
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
} else {
$data['thumb'] = '';
}
$data['images'] = [];
$results = $this->model_catalog_product->getImages($product_id);
foreach ($results as $result) {
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
$data['images'][] = [
'popup' => $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
'thumb' => $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
];
}
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$data['price'] = false;
}
if ((float)$product_info['special']) {
$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$data['special'] = false;
}
if ($this->config->get('config_tax')) {
$data['tax'] = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price'], $this->session->data['currency']);
} else {
$data['tax'] = false;
}
$discounts = $this->model_catalog_product->getDiscounts($product_id);
$data['discounts'] = [];
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
foreach ($discounts as $discount) {
$data['discounts'][] = [
'quantity' => $discount['quantity'],
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
];
}
}
$data['options'] = [];
// Check if product is variant
if ($product_info['master_id']) {
$product_id = (int)$product_info['master_id'];
} else {
$product_id = (int)$this->request->get['product_id'];
}
$product_options = $this->model_catalog_product->getOptions($product_id);
foreach ($product_options as $option) {
if ((int)$this->request->get['product_id'] && !isset($product_info['override']['variant'][$option['product_option_id']])) {
$product_option_value_data = [];
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
if (is_file(DIR_IMAGE . html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8'), 50, 50);
} else {
$image = '';
}
$product_option_value_data[] = [
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $image,
'price' => $price,
'price_prefix' => $option_value['price_prefix']
];
}
}
$data['options'][] = [
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
];
}
}
// Subscriptions
$data['subscription_plans'] = [];
$results = $this->model_catalog_product->getSubscriptions($product_id);
foreach ($results as $result) {
$description = '';
if ($result['trial_status']) {
$trial_price = $this->currency->format($this->tax->calculate($result['trial_price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
$trial_cycle = $result['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $result['trial_frequency']);
$trial_duration = $result['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($result['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
$cycle = $result['cycle'];
$frequency = $this->language->get('text_' . $result['frequency']);
$duration = $result['duration'];
if ($duration) {
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
} else {
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}
$data['subscription_plans'][] = [
'subscription_plan_id' => $result['subscription_plan_id'],
'name' => $result['name'],
'description' => $description
];
}
if ($product_info['minimum']) {
$data['minimum'] = $product_info['minimum'];
} else {
$data['minimum'] = 1;
}
$data['share'] = $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . (int)$this->request->get['product_id']);
$data['attribute_groups'] = $this->model_catalog_product->getAttributes($product_id);
$data['products'] = [];
$results = $this->model_catalog_product->getRelated($product_id);
foreach ($results as $result) {
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
$product_data = [
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'])
];
$data['products'][] = $this->load->controller('product/thumb', $product_data);
}
$data['tags'] = [];
if ($product_info['tag']) {
$tags = explode(',', $product_info['tag']);
foreach ($tags as $tag) {
$data['tags'][] = [
'tag' => trim($tag),
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&tag=' . trim($tag))
];
}
}
if ($this->config->get('config_product_report_status')) {
$this->model_catalog_product->addReport($this->request->get['product_id'], $this->request->server['REMOTE_ADDR']);
}
$data['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('product/product', $data));
} else {
return new \Opencart\System\Engine\Action('error/not_found');
}
return null;
}
}

View File

@@ -0,0 +1,198 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Review
*
* @package Opencart\Catalog\Controller\Product
*/
class Review extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$this->load->language('product/review');
$data['text_login'] = 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')));
$data['list'] = $this->getList();
if (isset($this->request->get['product_id'])) {
$data['product_id'] = (int)$this->request->get['product_id'];
} else {
$data['product_id'] = 0;
}
if ($this->customer->isLogged() || $this->config->get('config_review_guest')) {
$data['review_guest'] = true;
} else {
$data['review_guest'] = false;
}
if ($this->customer->isLogged()) {
$data['customer_name'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
} else {
$data['customer_name'] = '';
}
// Create a login token to prevent brute force attacks
$this->session->data['review_token'] = oc_token(32);
$data['review_token'] = $this->session->data['review_token'];
// 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('review', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code']);
} else {
$data['captcha'] = '';
}
$data['language'] = $this->config->get('config_language');
return $this->load->view('product/review', $data);
}
/**
* @return void
*/
public function write(): void {
$this->load->language('product/review');
$json = [];
if (isset($this->request->get['product_id'])) {
$product_id = (int)$this->request->get['product_id'];
} else {
$product_id = 0;
}
if (!isset($this->request->get['review_token']) || !isset($this->session->data['review_token']) || $this->request->get['review_token'] != $this->session->data['review_token']) {
$json['error']['warning'] = $this->language->get('error_token');
}
$keys = [
'name',
'text',
'rating'
];
foreach ($keys as $key) {
if (!isset($this->request->post[$key])) {
$this->request->post[$key] = '';
}
}
$this->load->model('product/product');
$product_info = $this->model_product_product->getProduct($product_id);
if (!$product_info) {
$json['error']['warning'] = $this->language->get('error_product');
}
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 25)) {
$json['error']['name'] = $this->language->get('error_name');
}
if ((oc_strlen($this->request->post['text']) < 25) || (oc_strlen($this->request->post['text']) > 1000)) {
$json['error']['text'] = $this->language->get('error_text');
}
if ($this->request->post['rating'] < 1 || $this->request->post['rating'] > 5) {
$json['error']['rating'] = $this->language->get('error_rating');
}
if (!$this->customer->isLogged() && !$this->config->get('config_review_guest')) {
$json['error']['warning'] = $this->language->get('error_guest');
}
if ($this->customer->isLogged() && $this->config->get('config_review_purchased')) {
$this->load->model('account/order');
if (!$this->model_account_order->getTotalOrdersByProductId($product_id)) {
$json['error']['purchased'] = $this->language->get('error_purchased');
}
}
// 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('review', (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) {
$this->load->model('catalog/review');
$this->model_catalog_review->addReview($product_id, $this->request->post);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('product/review');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
public function getList(): string {
if (isset($this->request->get['product_id'])) {
$product_id = (int)$this->request->get['product_id'];
} else {
$product_id = 0;
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$data['reviews'] = [];
$this->load->model('catalog/review');
$review_total = $this->model_catalog_review->getTotalReviewsByProductId($product_id);
$results = $this->model_catalog_review->getReviewsByProductId($product_id, ($page - 1) * 5, 5);
foreach ($results as $result) {
$data['reviews'][] = [
'author' => $result['author'],
'text' => nl2br($result['text']),
'rating' => (int)$result['rating'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $review_total,
'page' => $page,
'limit' => 5,
'url' => $this->url->link('product/review.list', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($review_total) ? (($page - 1) * 5) + 1 : 0, ((($page - 1) * 5) > ($review_total - 5)) ? $review_total : ((($page - 1) * 5) + 5), $review_total, ceil($review_total / 5));
return $this->load->view('product/review_list', $data);
}
}

View File

@@ -0,0 +1,461 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Search
*
* @package Opencart\Catalog\Controller\Product
*/
class Search extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('product/search');
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
if (isset($this->request->get['search'])) {
$search = $this->request->get['search'];
} else {
$search = '';
}
if (isset($this->request->get['tag'])) {
$tag = $this->request->get['tag'];
} elseif (isset($this->request->get['search'])) {
$tag = $this->request->get['search'];
} else {
$tag = '';
}
if (isset($this->request->get['description'])) {
$description = $this->request->get['description'];
} else {
$description = '';
}
if (isset($this->request->get['category_id'])) {
$category_id = (int)$this->request->get['category_id'];
} else {
$category_id = 0;
}
if (isset($this->request->get['sub_category'])) {
$sub_category = $this->request->get['sub_category'];
} else {
$sub_category = 0;
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
$limit = (int)$this->request->get['limit'];
} else {
$limit = $this->config->get('config_pagination');
}
if (isset($this->request->get['search'])) {
$this->document->setTitle($this->language->get('heading_title') . ' - ' . $this->request->get['search']);
} elseif (isset($this->request->get['tag'])) {
$this->document->setTitle($this->language->get('heading_title') . ' - ' . $this->language->get('heading_tag') . $this->request->get['tag']);
} else {
$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'))
];
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url)
];
if (isset($this->request->get['search'])) {
$data['heading_title'] = $this->language->get('heading_title') . ' - ' . $this->request->get['search'];
} else {
$data['heading_title'] = $this->language->get('heading_title');
}
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
$this->load->model('catalog/category');
// 3 Level Category Search
$data['categories'] = [];
$categories_1 = $this->model_catalog_category->getCategories(0);
foreach ($categories_1 as $category_1) {
$level_2_data = [];
$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);
foreach ($categories_2 as $category_2) {
$level_3_data = [];
$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);
foreach ($categories_3 as $category_3) {
$level_3_data[] = [
'category_id' => $category_3['category_id'],
'name' => $category_3['name'],
];
}
$level_2_data[] = [
'category_id' => $category_2['category_id'],
'name' => $category_2['name'],
'children' => $level_3_data
];
}
$data['categories'][] = [
'category_id' => $category_1['category_id'],
'name' => $category_1['name'],
'children' => $level_2_data
];
}
$data['products'] = [];
if ($search || $tag) {
$filter_data = [
'filter_search' => $search,
'filter_tag' => $tag,
'filter_description' => $description,
'filter_category_id' => $category_id,
'filter_sub_category' => $sub_category,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
$product_data = [
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . $url)
];
$data['products'][] = $this->load->controller('product/thumb', $product_data);
}
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['sorts'] = [];
$data['sorts'][] = [
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.sort_order&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=DESC' . $url)
];
if ($this->config->get('config_review_status')) {
$data['sorts'][] = [
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=rating&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=rating&order=ASC' . $url)
];
}
$data['sorts'][] = [
'text' => $this->language->get('text_model_asc'),
'value' => 'p.model-ASC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_model_desc'),
'value' => 'p.model-DESC',
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=DESC' . $url)
];
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['limits'] = [];
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
sort($limits);
foreach ($limits as $value) {
$data['limits'][] = [
'text' => $value,
'value' => $value,
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url . '&limit=' . $value)
];
}
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $product_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
if (isset($this->request->get['search']) && $this->config->get('config_customer_search')) {
$this->load->model('account/search');
if ($this->customer->isLogged()) {
$customer_id = $this->customer->getId();
} else {
$customer_id = 0;
}
if (isset($this->request->server['REMOTE_ADDR'])) {
$ip = $this->request->server['REMOTE_ADDR'];
} else {
$ip = '';
}
$search_data = [
'keyword' => $search,
'category_id' => $category_id,
'sub_category' => $sub_category,
'description' => $description,
'products' => $product_total,
'customer_id' => $customer_id,
'ip' => $ip
];
$this->model_account_search->addSearch($search_data);
}
}
$data['search'] = $search;
$data['description'] = $description;
$data['category_id'] = $category_id;
$data['sub_category'] = $sub_category;
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$data['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('product/search', $data));
}
}

View File

@@ -0,0 +1,274 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Special
*
* @package Opencart\Catalog\Controller\Product
*/
class Special extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('product/special');
$this->load->model('catalog/product');
$this->load->model('tool/image');
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
$limit = (int)$this->request->get['limit'];
} else {
$limit = $this->config->get('config_pagination');
}
$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'))
];
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url)
];
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
$data['products'] = [];
$filter_data = [
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$product_total = $this->model_catalog_product->getTotalSpecials();
$results = $this->model_catalog_product->getSpecials($filter_data);
foreach ($results as $result) {
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
$product_data = [
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . $url)
];
$data['products'][] = $this->load->controller('product/thumb', $product_data);
}
$url = '';
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['sorts'] = [];
$data['sorts'][] = [
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.sort_order&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_asc'),
'value' => 'ps.price-ASC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=ps.price&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_price_desc'),
'value' => 'ps.price-DESC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=ps.price&order=DESC' . $url)
];
if ($this->config->get('config_review_status')) {
$data['sorts'][] = [
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=rating&order=DESC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=rating&order=ASC' . $url)
];
}
$data['sorts'][] = [
'text' => $this->language->get('text_model_asc'),
'value' => 'p.model-ASC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=ASC' . $url)
];
$data['sorts'][] = [
'text' => $this->language->get('text_model_desc'),
'value' => 'p.model-DESC',
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=DESC' . $url)
];
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['limits'] = [];
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
sort($limits);
foreach ($limits as $value) {
$data['limits'][] = [
'text' => $value,
'value' => $value,
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url . '&limit=' . $value)
];
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $product_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
if ($page == 1) {
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language')), 'canonical');
} else {
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&page='. $page), 'canonical');
}
if ($page > 1) {
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . (($page - 2) ? '&page='. ($page - 1) : '')), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&page='. ($page + 1)), 'next');
}
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$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('product/special', $data));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Opencart\Catalog\Controller\Product;
/**
* Class Thumb
*
* @package Opencart\Catalog\Controller\Product
*/
class Thumb extends \Opencart\System\Engine\Controller {
/**
* @param array $data
*
* @return string
*/
public function index(array $data): string {
$this->load->language('product/thumb');
$data['cart'] = $this->url->link('common/cart.info', 'language=' . $this->config->get('config_language'));
$data['add_to_cart'] = $this->url->link('checkout/cart.add', 'language=' . $this->config->get('config_language'));
$data['add_to_wishlist'] = $this->url->link('account/wishlist.add', 'language=' . $this->config->get('config_language'));
$data['add_to_compare'] = $this->url->link('product/compare.add', 'language=' . $this->config->get('config_language'));
$data['review_status'] = (int)$this->config->get('config_review_status');
return $this->load->view('product/thumb', $data);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Opencart\Catalog\Controller\Startup;
/**
* Class Api
*
* @package Opencart\Catalog\Controller\Startup
*/
class Api extends \Opencart\System\Engine\Controller {
/**
* @return object|\Opencart\System\Engine\Action|null
*/
public function index(): object|null {
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = '';
}
if (substr($route, 0, 4) == 'api/' && $route !== 'api/account/login' && !isset($this->session->data['api_id'])) {
return new \Opencart\System\Engine\Action('error/permission');
}
return null;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Opencart\Catalog\Controller\Startup;
/**
* Class Application
*
* @package Opencart\Catalog\Controller\Startup
*/
class Application extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
// Weight
$this->registry->set('weight', new \Opencart\System\Library\Cart\Weight($this->registry));
// Length
$this->registry->set('length', new \Opencart\System\Library\Cart\Length($this->registry));
// Cart
$this->registry->set('cart', new \Opencart\System\Library\Cart\Cart($this->registry));
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Opencart\Catalog\Controller\Startup;
/**
* Class Currency
*
* @package Opencart\Catalog\Controller\Startup
*/
class Currency extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$code = '';
$this->load->model('localisation/currency');
$currencies = $this->model_localisation_currency->getCurrencies();
if (isset($this->session->data['currency'])) {
$code = $this->session->data['currency'];
}
if (isset($this->request->cookie['currency']) && !array_key_exists($code, $currencies)) {
$code = $this->request->cookie['currency'];
}
if (!array_key_exists($code, $currencies)) {
$code = $this->config->get('config_currency');
}
if (!isset($this->session->data['currency']) || $this->session->data['currency'] != $code) {
$this->session->data['currency'] = $code;
}
// Set a new currency cookie if the code does not match the current one
if (!isset($this->request->cookie['currency']) || $this->request->cookie['currency'] != $code) {
$option = [
'expires' => time() + 60 * 60 * 24 * 30,
'path' => '/',
'SameSite' => 'Lax'
];
setcookie('currency', $code, $option);
}
$this->registry->set('currency', new \Opencart\System\Library\Cart\Currency($this->registry));
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Opencart\Catalog\Controller\Startup;
/**
* Class Customer
*
* @package Opencart\Catalog\Controller\Startup
*/
class Customer extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->registry->set('customer', new \Opencart\System\Library\Cart\Customer($this->registry));
// Customer Group
if (isset($this->session->data['customer'])) {
$this->config->set('config_customer_group_id', $this->session->data['customer']['customer_group_id']);
} elseif ($this->customer->isLogged()) {
// Logged in customers
$this->config->set('config_customer_group_id', $this->customer->getGroupId());
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Opencart\Catalog\Controller\Startup;
/**
* Class Error
*
* @package Opencart\Catalog\Controller\Startup
*/
class Error extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->registry->set('log', new \Opencart\System\Library\Log($this->config->get('config_error_filename')));
set_error_handler([$this, 'error']);
set_exception_handler([$this, 'exception']);
}
/**
* @param string $code
* @param string $message
* @param string $file
* @param string $line
*
* @return bool
*/
public function error(string $code, string $message, string $file, string $line): bool {
switch ($code) {
case E_NOTICE:
case E_USER_NOTICE:
$error = 'Notice';
break;
case E_WARNING:
case E_USER_WARNING:
$error = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$error = 'Fatal Error';
break;
default:
$error = 'Unknown';
break;
}
if ($this->config->get('config_error_log')) {
$this->log->write('PHP ' . $error . ': ' . $message . ' in ' . $file . ' on line ' . $line);
}
if ($this->config->get('config_error_display')) {
echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
} else {
header('Location: ' . $this->config->get('error_page'));
exit();
}
return true;
}
/**
* @param \Throwable $e
*
* @return void
*/
public function exception(\Throwable $e): void {
if ($this->config->get('config_error_log')) {
$this->log->write($e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
}
if ($this->config->get('config_error_display')) {
echo '<b>' . $e->getMessage() . '</b>: in <b>' . $e->getFile() . '</b> on line <b>' . $e->getLine() . '</b>';
} else {
header('Location: ' . $this->config->get('error_page'));
exit();
}
}
}

Some files were not shown because too many files have changed in this diff Show More