first commit
This commit is contained in:
349
catalog/controller/event/activity.php
Normal file
349
catalog/controller/event/activity.php
Normal file
@ -0,0 +1,349 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Event;
|
||||
/**
|
||||
* Class Activity
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Event
|
||||
*/
|
||||
class Activity extends \Opencart\System\Engine\Controller {
|
||||
// catalog/model/account/customer/addCustomer/after
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addCustomer(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $output,
|
||||
'name' => $args[0]['firstname'] . ' ' . $args[0]['lastname']
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('register', $activity_data);
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/customer/editCustomer/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCustomer(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('edit', $activity_data);
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/customer/editPassword/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editPassword(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$activity_data = [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('password', $activity_data);
|
||||
} else {
|
||||
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
|
||||
|
||||
if ($customer_info) {
|
||||
$activity_data = [
|
||||
'customer_id' => $customer_info['customer_id'],
|
||||
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('reset', $activity_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/customer/deleteLoginAttempts/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function login(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($this->request->get['route']) && ($this->request->get['route'] == 'account/login' || $this->request->get['route'] == 'checkout/login.save') && $this->config->get('config_customer_activity')) {
|
||||
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $customer_info['customer_id'],
|
||||
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('login', $activity_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/customer/editCode/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function forgotten(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($this->request->get['route']) && $this->request->get['route'] == 'account/forgotten' && $this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $customer_info['customer_id'],
|
||||
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('forgotten', $activity_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/customer/addTransaction/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addTransaction(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$customer_info = $this->model_account_customer->getCustomer($args[0]);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $customer_info['customer_id'],
|
||||
'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname'],
|
||||
'order_id' => $args[3]
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('transaction', $activity_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/affiliate/addAffiliate/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addAffiliate(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $args[0],
|
||||
'name' => $args[1]['firstname'] . ' ' . $args[1]['lastname']
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('affiliate_add', $activity_data);
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/affiliate/editAffiliate/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAffiliate(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('affiliate_edit', $activity_data);
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/address/addAddress/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addAddress(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('address_add', $activity_data);
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/address/editAddress/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAddress(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('address_edit', $activity_data);
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/address/deleteAddress/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddress(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
$activity_data = [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('address_delete', $activity_data);
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/returns/addReturn/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReturn(string &$route, array &$args, mixed &$output): void {
|
||||
if ($this->config->get('config_customer_activity') && $output) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$activity_data = [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(),
|
||||
'return_id' => $output
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('return_account', $activity_data);
|
||||
} else {
|
||||
$activity_data = [
|
||||
'name' => $args[0]['firstname'] . ' ' . $args[0]['lastname'],
|
||||
'return_id' => $output
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('return_guest', $activity_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/checkout/order/addHistory/before
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory(string &$route, array &$args): void {
|
||||
if ($this->config->get('config_customer_activity')) {
|
||||
// If the last order status id returns 0, and the new order status is not, then we record it as new order
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($args[0]);
|
||||
|
||||
if ($order_info && !$order_info['order_status_id'] && $args[1]) {
|
||||
$this->load->model('account/activity');
|
||||
|
||||
if ($order_info['customer_id']) {
|
||||
$activity_data = [
|
||||
'customer_id' => $order_info['customer_id'],
|
||||
'name' => $order_info['firstname'] . ' ' . $order_info['lastname'],
|
||||
'order_id' => $args[0]
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('order_account', $activity_data);
|
||||
} else {
|
||||
$activity_data = [
|
||||
'name' => $order_info['firstname'] . ' ' . $order_info['lastname'],
|
||||
'order_id' => $args[0]
|
||||
];
|
||||
|
||||
$this->model_account_activity->addActivity('order_guest', $activity_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
catalog/controller/event/debug.php
Normal file
56
catalog/controller/event/debug.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Event;
|
||||
/**
|
||||
* Class Debug
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Event
|
||||
*/
|
||||
class Debug extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args): void {
|
||||
//echo $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function before(string &$route, array &$args): void {
|
||||
// add the route you want to test
|
||||
/*
|
||||
if ($route == 'common/home') {
|
||||
$this->session->data['debug'][$route] = microtime(true);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function after(string $route, array &$args, mixed &$output): void {
|
||||
// add the route you want to test
|
||||
/*
|
||||
if ($route == 'common/home') {
|
||||
if (isset($this->session->data['debug'][$route])) {
|
||||
$log_data = [
|
||||
'route' => $route,
|
||||
'time' => microtime(true) - $this->session->data['debug'][$route]
|
||||
];
|
||||
|
||||
$this->log->write($log_data);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
61
catalog/controller/event/language.php
Normal file
61
catalog/controller/event/language.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Event;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Event
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Controller {
|
||||
// view/*/before
|
||||
// Dump all the language vars into the template.
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args): void {
|
||||
foreach ($this->language->all() as $key => $value) {
|
||||
if (!isset($args[$key])) {
|
||||
$args[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// controller/*/before
|
||||
// 1. Before controller load store all current loaded language data
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function before(string &$route, array &$args): void {
|
||||
$data = $this->language->all();
|
||||
|
||||
if ($data) {
|
||||
$this->language->set('backup', json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
// controller/*/after
|
||||
// 2. After controller load restore old language data
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function after(string &$route, array &$args, mixed &$output): void {
|
||||
$data = json_decode($this->language->get('backup'), true);
|
||||
|
||||
if (is_array($data)) {
|
||||
$this->language->clear();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$this->language->set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
93
catalog/controller/event/statistics.php
Normal file
93
catalog/controller/event/statistics.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Event;
|
||||
/**
|
||||
* Class Statistics
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Event
|
||||
*/
|
||||
class Statistics extends \Opencart\System\Engine\Controller {
|
||||
// catalog/model/catalog/review/addReview/after
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReview(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$this->model_report_statistics->addValue('review', 1);
|
||||
}
|
||||
|
||||
// catalog/model/account/returns/addReturn/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReturn(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$this->model_report_statistics->addValue('returns', 1);
|
||||
}
|
||||
|
||||
// catalog/model/checkout/order/addHistory/before
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory(string &$route, array &$args): void {
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($args[0]);
|
||||
|
||||
if ($order_info) {
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$old_status_id = $order_info['order_status_id'];
|
||||
$new_status_id = $args[1];
|
||||
|
||||
$processing_status = (array)$this->config->get('config_processing_status');
|
||||
$complete_status = (array)$this->config->get('config_complete_status');
|
||||
|
||||
$active_status = array_merge($processing_status, $complete_status);
|
||||
|
||||
// If order status in complete or processing add value to sale total
|
||||
if (in_array($new_status_id, $active_status) && !in_array($old_status_id, $active_status)) {
|
||||
$this->model_report_statistics->addValue('order_sale', $order_info['total']);
|
||||
}
|
||||
|
||||
// If order status not in complete or processing remove value to sale total
|
||||
if (!in_array($new_status_id, $active_status) && in_array($old_status_id, $active_status)) {
|
||||
$this->model_report_statistics->removeValue('order_sale', $order_info['total']);
|
||||
}
|
||||
|
||||
// Add to processing status if new status is in the array
|
||||
if (in_array($new_status_id, $processing_status) && !in_array($old_status_id, $processing_status)) {
|
||||
$this->model_report_statistics->addValue('order_processing', 1);
|
||||
}
|
||||
|
||||
// Remove from processing status if new status is not array and old status is
|
||||
if (!in_array($new_status_id, $processing_status) && in_array($old_status_id, $processing_status)) {
|
||||
$this->model_report_statistics->removeValue('order_processing', 1);
|
||||
}
|
||||
|
||||
// Add to complete status if new status is not array
|
||||
if (in_array($new_status_id, $complete_status) && !in_array($old_status_id, $complete_status)) {
|
||||
$this->model_report_statistics->addValue('order_complete', 1);
|
||||
}
|
||||
|
||||
// Remove from complete status if new status is not array
|
||||
if (!in_array($new_status_id, $complete_status) && in_array($old_status_id, $complete_status)) {
|
||||
$this->model_report_statistics->removeValue('order_complete', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
catalog/controller/event/theme.php
Normal file
26
catalog/controller/event/theme.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Event;
|
||||
/**
|
||||
* Class Theme
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Event
|
||||
*/
|
||||
class Theme extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args, string &$code): void {
|
||||
// If there is a theme override we should get it
|
||||
$this->load->model('design/theme');
|
||||
|
||||
$theme_info = $this->model_design_theme->getTheme($route, $this->config->get('config_theme'));
|
||||
|
||||
if ($theme_info) {
|
||||
$code = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
}
|
28
catalog/controller/event/translation.php
Normal file
28
catalog/controller/event/translation.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Event;
|
||||
/**
|
||||
* Class Translation
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Event
|
||||
*/
|
||||
class Translation extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, string &$prefix): void {
|
||||
$this->load->model('design/translation');
|
||||
|
||||
$results = $this->model_design_translation->getTranslations($route);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!$prefix) {
|
||||
$this->language->set($result['key'], html_entity_decode($result['value'], ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$this->language->set($prefix . '_' . $result['key'], html_entity_decode($result['value'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user