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,24 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Activity
*
* @package Opencart\Catalog\Model\Account
*/
class Activity extends \Opencart\System\Engine\Model {
/**
* @param string $key
* @param array $data
*
* @return void
*/
public function addActivity(string $key, array $data): void {
if (isset($data['customer_id'])) {
$customer_id = $data['customer_id'];
} else {
$customer_id = 0;
}
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_activity` SET `customer_id` = '" . (int)$customer_id . "', `key` = '" . $this->db->escape($key) . "', `data` = '" . $this->db->escape(json_encode($data)) . "', `ip` = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', `date_added` = NOW()");
}
}

View File

@ -0,0 +1,144 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Address
*
* @package Opencart\Catalog\Model\Account
*/
class Address extends \Opencart\System\Engine\Model {
/**
* @param int $customer_id
* @param array $data
*
* @return int
*/
public function addAddress(int $customer_id, array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "address` SET `customer_id` = '" . (int)$customer_id . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `company` = '" . $this->db->escape((string)$data['company']) . "', `address_1` = '" . $this->db->escape((string)$data['address_1']) . "', `address_2` = '" . $this->db->escape((string)$data['address_2']) . "', `postcode` = '" . $this->db->escape((string)$data['postcode']) . "', `city` = '" . $this->db->escape((string)$data['city']) . "', `zone_id` = '" . (int)$data['zone_id'] . "', `country_id` = '" . (int)$data['country_id'] . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "', `default` = '" . (isset($data['default']) ? (int)$data['default'] : 0) . "'");
$address_id = $this->db->getLastId();
if (!empty($data['default'])) {
$this->db->query("UPDATE `" . DB_PREFIX . "address` SET `default` = '0' WHERE `address_id` != '" . (int)$address_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
}
return $address_id;
}
/**
* @param int $address_id
* @param array $data
*
* @return void
*/
public function editAddress(int $address_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "address` SET `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `company` = '" . $this->db->escape((string)$data['company']) . "', `address_1` = '" . $this->db->escape((string)$data['address_1']) . "', `address_2` = '" . $this->db->escape((string)$data['address_2']) . "', `postcode` = '" . $this->db->escape((string)$data['postcode']) . "', `city` = '" . $this->db->escape((string)$data['city']) . "', `zone_id` = '" . (int)$data['zone_id'] . "', `country_id` = '" . (int)$data['country_id'] . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "', `default` = '" . (isset($data['default']) ? (int)$data['default'] : 0) . "' WHERE `address_id` = '" . (int)$address_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
if (!empty($data['default'])) {
$this->db->query("UPDATE `" . DB_PREFIX . "address` SET `default` = '0' WHERE `address_id` != '" . (int)$address_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
}
}
/**
* @param int $address_id
*
* @return void
*/
public function deleteAddress(int $address_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "address` WHERE `address_id` = '" . (int)$address_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
}
/**
* @param int $customer_id
* @param int $address_id
*
* @return array
*/
public function getAddress(int $customer_id, int $address_id): array {
$address_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "address` WHERE `address_id` = '" . (int)$address_id . "' AND `customer_id` = '" . (int)$customer_id . "'");
if ($address_query->num_rows) {
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($address_query->row['country_id']);
if ($country_info) {
$country = $country_info['name'];
$iso_code_2 = $country_info['iso_code_2'];
$iso_code_3 = $country_info['iso_code_3'];
$address_format = $country_info['address_format'];
} else {
$country = '';
$iso_code_2 = '';
$iso_code_3 = '';
$address_format = '';
}
$this->load->model('localisation/zone');
$zone_info = $this->model_localisation_zone->getZone($address_query->row['zone_id']);
if ($zone_info) {
$zone = $zone_info['name'];
$zone_code = $zone_info['code'];
} else {
$zone = '';
$zone_code = '';
}
return [
'address_id' => $address_query->row['address_id'],
'firstname' => $address_query->row['firstname'],
'lastname' => $address_query->row['lastname'],
'company' => $address_query->row['company'],
'address_1' => $address_query->row['address_1'],
'address_2' => $address_query->row['address_2'],
'city' => $address_query->row['city'],
'postcode' => $address_query->row['postcode'],
'zone_id' => $address_query->row['zone_id'],
'zone' => $zone,
'zone_code' => $zone_code,
'country_id' => $address_query->row['country_id'],
'country' => $country,
'iso_code_2' => $iso_code_2,
'iso_code_3' => $iso_code_3,
'address_format' => $address_format,
'custom_field' => json_decode($address_query->row['custom_field'], true),
'default' => $address_query->row['default']
];
} else {
return [];
}
}
/**
* @param int $customer_id
*
* @return array
*/
public function getAddresses(int $customer_id): array {
$address_data = [];
$query = $this->db->query("SELECT `address_id` FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
foreach ($query->rows as $result) {
$address_info = $this->getAddress($customer_id, $result['address_id']);
if ($address_info) {
$address_data[$result['address_id']] = $address_info;
}
}
return $address_data;
}
/**
* @param int $customer_id
*
* @return int
*/
public function getTotalAddresses(int $customer_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Affiliate
*
* @package Opencart\Catalog\Model\Account
*/
class Affiliate extends \Opencart\System\Engine\Model {
/**
* @param int $customer_id
* @param array $data
*
* @return void
*/
public function addAffiliate(int $customer_id, array $data): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_affiliate` SET `customer_id` = '" . (int)$customer_id . "', `company` = '" . $this->db->escape((string)$data['company']) . "', `website` = '" . $this->db->escape((string)$data['website']) . "', `tracking` = '" . $this->db->escape(oc_token(10)) . "', `commission` = '" . (float)$this->config->get('config_affiliate_commission') . "', `tax` = '" . $this->db->escape((string)$data['tax']) . "', `payment_method` = '" . $this->db->escape((string)$data['payment_method']) . "', `cheque` = '" . $this->db->escape((string)$data['cheque']) . "', `paypal` = '" . $this->db->escape((string)$data['paypal']) . "', `bank_name` = '" . $this->db->escape((string)$data['bank_name']) . "', `bank_branch_number` = '" . $this->db->escape((string)$data['bank_branch_number']) . "', `bank_swift_code` = '" . $this->db->escape((string)$data['bank_swift_code']) . "', `bank_account_name` = '" . $this->db->escape((string)$data['bank_account_name']) . "', `bank_account_number` = '" . $this->db->escape((string)$data['bank_account_number']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "', `status` = '" . (int)!$this->config->get('config_affiliate_approval') . "', `date_added` = NOW()");
if ($this->config->get('config_affiliate_approval')) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_approval` SET `customer_id` = '" . (int)$customer_id . "', `type` = 'affiliate', `date_added` = NOW()");
}
}
/**
* @param int $customer_id
* @param array $data
*
* @return void
*/
public function editAffiliate(int $customer_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer_affiliate` SET `company` = '" . $this->db->escape((string)$data['company']) . "', `website` = '" . $this->db->escape((string)$data['website']) . "', `commission` = '" . (float)$this->config->get('config_affiliate_commission') . "', `tax` = '" . $this->db->escape((string)$data['tax']) . "', `payment_method` = '" . $this->db->escape((string)$data['payment_method']) . "', `cheque` = '" . $this->db->escape((string)$data['cheque']) . "', `paypal` = '" . $this->db->escape((string)$data['paypal']) . "', `bank_name` = '" . $this->db->escape((string)$data['bank_name']) . "', `bank_branch_number` = '" . $this->db->escape((string)$data['bank_branch_number']) . "', `bank_swift_code` = '" . $this->db->escape((string)$data['bank_swift_code']) . "', `bank_account_name` = '" . $this->db->escape((string)$data['bank_account_name']) . "', `bank_account_number` = '" . $this->db->escape((string)$data['bank_account_number']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
}
/**
* @param int $customer_id
*
* @return array
*/
public function getAffiliate(int $customer_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_affiliate` WHERE `customer_id` = '" . (int)$customer_id . "'");
return $query->row;
}
/**
* @param string $code
*
* @return array
*/
public function getAffiliateByTracking(string $code): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_affiliate` WHERE `tracking` = '" . $this->db->escape($code) . "'");
return $query->row;
}
/**
* @param int $customer_id
* @param string $ip
* @param string $country
*
* @return void
*/
public function addReport(int $customer_id, string $ip, string $country = ''): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_affiliate_report` SET `customer_id` = '" . (int)$customer_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Api
*
* @package Opencart\Catalog\Model\Account
*/
class Api extends \Opencart\System\Engine\Model {
/**
* @param string $username
* @param string $key
*
* @return array
*/
public function login(string $username, string $key): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE `username` = '" . $this->db->escape($username) . "' AND `key` = '" . $this->db->escape($key) . "' AND `status` = '1'");
return $query->row;
}
/**
* @param int $api_id
* @param string $session_id
* @param string $ip
*
* @return int
*/
public function addSession(int $api_id, string $session_id, string $ip): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_session` SET `api_id` = '" . (int)$api_id . "', `session_id` = '" . $this->db->escape($session_id) . "', `ip` = '" . $this->db->escape($ip) . "', `date_added` = NOW(), `date_modified` = NOW()");
return $this->db->getLastId();
}
/**
* @param int $api_id
*
* @return array
*/
public function getIps(int $api_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_ip` WHERE `api_id` = '" . (int)$api_id . "'");
return $query->rows;
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class CustomField
*
* @package Opencart\Catalog\Model\Account
*/
class CustomField extends \Opencart\System\Engine\Model {
/**
* @param int $custom_field_id
*
* @return array
*/
public function getCustomField(int $custom_field_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cf.`status` = '1' AND cf.`custom_field_id` = '" . (int)$custom_field_id . "' AND cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
return $query->row;
}
/**
* @param int $customer_group_id
*
* @return array
*/
public function getCustomFields(int $customer_group_id = 0): array {
$custom_field_data = [];
if (!$customer_group_id) {
$custom_field_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cf.`status` = '1' AND cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY cf.`sort_order` ASC");
} else {
$custom_field_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_customer_group` cfcg LEFT JOIN `" . DB_PREFIX . "custom_field` cf ON (cfcg.`custom_field_id` = cf.`custom_field_id`) LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cf.`status` = '1' AND cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND cfcg.`customer_group_id` = '" . (int)$customer_group_id . "' ORDER BY cf.`sort_order` ASC");
}
foreach ($custom_field_query->rows as $custom_field) {
$custom_field_value_data = [];
if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio' || $custom_field['type'] == 'checkbox') {
$custom_field_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` cfv LEFT JOIN `" . DB_PREFIX . "custom_field_value_description` cfvd ON (cfv.`custom_field_value_id` = cfvd.`custom_field_value_id`) WHERE cfv.`custom_field_id` = '" . (int)$custom_field['custom_field_id'] . "' AND cfvd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY cfv.`sort_order` ASC");
foreach ($custom_field_value_query->rows as $custom_field_value) {
$custom_field_value_data[] = [
'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
'name' => $custom_field_value['name']
];
}
}
$custom_field_data[] = [
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $custom_field_value_data,
'name' => $custom_field['name'],
'type' => $custom_field['type'],
'value' => $custom_field['value'],
'validation' => $custom_field['validation'],
'location' => $custom_field['location'],
'required' => empty($custom_field['required']) || $custom_field['required'] == 0 ? false : true,
'sort_order' => $custom_field['sort_order']
];
}
return $custom_field_data;
}
}

View File

@ -0,0 +1,284 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Customer
*
* @package Opencart\Catalog\Model\Account
*/
class Customer extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return int
*/
public function addCustomer(array $data): int {
if (isset($data['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($data['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = (int)$data['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);
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer` SET `customer_group_id` = '" . (int)$customer_group_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `language_id` = '" . (int)$this->config->get('config_language_id') . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "', `password` = '" . $this->db->escape(password_hash(html_entity_decode($data['password'], ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "', `newsletter` = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "', `ip` = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', `status` = '" . (int)!$customer_group_info['approval'] . "', `date_added` = NOW()");
$customer_id = $this->db->getLastId();
if ($customer_group_info['approval']) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_approval` SET `customer_id` = '" . (int)$customer_id . "', `type` = 'customer', `date_added` = NOW()");
}
return $customer_id;
}
/**
* @param int $customer_id
* @param array $data
*
* @return void
*/
public function editCustomer(int $customer_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
}
/**
* @param string $email
* @param string $password
*
* @return void
*/
public function editPassword(string $email, string $password): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `password` = '" . $this->db->escape(password_hash(html_entity_decode($password, ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "', `code` = '' WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
}
/**
* @param string $email
* @param string $code
*
* @return void
*/
public function editCode(string $email, string $code): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `code` = '" . $this->db->escape($code) . "' WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
}
/**
* @param string $email
* @param string $token
*
* @return void
*/
public function editToken(string $email, string $token): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `token` = '" . $this->db->escape($token) . "' WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
}
/**
* @param bool $newsletter
*
* @return void
*/
public function editNewsletter(bool $newsletter): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `newsletter` = '" . (int)$newsletter . "' WHERE `customer_id` = '" . (int)$this->customer->getId() . "'");
}
/**
* @param int $customer_id
*
* @return void
*/
public function deleteCustomer(int $customer_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_activity` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_history` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
}
/**
* @param int $customer_id
*
* @return array
*/
public function getCustomer(int $customer_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");
return $query->row;
}
/**
* @param string $email
*
* @return array
*/
public function getCustomerByEmail(string $email): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
return $query->row;
}
/**
* @param string $code
*
* @return array
*/
public function getCustomerByCode(string $code): array {
$query = $this->db->query("SELECT `customer_id`, `firstname`, `lastname`, `email` FROM `" . DB_PREFIX . "customer` WHERE `code` = '" . $this->db->escape($code) . "' AND `code` != ''");
return $query->row;
}
/**
* @param string $token
*
* @return array
*/
public function getCustomerByToken(string $token): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE `token` = '" . $this->db->escape($token) . "' AND `token` != ''");
if ($query->num_rows) {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `token` = '' WHERE `customer_id` = '" . (int)$query->row['customer_id'] . "'");
}
return $query->row;
}
/**
* @param string $email
*
* @return int
*/
public function getTotalCustomersByEmail(string $email): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
* @param string $description
* @param float $amount
* @param int $order_id
*
* @return void
*/
public function addTransaction(int $customer_id, string $description, float $amount = 0, int $order_id = 0): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_transaction` SET `customer_id` = '" . (int)$customer_id . "', `order_id` = '" . (int)$order_id . "', `description` = '" . $this->db->escape($description) . "', `amount` = '" . (float)$amount . "', `date_added` = NOW()");
}
/**
* @param int $order_id
*
* @return void
*/
public function deleteTransactionByOrderId(int $order_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
}
/**
* @param int $customer_id
*
* @return float
*/
public function getTransactionTotal(int $customer_id): float {
$query = $this->db->query("SELECT SUM(`amount`) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (float)$query->row['total'];
}
/**
* @param int $order_id
*
* @return int
*/
public function getTotalTransactionsByOrderId(int $order_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
*
* @return int
*/
public function getRewardTotal(int $customer_id): int {
$query = $this->db->query("SELECT SUM(`points`) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
*
* @return array
*/
public function getIps(int $customer_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "'");
return $query->rows;
}
/**
* @param int $customer_id
*
* @return int
*/
public function getTotalIps(int $customer_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
* @param string $ip
* @param string $country
*
* @return void
*/
public function addLogin(int $customer_id, string $ip, string $country = ''): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_ip` SET `customer_id` = '" . (int)$customer_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
}
/**
* @param string $email
*
* @return void
*/
public function addLoginAttempt(string $email): void {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_login` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower((string)$email)) . "' AND `ip` = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
if (!$query->num_rows) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_login` SET `email` = '" . $this->db->escape(oc_strtolower((string)$email)) . "', `ip` = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', `total` = '1', `date_added` = '" . $this->db->escape(date('Y-m-d H:i:s')) . "', `date_modified` = '" . $this->db->escape(date('Y-m-d H:i:s')) . "'");
} else {
$this->db->query("UPDATE `" . DB_PREFIX . "customer_login` SET `total` = (`total` + 1), `date_modified` = '" . $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE `customer_login_id` = '" . (int)$query->row['customer_login_id'] . "'");
}
}
/**
* @param string $email
*
* @return array
*/
public function getLoginAttempts(string $email): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_login` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
return $query->row;
}
/**
* @param string $email
*
* @return void
*/
public function deleteLoginAttempts(string $email): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_login` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Customer Group
*
* @package Opencart\Catalog\Model\Account
*/
class CustomerGroup extends \Opencart\System\Engine\Model {
/**
* @param int $customer_group_id
*
* @return array
*/
public function getCustomerGroup(int $customer_group_id): array {
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "customer_group` cg LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (cg.`customer_group_id` = cgd.`customer_group_id`) WHERE cg.`customer_group_id` = '" . (int)$customer_group_id . "' AND cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
return $query->row;
}
/**
* @return array
*/
public function getCustomerGroups(): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_group` cg LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (cg.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY cg.`sort_order` ASC, cgd.`name` ASC");
return $query->rows;
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Download
*
* @package Opencart\Catalog\Model\Account
*/
class Download extends \Opencart\System\Engine\Model {
/**
* @param int $download_id
*
* @return array
*/
public function getDownload(int $download_id): array {
$implode = [];
$order_statuses = (array)$this->config->get('config_complete_status');
foreach ($order_statuses as $order_status_id) {
$implode[] = "o.`order_status_id` = '" . (int)$order_status_id . "'";
}
if ($implode) {
$query = $this->db->query("SELECT d.`filename`, d.`mask` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.`order_id` = op.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` p2d ON (op.`product_id` = p2d.`product_id`) LEFT JOIN `" . DB_PREFIX . "download` d ON (p2d.`download_id` = d.`download_id`) WHERE o.`customer_id` = '" . (int)$this->customer->getId() . "' AND (" . implode(" OR ", $implode) . ") AND d.`download_id` = '" . (int)$download_id . "'");
return $query->row;
}
return [];
}
/**
* @param int $start
* @param int $limit
*
* @return array
*/
public function getDownloads(int $start = 0, int $limit = 20): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 20;
}
$implode = [];
$order_statuses = (array)$this->config->get('config_complete_status');
foreach ($order_statuses as $order_status_id) {
$implode[] = "o.`order_status_id` = '" . (int)$order_status_id . "'";
}
if ($implode) {
$query = $this->db->query("SELECT DISTINCT d.`download_id`, o.`order_id`, o.`date_added`, dd.`name`, d.`filename` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.`order_id` = op.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` p2d ON (op.`product_id` = p2d.`product_id`) LEFT JOIN `" . DB_PREFIX . "download` d ON (p2d.`download_id` = d.`download_id`) LEFT JOIN `" . DB_PREFIX . "download_description` dd ON (d.`download_id` = dd.`download_id`) WHERE o.`customer_id` = '" . (int)$this->customer->getId() . "' AND o.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND (" . implode(" OR ", $implode) . ") AND dd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY dd.`name` ASC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
return [];
}
/**
* @return int
*/
public function getTotalDownloads(): int {
$implode = [];
$order_statuses = (array)$this->config->get('config_complete_status');
foreach ($order_statuses as $order_status_id) {
$implode[] = "o.`order_status_id` = '" . (int)$order_status_id . "'";
}
if ($implode) {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.`order_id` = op.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` p2d ON (op.`product_id` = p2d.`product_id`) WHERE o.`customer_id` = '" . (int)$this->customer->getId() . "' AND o.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND (" . implode(" OR ", $implode) . ") AND p2d.`download_id` > 0");
return $query->row['total'];
}
return 0;
}
/**
* @param int $download_id
* @param string $ip
* @param string $country
*
* @return void
*/
public function addReport(int $download_id, string $ip, string $country = ''): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "download_report` SET `download_id` = '" . (int)$download_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Gdpr
*
* @package Opencart\Catalog\Model\Account
*/
class Gdpr extends \Opencart\System\Engine\Model {
/**
* @param string $code
* @param string $email
* @param string $action
*
* @return void
*/
public function addGdpr(string $code, string $email, string $action): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "gdpr` SET `store_id` = '" . $this->db->escape($this->config->get('config_store_id')) . "', `language_id` = '" . $this->db->escape($this->config->get('config_language_id')) . "', `code` = '" . $this->db->escape($code) . "', `email` = '" . $this->db->escape($email) . "', `action` = '" . $this->db->escape($action) . "', `date_added` = NOW()");
}
/**
* @param int $gdpr_id
* @param int $status
*
* @return void
*/
public function editStatus(int $gdpr_id, int $status): void {
$this->db->query("UPDATE `" . DB_PREFIX . "gdpr` SET `status` = '" . (int)$status . "' WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
}
/**
* @param int $gdpr_id
*
* @return array
*/
public function getGdpr(int $gdpr_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
return $query->row;
}
/**
* @param string $code
*
* @return array
*/
public function getGdprByCode(string $code): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `code` = '" . $this->db->escape($code) . "'");
return $query->row;
}
/**
* @param string $email
*
* @return array
*/
public function getGdprsByEmail(string $email): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `email` = '" . $this->db->escape($email) . "'");
return $query->rows;
}
/**
* @return array
*/
public function getExpires(): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `status` = '2' AND DATE(`date_added`) <= DATE('" . $this->db->escape(date('Y-m-d', strtotime('+' . (int)$this->config->get('config_gdpr_limit') . ' days'))) . "') ORDER BY `date_added` DESC");
return $query->rows;
}
}

View File

@ -0,0 +1,318 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Order
*
* @package Opencart\Catalog\Model\Account
*/
class Order extends \Opencart\System\Engine\Model {
/**
* @param int $order_id
*
* @return array
*/
public function getOrder(int $order_id): array {
$order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE `order_id` = '" . (int)$order_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "' AND `customer_id` != '0' AND `order_status_id` > '0'");
if ($order_query->num_rows) {
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE `country_id` = '" . (int)$order_query->row['payment_country_id'] . "'");
if ($country_query->num_rows) {
$payment_iso_code_2 = $country_query->row['iso_code_2'];
$payment_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$payment_iso_code_2 = '';
$payment_iso_code_3 = '';
}
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$order_query->row['payment_zone_id'] . "'");
if ($zone_query->num_rows) {
$payment_zone_code = $zone_query->row['code'];
} else {
$payment_zone_code = '';
}
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'");
if ($country_query->num_rows) {
$shipping_iso_code_2 = $country_query->row['iso_code_2'];
$shipping_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$shipping_iso_code_2 = '';
$shipping_iso_code_3 = '';
}
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$order_query->row['shipping_zone_id'] . "'");
if ($zone_query->num_rows) {
$shipping_zone_code = $zone_query->row['code'];
} else {
$shipping_zone_code = '';
}
return [
'order_id' => $order_query->row['order_id'],
'invoice_no' => $order_query->row['invoice_no'],
'invoice_prefix' => $order_query->row['invoice_prefix'],
'store_id' => $order_query->row['store_id'],
'store_name' => $order_query->row['store_name'],
'store_url' => $order_query->row['store_url'],
'customer_id' => $order_query->row['customer_id'],
'firstname' => $order_query->row['firstname'],
'lastname' => $order_query->row['lastname'],
'telephone' => $order_query->row['telephone'],
'email' => $order_query->row['email'],
'payment_firstname' => $order_query->row['payment_firstname'],
'payment_lastname' => $order_query->row['payment_lastname'],
'payment_company' => $order_query->row['payment_company'],
'payment_address_1' => $order_query->row['payment_address_1'],
'payment_address_2' => $order_query->row['payment_address_2'],
'payment_postcode' => $order_query->row['payment_postcode'],
'payment_city' => $order_query->row['payment_city'],
'payment_zone_id' => $order_query->row['payment_zone_id'],
'payment_zone' => $order_query->row['payment_zone'],
'payment_zone_code' => $payment_zone_code,
'payment_country_id' => $order_query->row['payment_country_id'],
'payment_country' => $order_query->row['payment_country'],
'payment_iso_code_2' => $payment_iso_code_2,
'payment_iso_code_3' => $payment_iso_code_3,
'payment_address_format' => $order_query->row['payment_address_format'],
'payment_method' => $order_query->row['payment_method'] ? json_decode($order_query->row['payment_method'], true) : '',
'shipping_firstname' => $order_query->row['shipping_firstname'],
'shipping_lastname' => $order_query->row['shipping_lastname'],
'shipping_company' => $order_query->row['shipping_company'],
'shipping_address_1' => $order_query->row['shipping_address_1'],
'shipping_address_2' => $order_query->row['shipping_address_2'],
'shipping_postcode' => $order_query->row['shipping_postcode'],
'shipping_city' => $order_query->row['shipping_city'],
'shipping_zone_id' => $order_query->row['shipping_zone_id'],
'shipping_zone' => $order_query->row['shipping_zone'],
'shipping_zone_code' => $shipping_zone_code,
'shipping_country_id' => $order_query->row['shipping_country_id'],
'shipping_country' => $order_query->row['shipping_country'],
'shipping_iso_code_2' => $shipping_iso_code_2,
'shipping_iso_code_3' => $shipping_iso_code_3,
'shipping_address_format' => $order_query->row['shipping_address_format'],
'shipping_method' => $order_query->row['shipping_method'] ? json_decode($order_query->row['shipping_method'], true) : '',
'comment' => $order_query->row['comment'],
'total' => $order_query->row['total'],
'order_status_id' => $order_query->row['order_status_id'],
'language_id' => $order_query->row['language_id'],
'currency_id' => $order_query->row['currency_id'],
'currency_code' => $order_query->row['currency_code'],
'currency_value' => $order_query->row['currency_value'],
'date_modified' => $order_query->row['date_modified'],
'date_added' => $order_query->row['date_added'],
'ip' => $order_query->row['ip']
];
} else {
return [];
}
}
/**
* @param int $start
* @param int $limit
*
* @return array
*/
public function getOrders(int $start = 0, int $limit = 20): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 1;
}
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `order_status_id` > '0' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "' ORDER BY `order_id` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @param int $subscription_id
* @param int $start
* @param int $limit
*
* @return array
*/
public function getOrdersBySubscriptionId(int $subscription_id, int $start = 0, int $limit = 20): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 1;
}
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE `subscription_id` = '" . (int)$subscription_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "' AND `order_status_id` > '0' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "' ORDER BY `order_id` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @param int $subscription_id
*
* @return int
*/
public function getTotalOrdersBySubscriptionId(int $subscription_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE `subscription_id` = '" . (int)$subscription_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
return (int)$query->row['total'];
}
/**
* @param int $order_id
* @param int $order_product_id
*
* @return array
*/
public function getProduct(int $order_id, int $order_product_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "'");
return $query->row;
}
/**
* @param int $order_id
*
* @return array
*/
public function getProducts(int $order_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
return $query->rows;
}
/**
* @param int $order_id
* @param int $order_product_id
*
* @return array
*/
public function getOptions(int $order_id, int $order_product_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_option` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "'");
return $query->rows;
}
/**
* @param int $order_id
* @param int $order_product_id
*
* @return array
*/
public function getSubscription(int $order_id, int $order_product_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_subscription` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "'");
return $query->row;
}
/**
* @param int $order_id
*
* @return array
*/
public function getVouchers(int $order_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_voucher` WHERE `order_id` = '" . (int)$order_id . "'");
return $query->rows;
}
/**
* @param int $order_id
*
* @return array
*/
public function getTotals(int $order_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_total` WHERE `order_id` = '" . (int)$order_id . "' ORDER BY `sort_order`");
return $query->rows;
}
/**
* @param int $order_id
*
* @return array
*/
public function getHistories(int $order_id): array {
$query = $this->db->query("SELECT `date_added`, os.`name` AS status, oh.`comment`, oh.`notify` FROM `" . DB_PREFIX . "order_history` oh LEFT JOIN `" . DB_PREFIX . "order_status` os ON oh.`order_status_id` = os.`order_status_id` WHERE oh.`order_id` = '" . (int)$order_id . "' AND os.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY oh.`date_added`");
return $query->rows;
}
/**
* @param int $order_id
*
* @return int
*/
public function getTotalHistories(int $order_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_history` WHERE `order_id` = '" . (int)$order_id . "'");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
/**
* @return int
*/
public function getTotalOrders(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` o WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND o.`order_status_id` > '0' AND o.`store_id` = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
/**
* @param int $product_id
*
* @return int
*/
public function getTotalOrdersByProductId(int $product_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.`order_id` = o.`order_id`) WHERE o.`customer_id` = '" . (int)$this->customer->getId() . "' AND op.`product_id` = '" . (int)$product_id . "'");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
/**
* @param int $order_id
*
* @return int
*/
public function getTotalProductsByOrderId(int $order_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
/**
* @param int $order_id
*
* @return int
*/
public function getTotalVouchersByOrderId(int $order_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_voucher` WHERE `order_id` = '" . (int)$order_id . "'");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class PaymentMethod
*
* @package Opencart\Catalog\Model\Account
*/
class PaymentMethod extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return void
*/
public function addPaymentMethod(array $data): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_payment` SET
`customer_id` = '" . (int)$this->customer->getId() . "',
`name` = '" . (int)$this->customer->getId() . "',
`image` = '" . $this->db->escape($data['image']) . "',
`type` = '" . $this->db->escape($data['type']) . "',
`extension` = '" . $this->db->escape($data['extension']) . "',
`code` = '" . $this->db->escape($data['code']) . "',
`token` = '" . $this->db->escape($data['token']) . "',
`date_expire` = '" . $this->db->escape($data['date_expire']) . "', `default` = '" . (bool)$data['default'] . "', `status` = '1', `date_added` = NOW()");
}
/**
* @param int $customer_payment_id
*
* @return void
*/
public function deletePaymentMethod(int $customer_payment_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_payment` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `customer_payment_id` = '" . (int)$customer_payment_id . "'");
}
/**
* @param int $customer_id
* @param int $customer_payment_id
*
* @return array
*/
public function getPaymentMethod(int $customer_id, int $customer_payment_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_payment` WHERE `customer_id` = '" . (int)$customer_id . "' AND `customer_payment_id` = '" . (int)$customer_payment_id . "'");
return $query->row;
}
/**
* @param int $customer_id
*
* @return array
*/
public function getPaymentMethods(int $customer_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_payment` WHERE `customer_id` = '" . (int)$customer_id . "'");
return $query->rows;
}
/**
* @return int
*/
public function getTotalPaymentMethods(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_payment` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'");
return (int)$query->row['total'];
}
}

View File

@ -0,0 +1,70 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Returns
*
* @package Opencart\Catalog\Model\Account
*/
class Returns extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return int
*/
public function addReturn(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "return` SET `order_id` = '" . (int)$data['order_id'] . "', `product_id` = '" . (int)$data['product_id'] . "', `customer_id` = '" . (int)$this->customer->getId() . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `product` = '" . $this->db->escape((string)$data['product']) . "', `model` = '" . $this->db->escape((string)$data['model']) . "', `quantity` = '" . (int)$data['quantity'] . "', `opened` = '" . (int)$data['opened'] . "', `return_reason_id` = '" . (int)$data['return_reason_id'] . "', `return_status_id` = '" . (int)$this->config->get('config_return_status_id') . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "', `date_ordered` = '" . $this->db->escape((string)$data['date_ordered']) . "', `date_added` = NOW(), `date_modified` = NOW()");
return $this->db->getLastId();
}
/**
* @param int $return_id
*
* @return array
*/
public function getReturn(int $return_id): array {
$query = $this->db->query("SELECT r.`return_id`, r.`order_id`, r.`firstname`, r.`lastname`, r.`email`, r.`telephone`, r.`product`, r.`model`, r.`quantity`, r.`opened`, (SELECT rr.`name` FROM `" . DB_PREFIX . "return_reason` rr WHERE rr.`return_reason_id` = r.`return_reason_id` AND rr.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS reason, (SELECT ra.`name` FROM `" . DB_PREFIX . "return_action` ra WHERE ra.`return_action_id` = r.`return_action_id` AND ra.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS action, (SELECT rs.`name` FROM `" . DB_PREFIX . "return_status` rs WHERE rs.`return_status_id` = r.`return_status_id` AND rs.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS status, r.`comment`, r.`date_ordered`, r.`date_added`, r.`date_modified` FROM `" . DB_PREFIX . "return` r WHERE r.`return_id` = '" . (int)$return_id . "' AND r.`customer_id` = '" . $this->customer->getId() . "'");
return $query->row;
}
/**
* @param int $start
* @param int $limit
*
* @return array
*/
public function getReturns(int $start = 0, int $limit = 20): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 20;
}
$query = $this->db->query("SELECT r.`return_id`, r.`order_id`, r.`firstname`, r.`lastname`, rs.`name` AS status, r.`date_added` FROM `" . DB_PREFIX . "return` r LEFT JOIN `" . DB_PREFIX . "return_status` rs ON (r.`return_status_id` = rs.`return_status_id`) WHERE r.`customer_id` = '" . (int)$this->customer->getId() . "' AND rs.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY r.`return_id` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @return int
*/
public function getTotalReturns(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return` WHERE `customer_id` = '" . $this->customer->getId() . "'");
return (int)$query->row['total'];
}
/**
* @param int $return_id
*
* @return array
*/
public function getHistories(int $return_id): array {
$query = $this->db->query("SELECT rh.`date_added`, rs.`name` AS status, rh.`comment` FROM `" . DB_PREFIX . "return_history` rh LEFT JOIN `" . DB_PREFIX . "return_status` rs ON (rh.`return_status_id` = rs.`return_status_id`) WHERE rh.`return_id` = '" . (int)$return_id . "' AND rs.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY rh.`date_added` ASC");
return $query->rows;
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Reward
*
* @package Opencart\Catalog\Model\Account
*/
class Reward extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return array
*/
public function getRewards(array $data = []): array {
$sql = "SELECT * FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'";
$sort_data = [
'points',
'description',
'date_added'
];
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY `" . $data['sort'] . "`";
} else {
$sql .= " ORDER BY `date_added`";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql);
return $query->rows;
}
/**
* @return int
*/
public function getTotalRewards(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'");
return (int)$query->row['total'];
}
/**
* @return int
*/
public function getTotalPoints(): int {
$query = $this->db->query("SELECT SUM(`points`) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' GROUP BY `customer_id`");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Search
*
* @package Opencart\Catalog\Model\Account
*/
class Search extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return void
*/
public function addSearch(array $data): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_search` SET `store_id` = '" . (int)$this->config->get('config_store_id') . "', `language_id` = '" . (int)$this->config->get('config_language_id') . "', `customer_id` = '" . (int)$data['customer_id'] . "', `keyword` = '" . $this->db->escape((string)$data['keyword']) . "', `category_id` = '" . (int)$data['category_id'] . "', `sub_category` = '" . (int)$data['sub_category'] . "', `description` = '" . (int)$data['description'] . "', `products` = '" . (int)$data['products'] . "', `ip` = '" . $this->db->escape((string)$data['ip']) . "', `date_added` = NOW()");
}
}

View File

@ -0,0 +1,136 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Subscription
*
* @package Opencart\Catalog\Model\Account
*/
class Subscription extends \Opencart\System\Engine\Model {
/**
* @param int $subscription_id
*
* @return array
*/
public function getSubscription(int $subscription_id): array {
$subscription_data = [];
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` `s` WHERE `subscription_id` = '" . (int)$subscription_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
if ($query->num_rows) {
$subscription_data = $query->row;
$subscription_data['payment_method'] = ($query->row['payment_method'] ? json_decode($query->row['payment_method'], true) : '');
$subscription_data['shipping_method'] = ($query->row['shipping_method'] ? json_decode($query->row['shipping_method'], true) : '');
}
return $subscription_data;
}
/**
* @param int $order_id
* @param int $order_product_id
*
* @return array
*/
public function getSubscriptionByOrderProductId(int $order_id, int $order_product_id): array {
$subscription_data = [];
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
if ($query->num_rows) {
$subscription_data = $query->row;
$subscription_data['payment_method'] = ($query->row['payment_method'] ? json_decode($query->row['payment_method'], true) : '');
$subscription_data['shipping_method'] = ($query->row['shipping_method'] ? json_decode($query->row['shipping_method'], true) : '');
}
return $subscription_data;
}
/**
* @param int $start
* @param int $limit
*
* @return array
*/
public function getSubscriptions(int $start = 0, int $limit = 20): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 1;
}
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `subscription_status_id` > '0' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "' ORDER BY `subscription_id` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @return int
*/
public function getTotalSubscriptions(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `subscription_status_id` > '0' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
/**
* @param int $address_id
*
* @return int
*/
public function getTotalSubscriptionByShippingAddressId(int $address_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `shipping_address_id` = '" . (int)$address_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $address_id
*
* @return int
*/
public function getTotalSubscriptionByPaymentAddressId(int $address_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `payment_address_id` = '" . (int)$address_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $subscription_id
* @param int $start
* @param int $limit
*
* @return array
*/
public function getHistories(int $subscription_id, int $start = 0, int $limit = 10): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 10;
}
$query = $this->db->query("SELECT sh.`date_added`, ss.`name` AS status, sh.`comment`, sh.`notify` FROM `" . DB_PREFIX . "subscription_history` `sh` LEFT JOIN `" . DB_PREFIX . "subscription_status` `ss` ON `sh`.`subscription_status_id` = ss.`subscription_status_id` WHERE sh.`subscription_id` = '" . (int)$subscription_id . "' AND ss.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY sh.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @param int $subscription_id
*
* @return int
*/
public function getTotalHistories(int $subscription_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_history` WHERE `subscription_id` = '" . (int)$subscription_id . "'");
return (int)$query->row['total'];
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Transaction
*
* @package Opencart\Catalog\Model\Account
*/
class Transaction extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return array
*/
public function getTransactions(array $data = []): array {
$sql = "SELECT * FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'";
$sort_data = [
'amount',
'description',
'date_added'
];
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY `" . $data['sort'] . "`";
} else {
$sql .= " ORDER BY `date_added`";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql);
return $query->rows;
}
/**
* @return int
*/
public function getTotalTransactions(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'");
return (int)$query->row['total'];
}
/**
* @return int
*/
public function getTotalAmount(): int {
$query = $this->db->query("SELECT SUM(`amount`) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' GROUP BY `customer_id`");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Opencart\Catalog\Model\Account;
/**
* Class Wishlist
*
* @package Opencart\Catalog\Model\Account
*/
class Wishlist extends \Opencart\System\Engine\Model {
/**
* @param int $product_id
*
* @return void
*/
public function addWishlist(int $product_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `product_id` = '" . (int)$product_id . "'");
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_wishlist` SET `customer_id` = '" . (int)$this->customer->getId() . "', `product_id` = '" . (int)$product_id . "', `date_added` = NOW()");
}
/**
* @param int $product_id
*
* @return void
*/
public function deleteWishlist(int $product_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `product_id` = '" . (int)$product_id . "'");
}
/**
* @return array
*/
public function getWishlist(): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'");
return $query->rows;
}
/**
* @return int
*/
public function getTotalWishlist(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'");
return (int)$query->row['total'];
}
}