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