first commit
This commit is contained in:
24
catalog/model/account/activity.php
Normal file
24
catalog/model/account/activity.php
Normal 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()");
|
||||
}
|
||||
}
|
144
catalog/model/account/address.php
Normal file
144
catalog/model/account/address.php
Normal 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'];
|
||||
}
|
||||
}
|
65
catalog/model/account/affiliate.php
Normal file
65
catalog/model/account/affiliate.php
Normal 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()");
|
||||
}
|
||||
}
|
44
catalog/model/account/api.php
Normal file
44
catalog/model/account/api.php
Normal 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;
|
||||
}
|
||||
}
|
63
catalog/model/account/custom_field.php
Normal file
63
catalog/model/account/custom_field.php
Normal 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;
|
||||
}
|
||||
}
|
284
catalog/model/account/customer.php
Normal file
284
catalog/model/account/customer.php
Normal 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)) . "'");
|
||||
}
|
||||
}
|
28
catalog/model/account/customer_group.php
Normal file
28
catalog/model/account/customer_group.php
Normal 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;
|
||||
}
|
||||
}
|
95
catalog/model/account/download.php
Normal file
95
catalog/model/account/download.php
Normal 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()");
|
||||
}
|
||||
}
|
71
catalog/model/account/gdpr.php
Normal file
71
catalog/model/account/gdpr.php
Normal 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;
|
||||
}
|
||||
}
|
318
catalog/model/account/order.php
Normal file
318
catalog/model/account/order.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
66
catalog/model/account/payment_method.php
Normal file
66
catalog/model/account/payment_method.php
Normal 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'];
|
||||
}
|
||||
}
|
70
catalog/model/account/returns.php
Normal file
70
catalog/model/account/returns.php
Normal 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;
|
||||
}
|
||||
}
|
73
catalog/model/account/reward.php
Normal file
73
catalog/model/account/reward.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
17
catalog/model/account/search.php
Normal file
17
catalog/model/account/search.php
Normal 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()");
|
||||
}
|
||||
}
|
136
catalog/model/account/subscription.php
Normal file
136
catalog/model/account/subscription.php
Normal 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'];
|
||||
}
|
||||
}
|
73
catalog/model/account/transaction.php
Normal file
73
catalog/model/account/transaction.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
46
catalog/model/account/wishlist.php
Normal file
46
catalog/model/account/wishlist.php
Normal 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'];
|
||||
}
|
||||
}
|
89
catalog/model/catalog/category.php
Normal file
89
catalog/model/catalog/category.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Catalog;
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Catalog
|
||||
*/
|
||||
class Category extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategory(int $category_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "category` c LEFT JOIN `" . DB_PREFIX . "category_description` cd ON (c.`category_id` = cd.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_to_store` c2s ON (c.`category_id` = c2s.`category_id`) WHERE c.`category_id` = '" . (int)$category_id . "' AND cd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND c2s.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND c.`status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $parent_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategories(int $parent_id = 0): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category` c LEFT JOIN `" . DB_PREFIX . "category_description` cd ON (c.`category_id` = cd.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_to_store` c2s ON (c.`category_id` = c2s.`category_id`) WHERE c.`parent_id` = '" . (int)$parent_id . "' AND cd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND c2s.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND c.`status` = '1' ORDER BY c.`sort_order`, LCASE(cd.`name`)");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters(int $category_id): array {
|
||||
$implode = [];
|
||||
|
||||
$query = $this->db->query("SELECT `filter_id` FROM `" . DB_PREFIX . "category_filter` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$implode[] = (int)$result['filter_id'];
|
||||
}
|
||||
|
||||
$filter_group_data = [];
|
||||
|
||||
if ($implode) {
|
||||
$filter_group_query = $this->db->query("SELECT DISTINCT f.`filter_group_id`, fgd.`name`, fg.`sort_order` FROM `" . DB_PREFIX . "filter` f LEFT JOIN `" . DB_PREFIX . "filter_group` fg ON (f.`filter_group_id` = fg.`filter_group_id`) LEFT JOIN `" . DB_PREFIX . "filter_group_description` fgd ON (fg.`filter_group_id` = fgd.`filter_group_id`) WHERE f.`filter_id` IN (" . implode(',', $implode) . ") AND fgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' GROUP BY f.`filter_group_id` ORDER BY fg.`sort_order`, LCASE(fgd.`name`)");
|
||||
|
||||
foreach ($filter_group_query->rows as $filter_group) {
|
||||
$filter_data = [];
|
||||
|
||||
$filter_query = $this->db->query("SELECT DISTINCT f.`filter_id`, fd.`name` FROM `" . DB_PREFIX . "filter` f LEFT JOIN `" . DB_PREFIX . "filter_description` fd ON (f.`filter_id` = fd.`filter_id`) WHERE f.`filter_id` IN (" . implode(',', $implode) . ") AND f.`filter_group_id` = '" . (int)$filter_group['filter_group_id'] . "' AND fd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY f.`sort_order`, LCASE(fd.`name`)");
|
||||
|
||||
foreach ($filter_query->rows as $filter) {
|
||||
$filter_data[] = [
|
||||
'filter_id' => $filter['filter_id'],
|
||||
'name' => $filter['name']
|
||||
];
|
||||
}
|
||||
|
||||
if ($filter_data) {
|
||||
$filter_group_data[] = [
|
||||
'filter_group_id' => $filter_group['filter_group_id'],
|
||||
'name' => $filter_group['name'],
|
||||
'filter' => $filter_data
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $filter_group_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $category_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLayoutId($category_id): int {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_to_layout` WHERE `category_id` = '" . (int)$category_id . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['layout_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
43
catalog/model/catalog/information.php
Normal file
43
catalog/model/catalog/information.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Catalog;
|
||||
/**
|
||||
* Class Information
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Catalog
|
||||
*/
|
||||
class Information extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInformation(int $information_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "information` i LEFT JOIN `" . DB_PREFIX . "information_description` id ON (i.`information_id` = id.`information_id`) LEFT JOIN `" . DB_PREFIX . "information_to_store` i2s ON (i.`information_id` = i2s.`information_id`) WHERE i.`information_id` = '" . (int)$information_id . "' AND id.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND i2s.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND i.`status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getInformations(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information` i LEFT JOIN `" . DB_PREFIX . "information_description` id ON (i.`information_id` = id.`information_id`) LEFT JOIN `" . DB_PREFIX . "information_to_store` i2s ON (i.`information_id` = i2s.`information_id`) WHERE id.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND i2s.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND i.`status` = '1' ORDER BY i.`sort_order`, LCASE(id.`title`) ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLayoutId(int $information_id): int {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_to_layout` WHERE `information_id` = '" . (int)$information_id . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['layout_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
84
catalog/model/catalog/manufacturer.php
Normal file
84
catalog/model/catalog/manufacturer.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Catalog;
|
||||
/**
|
||||
* Class Manufacturer
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Catalog
|
||||
*/
|
||||
class Manufacturer extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getManufacturer(int $manufacturer_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "manufacturer` m LEFT JOIN `" . DB_PREFIX . "manufacturer_to_store` m2s ON (m.`manufacturer_id` = m2s.`manufacturer_id`) WHERE m.`manufacturer_id` = '" . (int)$manufacturer_id . "' AND m2s.`store_id` = '" . (int)$this->config->get('config_store_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getManufacturers(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "manufacturer` m LEFT JOIN `" . DB_PREFIX . "manufacturer_to_store` m2s ON (m.`manufacturer_id` = m2s.`manufacturer_id`) WHERE m2s.`store_id` = '" . (int)$this->config->get('config_store_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY `" . $data['sort'] . "`";
|
||||
} else {
|
||||
$sql .= " ORDER BY `name`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$manufacturer_data = $this->cache->get('manufacturer.' . md5($sql));
|
||||
|
||||
if (!$manufacturer_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$manufacturer_data = $query->rows;
|
||||
|
||||
$this->cache->set('manufacturer.' . md5($sql), $manufacturer_data);
|
||||
}
|
||||
|
||||
return $manufacturer_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLayoutId(int $manufacturer_id): int {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "manufacturer_to_layout` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['layout_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
572
catalog/model/catalog/product.php
Normal file
572
catalog/model/catalog/product.php
Normal file
@ -0,0 +1,572 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Catalog;
|
||||
/**
|
||||
* Class Product
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Catalog
|
||||
*/
|
||||
class Product extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $statement = [];
|
||||
|
||||
/**
|
||||
* @param \Opencart\System\Engine\Registry $registry
|
||||
*/
|
||||
public function __construct(\Opencart\System\Engine\Registry $registry) {
|
||||
$this->registry = $registry;
|
||||
|
||||
// Storing some sub queries so that we are not typing them out multiple times.
|
||||
$this->statement['discount'] = "(SELECT `pd2`.`price` FROM `" . DB_PREFIX . "product_discount` `pd2` WHERE `pd2`.`product_id` = `p`.`product_id` AND `pd2`.`customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "'AND `pd2`.`quantity` = '1' AND ((`pd2`.`date_start` = '0000-00-00' OR `pd2`.`date_start` < NOW()) AND (`pd2`.`date_end` = '0000-00-00' OR `pd2`.`date_end` > NOW())) ORDER BY `pd2`.`priority` ASC, `pd2`.`price` ASC LIMIT 1) AS `discount`";
|
||||
$this->statement['special'] = "(SELECT `ps`.`price` FROM `" . DB_PREFIX . "product_special` `ps` WHERE `ps`.`product_id` = `p`.`product_id` AND `ps`.`customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((`ps`.`date_start` = '0000-00-00' OR `ps`.`date_start` < NOW()) AND (`ps`.`date_end` = '0000-00-00' OR `ps`.`date_end` > NOW())) ORDER BY `ps`.`priority` ASC, `ps`.`price` ASC LIMIT 1) AS `special`";
|
||||
$this->statement['reward'] = "(SELECT `pr`.`points` FROM `" . DB_PREFIX . "product_reward` `pr` WHERE `pr`.`product_id` = `p`.`product_id` AND `pr`.`customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "') AS `reward`";
|
||||
$this->statement['review'] = "(SELECT COUNT(*) FROM `" . DB_PREFIX . "review` `r` WHERE `r`.`product_id` = `p`.`product_id` AND `r`.`status` = '1' GROUP BY `r`.`product_id`) AS `reviews`";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProduct(int $product_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT *, pd.`name`, `p`.`image`, " . $this->statement['discount'] . ", " . $this->statement['special'] . ", " . $this->statement['reward'] . ", " . $this->statement['review'] . " FROM `" . DB_PREFIX . "product_to_store` `p2s` LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `p2s`.`product_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW()) LEFT JOIN `" . DB_PREFIX . "product_description` `pd` ON (`p`.`product_id` = `pd`.`product_id`) WHERE `p2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `p2s`.`product_id` = '" . (int)$product_id . "' AND `pd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$product_data = $query->row;
|
||||
|
||||
$product_data['variant'] = (array)json_decode($query->row['variant'], true);
|
||||
$product_data['override'] = (array)json_decode($query->row['override'], true);
|
||||
$product_data['price'] = (float)($query->row['discount'] ? $query->row['discount'] : $query->row['price']);
|
||||
$product_data['rating'] = (int)$query->row['rating'];
|
||||
$product_data['reviews'] = (int)$query->row['reviews'] ? $query->row['reviews'] : 0;
|
||||
|
||||
return $product_data;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProducts(array $data = []): array {
|
||||
$sql = "SELECT DISTINCT *, pd.`name`, `p`.`image`, " . $this->statement['discount'] . ", " . $this->statement['special'] . ", " . $this->statement['reward'] . ", " . $this->statement['review'];
|
||||
|
||||
if (!empty($data['filter_category_id'])) {
|
||||
$sql .= " FROM `" . DB_PREFIX . "category_to_store` `c2s`";
|
||||
|
||||
if (!empty($data['filter_sub_category'])) {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "category_path` `cp` ON (`cp`.`category_id` = `c2s`.`category_id` AND `c2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "') LEFT JOIN `" . DB_PREFIX . "product_to_category` `p2c` ON (`p2c`.`category_id` = `cp`.`category_id`)";
|
||||
} else {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_to_category` `p2c` ON (`p2c`.`category_id` = `c2s`.`category_id` AND `c2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "')";
|
||||
}
|
||||
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_to_store` `p2s` ON (`p2s`.`product_id` = `p2c`.`product_id` AND `p2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "')";
|
||||
|
||||
if (!empty($data['filter_filter'])) {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_filter` `pf` ON (`pf`.`product_id` = `p2s`.`product_id`) LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `pf`.`product_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW())";
|
||||
} else {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `p2s`.`product_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW())";
|
||||
}
|
||||
} else {
|
||||
$sql .= " FROM `" . DB_PREFIX . "product_to_store` `p2s` LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `p2s`.`product_id` AND `p`.`status` = '1' AND `p2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `p`.`date_available` <= NOW())";
|
||||
}
|
||||
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_description` `pd` ON (`p`.`product_id` = `pd`.`product_id`) WHERE `pd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_category_id'])) {
|
||||
if (!empty($data['filter_sub_category'])) {
|
||||
$sql .= " AND `cp`.`path_id` = '" . (int)$data['filter_category_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND `p2c`.`category_id` = '" . (int)$data['filter_category_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_filter'])) {
|
||||
$implode = [];
|
||||
|
||||
$filters = explode(',', $data['filter_filter']);
|
||||
|
||||
foreach ($filters as $filter_id) {
|
||||
$implode[] = (int)$filter_id;
|
||||
}
|
||||
|
||||
$sql .= " AND `pf`.`filter_id` IN (" . implode(',', $implode) . ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['filter_search']) || !empty($data['filter_tag'])) {
|
||||
$sql .= " AND (";
|
||||
|
||||
if (!empty($data['filter_search'])) {
|
||||
$implode = [];
|
||||
|
||||
$words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search'])));
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`pd`.`name` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_description'])) {
|
||||
$sql .= " OR `pd`.`description` LIKE '" . $this->db->escape('%' . (string)$data['filter_search'] . '%') . "'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['filter_search']) && !empty($data['filter_tag'])) {
|
||||
$sql .= " OR ";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_tag'])) {
|
||||
$implode = [];
|
||||
|
||||
$words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_tag'])));
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`pd`.`tag` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['filter_search'])) {
|
||||
$sql .= " OR LCASE(`p`.`model`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`sku`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`upc`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`ean`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`jan`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`isbn`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`mpn`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
}
|
||||
|
||||
$sql .= ")";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_manufacturer_id'])) {
|
||||
$sql .= " AND `p`.`manufacturer_id` = '" . (int)$data['filter_manufacturer_id'] . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'pd.name',
|
||||
'p.model',
|
||||
'p.quantity',
|
||||
'p.price',
|
||||
'rating',
|
||||
'p.sort_order',
|
||||
'p.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
|
||||
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
|
||||
} elseif ($data['sort'] == 'p.price') {
|
||||
$sql .= " ORDER BY (CASE WHEN `special` IS NOT NULL THEN `special` WHEN `discount` IS NOT NULL THEN `discount` ELSE p.`price` END)";
|
||||
} else {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
}
|
||||
} else {
|
||||
$sql .= " ORDER BY p.`sort_order`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC, LCASE(`pd`.`name`) DESC";
|
||||
} else {
|
||||
$sql .= " ASC, LCASE(`pd`.`name`) 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'];
|
||||
}
|
||||
|
||||
$product_data = (array)$this->cache->get('product.' . md5($sql));
|
||||
|
||||
if (!$product_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$product_data = $query->rows;
|
||||
|
||||
$this->cache->set('product.' . md5($sql), $product_data);
|
||||
}
|
||||
|
||||
return $product_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategories(int $product_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_to_category` WHERE `product_id` = '" . (int)$product_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes(int $product_id): array {
|
||||
$product_attribute_group_data = [];
|
||||
|
||||
$product_attribute_group_query = $this->db->query("SELECT ag.`attribute_group_id`, agd.`name` FROM `" . DB_PREFIX . "product_attribute` pa LEFT JOIN `" . DB_PREFIX . "attribute` a ON (pa.`attribute_id` = a.`attribute_id`) LEFT JOIN `" . DB_PREFIX . "attribute_group` ag ON (a.`attribute_group_id` = ag.`attribute_group_id`) LEFT JOIN `" . DB_PREFIX . "attribute_group_description` agd ON (ag.`attribute_group_id` = agd.`attribute_group_id`) WHERE pa.`product_id` = '" . (int)$product_id . "' AND agd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' GROUP BY ag.`attribute_group_id` ORDER BY ag.`sort_order`, agd.`name`");
|
||||
|
||||
foreach ($product_attribute_group_query->rows as $product_attribute_group) {
|
||||
$product_attribute_data = [];
|
||||
|
||||
$product_attribute_query = $this->db->query("SELECT a.`attribute_id`, ad.`name`, pa.`text` FROM `" . DB_PREFIX . "product_attribute` pa LEFT JOIN `" . DB_PREFIX . "attribute` a ON (pa.`attribute_id` = a.`attribute_id`) LEFT JOIN `" . DB_PREFIX . "attribute_description` ad ON (a.`attribute_id` = ad.`attribute_id`) WHERE pa.`product_id` = '" . (int)$product_id . "' AND a.`attribute_group_id` = '" . (int)$product_attribute_group['attribute_group_id'] . "' AND ad.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND pa.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY a.`sort_order`, ad.`name`");
|
||||
|
||||
foreach ($product_attribute_query->rows as $product_attribute) {
|
||||
$product_attribute_data[] = [
|
||||
'attribute_id' => $product_attribute['attribute_id'],
|
||||
'name' => $product_attribute['name'],
|
||||
'text' => $product_attribute['text']
|
||||
];
|
||||
}
|
||||
|
||||
$product_attribute_group_data[] = [
|
||||
'attribute_group_id' => $product_attribute_group['attribute_group_id'],
|
||||
'name' => $product_attribute_group['name'],
|
||||
'attribute' => $product_attribute_data
|
||||
];
|
||||
}
|
||||
|
||||
return $product_attribute_group_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(int $product_id): array {
|
||||
$product_option_data = [];
|
||||
|
||||
$product_option_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_option` `po` LEFT JOIN `" . DB_PREFIX . "option` o ON (po.`option_id` = o.`option_id`) LEFT JOIN `" . DB_PREFIX . "option_description` od ON (o.`option_id` = od.`option_id`) WHERE po.`product_id` = '" . (int)$product_id . "' AND od.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.`sort_order`");
|
||||
|
||||
foreach ($product_option_query->rows as $product_option) {
|
||||
$product_option_value_data = [];
|
||||
|
||||
$product_option_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_option_value` pov LEFT JOIN `" . DB_PREFIX . "option_value` ov ON (pov.`option_value_id` = ov.`option_value_id`) LEFT JOIN `" . DB_PREFIX . "option_value_description` ovd ON (ov.`option_value_id` = ovd.`option_value_id`) WHERE pov.`product_id` = '" . (int)$product_id . "' AND pov.`product_option_id` = '" . (int)$product_option['product_option_id'] . "' AND ovd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.`sort_order`");
|
||||
|
||||
foreach ($product_option_value_query->rows as $product_option_value) {
|
||||
$product_option_value_data[] = [
|
||||
'product_option_value_id' => $product_option_value['product_option_value_id'],
|
||||
'option_value_id' => $product_option_value['option_value_id'],
|
||||
'name' => $product_option_value['name'],
|
||||
'image' => $product_option_value['image'],
|
||||
'quantity' => $product_option_value['quantity'],
|
||||
'subtract' => $product_option_value['subtract'],
|
||||
'price' => $product_option_value['price'],
|
||||
'price_prefix' => $product_option_value['price_prefix'],
|
||||
'weight' => $product_option_value['weight'],
|
||||
'weight_prefix' => $product_option_value['weight_prefix']
|
||||
];
|
||||
}
|
||||
|
||||
$product_option_data[] = [
|
||||
'product_option_id' => $product_option['product_option_id'],
|
||||
'product_option_value' => $product_option_value_data,
|
||||
'option_id' => $product_option['option_id'],
|
||||
'name' => $product_option['name'],
|
||||
'type' => $product_option['type'],
|
||||
'value' => $product_option['value'],
|
||||
'required' => $product_option['required']
|
||||
];
|
||||
}
|
||||
|
||||
return $product_option_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDiscounts(int $product_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_discount` WHERE `product_id` = '" . (int)$product_id . "' AND `customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "' AND `quantity` > 1 AND ((`date_start` = '0000-00-00' OR `date_start` < NOW()) AND (`date_end` = '0000-00-00' OR `date_end` > NOW())) ORDER BY `quantity` ASC, `priority` ASC, `price` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImages(int $product_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_image` WHERE `product_id` = '" . (int)$product_id . "' ORDER BY `sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
* @param int $subscription_plan_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscription(int $product_id, int $subscription_plan_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_subscription` ps LEFT JOIN `" . DB_PREFIX . "subscription_plan` sp ON (ps.`subscription_plan_id` = sp.`subscription_plan_id`) WHERE ps.`product_id` = '" . (int)$product_id . "' AND ps.`subscription_plan_id` = '" . (int)$subscription_plan_id . "' AND ps.`customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "' AND sp.`status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptions(int $product_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_subscription` ps LEFT JOIN `" . DB_PREFIX . "subscription_plan` sp ON (ps.`subscription_plan_id` = sp.`subscription_plan_id`) LEFT JOIN `" . DB_PREFIX . "subscription_plan_description` spd ON (sp.`subscription_plan_id` = spd.`subscription_plan_id`) WHERE ps.`product_id` = '" . (int)$product_id . "' AND ps.`customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "' AND spd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND sp.`status` = '1' ORDER BY sp.`sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLayoutId(int $product_id): int {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_to_layout` WHERE `product_id` = '" . (int)$product_id . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['layout_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRelated(int $product_id): array {
|
||||
$sql = "SELECT DISTINCT *, `pd`.`name` AS name, `p`.`image`, " . $this->statement['discount'] . ", " . $this->statement['special'] . ", " . $this->statement['reward'] . ", " . $this->statement['review'] . " FROM `" . DB_PREFIX . "product_related` `pr` LEFT JOIN `" . DB_PREFIX . "product_to_store` `p2s` ON (`p2s`.`product_id` = `pr`.`product_id` AND `p2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "') LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `pr`.`related_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW()) LEFT JOIN `" . DB_PREFIX . "product_description` `pd` ON (`p`.`product_id` = `pd`.`product_id`) WHERE `pr`.`product_id` = '" . (int)$product_id . "' AND `pd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$product_data = $this->cache->get('product.' . md5($sql));
|
||||
|
||||
if (!$product_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$product_data = $query->rows;
|
||||
|
||||
$this->cache->set('product.' . md5($sql), $product_data);
|
||||
}
|
||||
|
||||
|
||||
return (array)$product_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalProducts(array $data = []): int {
|
||||
$sql = "SELECT COUNT(DISTINCT `p`.`product_id`) AS total";
|
||||
|
||||
if (!empty($data['filter_category_id'])) {
|
||||
$sql .= " FROM `" . DB_PREFIX . "category_to_store` `c2s`";
|
||||
|
||||
if (!empty($data['filter_sub_category'])) {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "category_path` `cp` ON (`cp`.`category_id` = `c2s`.`category_id` AND `c2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "') LEFT JOIN `" . DB_PREFIX . "product_to_category` `p2c` ON (`p2c`.`category_id` = `cp`.`category_id`)";
|
||||
} else {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_to_category` `p2c` ON (`p2c`.`category_id` = `c2s`.`category_id`)";
|
||||
}
|
||||
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_to_store` `p2s` ON (`p2s`.`product_id` = `p2c`.`product_id`)";
|
||||
|
||||
if (!empty($data['filter_filter'])) {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_filter` `pf` ON (`pf`.`product_id` = `p2s`.`product_id`) LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `pf`.`product_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW())";
|
||||
} else {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `p2s`.`product_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW() AND `p2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "')";
|
||||
}
|
||||
} else {
|
||||
$sql .= " FROM `" . DB_PREFIX . "product` `p`";
|
||||
}
|
||||
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "product_description` `pd` ON (`p`.`product_id` = `pd`.`product_id`) WHERE `pd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_category_id'])) {
|
||||
if (!empty($data['filter_sub_category'])) {
|
||||
$sql .= " AND `cp`.`path_id` = '" . (int)$data['filter_category_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND `p2c`.`category_id` = '" . (int)$data['filter_category_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_filter'])) {
|
||||
$implode = [];
|
||||
|
||||
$filters = explode(',', $data['filter_filter']);
|
||||
|
||||
foreach ($filters as $filter_id) {
|
||||
$implode[] = (int)$filter_id;
|
||||
}
|
||||
|
||||
$sql .= " AND `pf`.`filter_id` IN (" . implode(',', $implode) . ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['filter_search']) || !empty($data['filter_tag'])) {
|
||||
$sql .= " AND (";
|
||||
|
||||
if (!empty($data['filter_search'])) {
|
||||
$implode = [];
|
||||
|
||||
$words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search'])));
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`pd`.`name` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_description'])) {
|
||||
$sql .= " OR `pd`.`description` LIKE '" . $this->db->escape('%' . (string)$data['filter_search'] . '%') . "'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['filter_search']) && !empty($data['filter_tag'])) {
|
||||
$sql .= " OR ";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_tag'])) {
|
||||
$implode = [];
|
||||
|
||||
$words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_tag'])));
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`pd`.`tag` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['filter_search'])) {
|
||||
$sql .= " OR LCASE(`p`.`model`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`sku`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`upc`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`ean`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`jan`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`isbn`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
$sql .= " OR LCASE(`p`.`mpn`) = '" . $this->db->escape(oc_strtolower($data['filter_search'])) . "'";
|
||||
}
|
||||
|
||||
$sql .= ")";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_manufacturer_id'])) {
|
||||
$sql .= " AND `p`.`manufacturer_id` = '" . (int)$data['filter_manufacturer_id'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecials(array $data = []): array {
|
||||
$sql = "SELECT DISTINCT *, `pd`.`name`, `p`.`image`, `p`.`price`, " . $this->statement['discount'] . ", " . $this->statement['special'] . ", " . $this->statement['reward'] . ", " . $this->statement['review'] . " FROM `" . DB_PREFIX . "product_special` `ps2` LEFT JOIN `" . DB_PREFIX . "product_to_store` `p2s` ON (`ps2`.`product_id` = `p2s`.`product_id` AND `p2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `ps2`.`customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((`ps2`.`date_start` = '0000-00-00' OR `ps2`.`date_start` < NOW()) AND (`ps2`.`date_end` = '0000-00-00' OR `ps2`.`date_end` > NOW()))) LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `p2s`.`product_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW()) LEFT JOIN `" . DB_PREFIX . "product_description` `pd` ON (`pd`.`product_id` = `p`.`product_id`) WHERE `pd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' GROUP BY `ps2`.`product_id`";
|
||||
|
||||
$sort_data = [
|
||||
'pd.name',
|
||||
'p.model',
|
||||
'p.price',
|
||||
'rating',
|
||||
'p.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
|
||||
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
|
||||
} elseif ($data['sort'] == 'p.price') {
|
||||
$sql .= " ORDER BY (CASE WHEN `special` IS NOT NULL THEN `special` WHEN `discount` IS NOT NULL THEN `discount` ELSE p.`price` END)";
|
||||
} else {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
}
|
||||
} else {
|
||||
$sql .= " ORDER BY p.`sort_order`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC, LCASE(`pd`.`name`) DESC";
|
||||
} else {
|
||||
$sql .= " ASC, LCASE(`pd`.`name`) 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'];
|
||||
}
|
||||
|
||||
$product_data = $this->cache->get('product.' . md5($sql));
|
||||
|
||||
if (!$product_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$product_data = $query->rows;
|
||||
|
||||
$this->cache->set('product.' . md5($sql), $product_data);
|
||||
}
|
||||
|
||||
return (array)$product_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSpecials(): int {
|
||||
$query = $this->db->query("SELECT COUNT(DISTINCT `ps`.`product_id`) AS `total` FROM `" . DB_PREFIX . "product_special` `ps` LEFT JOIN `" . DB_PREFIX . "product_to_store` `p2s` ON (`p2s`.`product_id` = `ps`.`product_id` AND `p2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `ps`.`customer_group_id` = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((`ps`.`date_start` = '0000-00-00' OR `ps`.`date_start` < NOW()) AND (`ps`.`date_end` = '0000-00-00' OR `ps`.`date_end` > NOW()))) LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p2s`.`product_id` = `p`.`product_id` AND `p`.`status` = '1' AND `p`.`date_available` <= NOW())");
|
||||
|
||||
if (isset($query->row['total'])) {
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
* @param string $ip
|
||||
* @param string $country
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReport(int $product_id, string $ip, string $country = ''): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_report` SET `product_id` = '" . (int)$product_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
|
||||
}
|
||||
}
|
52
catalog/model/catalog/review.php
Normal file
52
catalog/model/catalog/review.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Catalog;
|
||||
/**
|
||||
* Class Review
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Catalog
|
||||
*/
|
||||
class Review extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $product_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReview(int $product_id, array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "review` SET `author` = '" . $this->db->escape((string)$data['name']) . "', `customer_id` = '" . (int)$this->customer->getId() . "', `product_id` = '" . (int)$product_id . "', `text` = '" . $this->db->escape((string)$data['text']) . "', `rating` = '" . (int)$data['rating'] . "', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReviewsByProductId(int $product_id, int $start = 0, int $limit = 20): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 20;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT r.`author`, r.`rating`, r.`text`, r.`date_added` FROM `" . DB_PREFIX . "review` r LEFT JOIN `" . DB_PREFIX . "product` p ON (r.`product_id` = p.`product_id`) LEFT JOIN `" . DB_PREFIX . "product_description` pd ON (p.`product_id` = pd.`product_id`) WHERE r.`product_id` = '" . (int)$product_id . "' AND p.`date_available` <= NOW() AND p.`status` = '1' AND r.`status` = '1' AND pd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY r.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReviewsByProductId(int $product_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "review` r LEFT JOIN `" . DB_PREFIX . "product` p ON (r.`product_id` = p.`product_id`) LEFT JOIN `" . DB_PREFIX . "product_description` pd ON (p.`product_id` = pd.`product_id`) WHERE p.`product_id` = '" . (int)$product_id . "' AND p.`date_available` <= NOW() AND p.`status` = '1' AND r.`status` = '1' AND pd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
74
catalog/model/catalog/subscription_plan.php
Normal file
74
catalog/model/catalog/subscription_plan.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Catalog;
|
||||
/**
|
||||
* Class Subscription Plan
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Catalog
|
||||
*/
|
||||
class SubscriptionPlan extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $subscription_plan_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionPlan(int $subscription_plan_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_plan` `sp` LEFT JOIN `" . DB_PREFIX . "subscription_plan_description` `spd` ON (`sp`.`subscription_plan_id` = `spd`.`subscription_plan_id`) WHERE `sp`.`subscription_plan_id` = '" . (int)$subscription_plan_id . "' AND `spd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionPlans(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "subscription_plan` `sp` LEFT JOIN `" . DB_PREFIX . "subscription_plan_description` `spd` ON (`sp`.`subscription_plan_id` = `spd`.`subscription_plan_id`) WHERE `spd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND spd.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'spd.name',
|
||||
'sp.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `spd`.`name`";
|
||||
}
|
||||
|
||||
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 getTotalSubscriptionPlans(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_plan`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
155
catalog/model/checkout/cart.php
Normal file
155
catalog/model/checkout/cart.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Checkout;
|
||||
/**
|
||||
* Class Cart
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Checkout
|
||||
*/
|
||||
class Cart extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getProducts(): array {
|
||||
$this->load->model('tool/image');
|
||||
$this->load->model('tool/upload');
|
||||
|
||||
// Products
|
||||
$product_data = [];
|
||||
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if ($product['image']) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($product['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
|
||||
}
|
||||
|
||||
$option_data = [];
|
||||
|
||||
foreach ($product['option'] 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[] = [
|
||||
'product_option_id' => $option['product_option_id'],
|
||||
'product_option_value_id' => $option['product_option_value_id'],
|
||||
'option_id' => $option['option_id'],
|
||||
'option_value_id' => $option['option_value_id'],
|
||||
'name' => $option['name'],
|
||||
'value' => $value,
|
||||
'type' => $option['type']
|
||||
];
|
||||
}
|
||||
|
||||
$product_total = 0;
|
||||
|
||||
foreach ($products as $product_2) {
|
||||
if ($product_2['product_id'] == $product['product_id']) {
|
||||
$product_total += $product_2['quantity'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($product['minimum'] > $product_total) {
|
||||
$minimum = false;
|
||||
} else {
|
||||
$minimum = true;
|
||||
}
|
||||
|
||||
$product_data[] = [
|
||||
'cart_id' => $product['cart_id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'master_id' => $product['master_id'],
|
||||
'image' => $image,
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'option' => $option_data,
|
||||
'subscription' => $product['subscription'],
|
||||
'download' => $product['download'],
|
||||
'quantity' => $product['quantity'],
|
||||
'stock' => $product['stock'],
|
||||
'minimum' => $minimum,
|
||||
'shipping' => $product['shipping'],
|
||||
'subtract' => $product['subtract'],
|
||||
'reward' => $product['reward'],
|
||||
'tax_class_id' => $product['tax_class_id'],
|
||||
'price' => $product['price'],
|
||||
'total' => $product['total']
|
||||
];
|
||||
}
|
||||
|
||||
return $product_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getVouchers(): array {
|
||||
$voucher_data = [];
|
||||
|
||||
if (!empty($this->session->data['vouchers'])) {
|
||||
foreach ($this->session->data['vouchers'] as $voucher) {
|
||||
$voucher_data[] = [
|
||||
'code' => $voucher['code'],
|
||||
'description' => $voucher['description'],
|
||||
'from_name' => $voucher['from_name'],
|
||||
'from_email' => $voucher['from_email'],
|
||||
'to_name' => $voucher['to_name'],
|
||||
'to_email' => $voucher['to_email'],
|
||||
'voucher_theme_id' => $voucher['voucher_theme_id'],
|
||||
'message' => $voucher['message'],
|
||||
'amount' => $voucher['amount']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $voucher_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param int $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotals(array &$totals, array &$taxes, int &$total): void {
|
||||
$sort_order = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getExtensionsByType('total');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $results);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($this->config->get('total_' . $result['code'] . '_status')) {
|
||||
$this->load->model('extension/' . $result['extension'] . '/total/' . $result['code']);
|
||||
|
||||
// __call magic method cannot pass-by-reference so we get PHP to call it as an anonymous function.
|
||||
($this->{'model_extension_' . $result['extension'] . '_total_' . $result['code']}->getTotal)($totals, $taxes, $total);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($totals as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $totals);
|
||||
}
|
||||
}
|
539
catalog/model/checkout/order.php
Normal file
539
catalog/model/checkout/order.php
Normal file
@ -0,0 +1,539 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Checkout;
|
||||
/**
|
||||
* Class Order
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Checkout
|
||||
*/
|
||||
class Order extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addOrder(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET `invoice_prefix` = '" . $this->db->escape((string)$data['invoice_prefix']) . "', `store_id` = '" . (int)$data['store_id'] . "', `store_name` = '" . $this->db->escape((string)$data['store_name']) . "', `store_url` = '" . $this->db->escape((string)$data['store_url']) . "', `customer_id` = '" . (int)$data['customer_id'] . "', `customer_group_id` = '" . (int)$data['customer_group_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']) : '') . "', `payment_address_id` = '" . (int)$data['payment_address_id'] . "', `payment_firstname` = '" . $this->db->escape((string)$data['payment_firstname']) . "', `payment_lastname` = '" . $this->db->escape((string)$data['payment_lastname']) . "', `payment_company` = '" . $this->db->escape((string)$data['payment_company']) . "', `payment_address_1` = '" . $this->db->escape((string)$data['payment_address_1']) . "', `payment_address_2` = '" . $this->db->escape((string)$data['payment_address_2']) . "', `payment_city` = '" . $this->db->escape((string)$data['payment_city']) . "', `payment_postcode` = '" . $this->db->escape((string)$data['payment_postcode']) . "', `payment_country` = '" . $this->db->escape((string)$data['payment_country']) . "', `payment_country_id` = '" . (int)$data['payment_country_id'] . "', `payment_zone` = '" . $this->db->escape((string)$data['payment_zone']) . "', `payment_zone_id` = '" . (int)$data['payment_zone_id'] . "', `payment_address_format` = '" . $this->db->escape((string)$data['payment_address_format']) . "', `payment_custom_field` = '" . $this->db->escape(isset($data['payment_custom_field']) ? json_encode($data['payment_custom_field']) : '') . "', `payment_method` = '" . $this->db->escape($data['payment_method'] ? json_encode($data['payment_method']) : '') . "', `shipping_address_id` = '" . (int)$data['shipping_address_id'] . "', `shipping_firstname` = '" . $this->db->escape((string)$data['shipping_firstname']) . "', `shipping_lastname` = '" . $this->db->escape((string)$data['shipping_lastname']) . "', `shipping_company` = '" . $this->db->escape((string)$data['shipping_company']) . "', `shipping_address_1` = '" . $this->db->escape((string)$data['shipping_address_1']) . "', `shipping_address_2` = '" . $this->db->escape((string)$data['shipping_address_2']) . "', `shipping_city` = '" . $this->db->escape((string)$data['shipping_city']) . "', `shipping_postcode` = '" . $this->db->escape((string)$data['shipping_postcode']) . "', `shipping_country` = '" . $this->db->escape((string)$data['shipping_country']) . "', `shipping_country_id` = '" . (int)$data['shipping_country_id'] . "', `shipping_zone` = '" . $this->db->escape((string)$data['shipping_zone']) . "', `shipping_zone_id` = '" . (int)$data['shipping_zone_id'] . "', `shipping_address_format` = '" . $this->db->escape((string)$data['shipping_address_format']) . "', `shipping_custom_field` = '" . $this->db->escape(isset($data['shipping_custom_field']) ? json_encode($data['shipping_custom_field']) : '') . "', `shipping_method` = '" . $this->db->escape($data['shipping_method'] ? json_encode($data['shipping_method']) : '') . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "', `total` = '" . (float)$data['total'] . "', `affiliate_id` = '" . (int)$data['affiliate_id'] . "', `commission` = '" . (float)$data['commission'] . "', `marketing_id` = '" . (int)$data['marketing_id'] . "', `tracking` = '" . $this->db->escape((string)$data['tracking']) . "', `language_id` = '" . (int)$data['language_id'] . "', `currency_id` = '" . (int)$data['currency_id'] . "', `currency_code` = '" . $this->db->escape((string)$data['currency_code']) . "', `currency_value` = '" . (float)$data['currency_value'] . "', `ip` = '" . $this->db->escape((string)$data['ip']) . "', `forwarded_ip` = '" . $this->db->escape((string)$data['forwarded_ip']) . "', `user_agent` = '" . $this->db->escape((string)$data['user_agent']) . "', `accept_language` = '" . $this->db->escape((string)$data['accept_language']) . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
$order_id = $this->db->getLastId();
|
||||
|
||||
// Products
|
||||
if (isset($data['products'])) {
|
||||
foreach ($data['products'] as $product) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_product` SET `order_id` = '" . (int)$order_id . "', `product_id` = '" . (int)$product['product_id'] . "', `master_id` = '" . (int)$product['master_id'] . "', `name` = '" . $this->db->escape($product['name']) . "', `model` = '" . $this->db->escape($product['model']) . "', `quantity` = '" . (int)$product['quantity'] . "', `price` = '" . (float)$product['price'] . "', `total` = '" . (float)$product['total'] . "', `tax` = '" . (float)$product['tax'] . "', `reward` = '" . (int)$product['reward'] . "'");
|
||||
|
||||
$order_product_id = $this->db->getLastId();
|
||||
|
||||
foreach ($product['option'] as $option) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_option` SET `order_id` = '" . (int)$order_id . "', `order_product_id` = '" . (int)$order_product_id . "', `product_option_id` = '" . (int)$option['product_option_id'] . "', `product_option_value_id` = '" . (int)$option['product_option_value_id'] . "', `name` = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', `type` = '" . $this->db->escape($option['type']) . "'");
|
||||
}
|
||||
|
||||
// If subscription add details
|
||||
if ($product['subscription']) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_subscription` SET `order_id` = '" . (int)$order_id . "', `order_product_id` = '" . (int)$order_product_id . "', `subscription_plan_id` = '" . (int)$product['subscription']['subscription_plan_id'] . "', `trial_price` = '" . (float)$product['subscription']['trial_price'] . "', `trial_tax` = '" . (float)$product['subscription']['trial_tax'] . "', `trial_frequency` = '" . $this->db->escape($product['subscription']['trial_frequency']) . "', `trial_cycle` = '" . (int)$product['subscription']['trial_cycle'] . "', `trial_duration` = '" . (int)$product['subscription']['trial_duration'] . "', `trial_remaining` = '" . (int)$product['subscription']['trial_remaining'] . "', `trial_status` = '" . (int)$product['subscription']['trial_status'] . "', `price` = '" . (float)$product['subscription']['price'] . "', `tax` = '" . (float)$product['subscription']['tax'] . "', `frequency` = '" . $this->db->escape($product['subscription']['frequency']) . "', `cycle` = '" . (int)$product['subscription']['cycle'] . "', `duration` = '" . (int)$product['subscription']['duration'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Vouchers
|
||||
if (isset($data['vouchers'])) {
|
||||
$this->load->model('checkout/voucher');
|
||||
|
||||
foreach ($data['vouchers'] as $voucher) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_voucher` SET `order_id` = '" . (int)$order_id . "', `description` = '" . $this->db->escape($voucher['description']) . "', `code` = '" . $this->db->escape($voucher['code']) . "', `from_name` = '" . $this->db->escape($voucher['from_name']) . "', `from_email` = '" . $this->db->escape($voucher['from_email']) . "', `to_name` = '" . $this->db->escape($voucher['to_name']) . "', `to_email` = '" . $this->db->escape($voucher['to_email']) . "', `voucher_theme_id` = '" . (int)$voucher['voucher_theme_id'] . "', `message` = '" . $this->db->escape($voucher['message']) . "', `amount` = '" . (float)$voucher['amount'] . "'");
|
||||
|
||||
$order_voucher_id = $this->db->getLastId();
|
||||
|
||||
$voucher_id = $this->model_checkout_voucher->addVoucher($order_id, $voucher);
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order_voucher` SET `voucher_id` = '" . (int)$voucher_id . "' WHERE `order_voucher_id` = '" . (int)$order_voucher_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Totals
|
||||
if (isset($data['totals'])) {
|
||||
foreach ($data['totals'] as $total) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_total` SET `order_id` = '" . (int)$order_id . "', `extension` = '" . $this->db->escape($total['extension']) . "', `code` = '" . $this->db->escape($total['code']) . "', `title` = '" . $this->db->escape($total['title']) . "', `value` = '" . (float)$total['value'] . "', `sort_order` = '" . (int)$total['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $order_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editOrder(int $order_id, array $data): void {
|
||||
// 1. Void the order first
|
||||
$this->addHistory($order_id, 0);
|
||||
|
||||
$order_info = $this->getOrder($order_id);
|
||||
|
||||
if ($order_info) {
|
||||
// 2. Merge the old order data with the new data
|
||||
foreach ($order_info as $key => $value) {
|
||||
if (!isset($data[$key])) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `invoice_prefix` = '" . $this->db->escape((string)$data['invoice_prefix']) . "', `store_id` = '" . (int)$data['store_id'] . "', `store_name` = '" . $this->db->escape((string)$data['store_name']) . "', `store_url` = '" . $this->db->escape((string)$data['store_url']) . "', `customer_id` = '" . (int)$data['customer_id'] . "', `customer_group_id` = '" . (int)$data['customer_group_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(json_encode($data['custom_field'])) . "', `payment_address_id` = '" . (int)$data['payment_address_id'] . "', `payment_firstname` = '" . $this->db->escape((string)$data['payment_firstname']) . "', `payment_lastname` = '" . $this->db->escape((string)$data['payment_lastname']) . "', `payment_company` = '" . $this->db->escape((string)$data['payment_company']) . "', `payment_address_1` = '" . $this->db->escape((string)$data['payment_address_1']) . "', `payment_address_2` = '" . $this->db->escape((string)$data['payment_address_2']) . "', `payment_city` = '" . $this->db->escape((string)$data['payment_city']) . "', `payment_postcode` = '" . $this->db->escape((string)$data['payment_postcode']) . "', `payment_country` = '" . $this->db->escape((string)$data['payment_country']) . "', `payment_country_id` = '" . (int)$data['payment_country_id'] . "', `payment_zone` = '" . $this->db->escape((string)$data['payment_zone']) . "', `payment_zone_id` = '" . (int)$data['payment_zone_id'] . "', `payment_address_format` = '" . $this->db->escape((string)$data['payment_address_format']) . "', `payment_custom_field` = '" . $this->db->escape(isset($data['payment_custom_field']) ? json_encode($data['payment_custom_field']) : '') . "', `payment_method` = '" . $this->db->escape($data['payment_method'] ? json_encode($data['payment_method']) : '') . "', `shipping_address_id` = '" . (int)$data['shipping_address_id'] . "', `shipping_firstname` = '" . $this->db->escape((string)$data['shipping_firstname']) . "', `shipping_lastname` = '" . $this->db->escape((string)$data['shipping_lastname']) . "', `shipping_company` = '" . $this->db->escape((string)$data['shipping_company']) . "', `shipping_address_1` = '" . $this->db->escape((string)$data['shipping_address_1']) . "', `shipping_address_2` = '" . $this->db->escape((string)$data['shipping_address_2']) . "', `shipping_city` = '" . $this->db->escape((string)$data['shipping_city']) . "', `shipping_postcode` = '" . $this->db->escape((string)$data['shipping_postcode']) . "', `shipping_country` = '" . $this->db->escape((string)$data['shipping_country']) . "', `shipping_country_id` = '" . (int)$data['shipping_country_id'] . "', `shipping_zone` = '" . $this->db->escape((string)$data['shipping_zone']) . "', `shipping_zone_id` = '" . (int)$data['shipping_zone_id'] . "', `shipping_address_format` = '" . $this->db->escape((string)$data['shipping_address_format']) . "', `shipping_custom_field` = '" . $this->db->escape(isset($data['shipping_custom_field']) ? json_encode($data['shipping_custom_field']) : '') . "', `shipping_method` = '" . $this->db->escape($data['shipping_method'] ? json_encode($data['shipping_method']) : '') . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "', `total` = '" . (float)$data['total'] . "', `affiliate_id` = '" . (int)$data['affiliate_id'] . "', `commission` = '" . (float)$data['commission'] . "', `date_modified` = NOW() WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_option` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_subscription` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
// Products
|
||||
if (isset($data['products'])) {
|
||||
foreach ($data['products'] as $product) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_product` SET `order_id` = '" . (int)$order_id . "', `product_id` = '" . (int)$product['product_id'] . "', `master_id` = '" . (int)$product['master_id'] . "', `name` = '" . $this->db->escape($product['name']) . "', `model` = '" . $this->db->escape($product['model']) . "', `quantity` = '" . (int)$product['quantity'] . "', `price` = '" . (float)$product['price'] . "', `total` = '" . (float)$product['total'] . "', `tax` = '" . (float)$product['tax'] . "', `reward` = '" . (int)$product['reward'] . "'");
|
||||
|
||||
$order_product_id = $this->db->getLastId();
|
||||
|
||||
foreach ($product['option'] as $option) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_option` SET `order_id` = '" . (int)$order_id . "', `order_product_id` = '" . (int)$order_product_id . "', `product_option_id` = '" . (int)$option['product_option_id'] . "', `product_option_value_id` = '" . (int)$option['product_option_value_id'] . "', `name` = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', `type` = '" . $this->db->escape($option['type']) . "'");
|
||||
}
|
||||
|
||||
if ($product['subscription']) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_subscription` SET `order_id` = '" . (int)$order_id . "', `order_product_id` = '" . (int)$order_product_id . "', `subscription_plan_id` = '" . (int)$product['subscription']['subscription_plan_id'] . "', `trial_price` = '" . (float)$product['subscription']['trial_price'] . "', `trial_tax` = '" . (float)$product['subscription']['trial_tax'] . "', `trial_frequency` = '" . $this->db->escape($product['subscription']['trial_frequency']) . "', `trial_cycle` = '" . (int)$product['subscription']['trial_cycle'] . "', `trial_duration` = '" . (int)$product['subscription']['trial_duration'] . "', `trial_remaining` = '" . (int)$product['subscription']['trial_remaining'] . "', `trial_status` = '" . (int)$product['subscription']['trial_status'] . "', `price` = '" . (float)$product['subscription']['price'] . "', `tax` = '" . (float)$product['subscription']['tax'] . "', `frequency` = '" . $this->db->escape($product['subscription']['frequency']) . "', `cycle` = '" . (int)$product['subscription']['cycle'] . "', `duration` = '" . (int)$product['subscription']['duration'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gift Voucher
|
||||
$this->load->model('checkout/voucher');
|
||||
|
||||
$this->model_checkout_voucher->deleteVoucherByOrderId($order_id);
|
||||
|
||||
// Vouchers
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_voucher` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
if (isset($data['vouchers'])) {
|
||||
foreach ($data['vouchers'] as $voucher) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_voucher` SET `order_id` = '" . (int)$order_id . "', `description` = '" . $this->db->escape($voucher['description']) . "', `code` = '" . $this->db->escape($voucher['code']) . "', `from_name` = '" . $this->db->escape($voucher['from_name']) . "', `from_email` = '" . $this->db->escape($voucher['from_email']) . "', `to_name` = '" . $this->db->escape($voucher['to_name']) . "', `to_email` = '" . $this->db->escape($voucher['to_email']) . "', `voucher_theme_id` = '" . (int)$voucher['voucher_theme_id'] . "', `message` = '" . $this->db->escape($voucher['message']) . "', `amount` = '" . (float)$voucher['amount'] . "'");
|
||||
|
||||
$order_voucher_id = $this->db->getLastId();
|
||||
|
||||
$voucher_id = $this->model_checkout_voucher->addVoucher($order_id, $voucher);
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order_voucher` SET `voucher_id` = '" . (int)$voucher_id . "' WHERE `order_voucher_id` = '" . (int)$order_voucher_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Totals
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_total` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
if (isset($data['totals'])) {
|
||||
foreach ($data['totals'] as $total) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_total` SET `order_id` = '" . (int)$order_id . "', `extension` = '" . $this->db->escape($total['extension']) . "', `code` = '" . $this->db->escape($total['code']) . "', `title` = '" . $this->db->escape($total['title']) . "', `value` = '" . (float)$total['value'] . "', `sort_order` = '" . (int)$total['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param string $transaction_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTransactionId(int $order_id, string $transaction_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `transaction_id` = '" . $this->db->escape($transaction_id) . "' WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param string $comment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editComment(int $order_id, string $comment): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `comment` = '" . $this->db->escape($comment) . "' WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteOrder(int $order_id): void {
|
||||
// Void the order first
|
||||
$this->addHistory($order_id, 0);
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_option` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_subscription` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_voucher` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_total` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_history` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
// Gift Voucher
|
||||
$this->load->model('checkout/voucher');
|
||||
|
||||
$this->model_checkout_voucher->deleteVoucherByOrderId($order_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrder(int $order_id): array {
|
||||
$order_query = $this->db->query("SELECT *, (SELECT `os`.`name` FROM `" . DB_PREFIX . "order_status` `os` WHERE `os`.`order_status_id` = `o`.`order_status_id` AND `os`.`language_id` = `o`.`language_id`) AS order_status FROM `" . DB_PREFIX . "order` `o` WHERE `o`.`order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
if ($order_query->num_rows) {
|
||||
$order_data = $order_query->row;
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$order_data['custom_field'] = json_decode($order_query->row['custom_field'], true);
|
||||
|
||||
foreach (['payment', 'shipping'] as $column) {
|
||||
$country_info = $this->model_localisation_country->getCountry($order_query->row[$column . '_country_id']);
|
||||
|
||||
if ($country_info) {
|
||||
$order_data[$column . '_iso_code_2'] = $country_info['iso_code_2'];
|
||||
$order_data[$column . '_iso_code_3'] = $country_info['iso_code_3'];
|
||||
} else {
|
||||
$order_data[$column . '_iso_code_2'] = '';
|
||||
$order_data[$column . '_iso_code_3'] = '';
|
||||
}
|
||||
|
||||
$zone_info = $this->model_localisation_zone->getZone($order_query->row[$column . '_zone_id']);
|
||||
|
||||
if ($zone_info) {
|
||||
$order_data[$column . '_zone_code'] = $zone_info['code'];
|
||||
} else {
|
||||
$order_data[$column . '_zone_code'] = '';
|
||||
}
|
||||
|
||||
$order_data[$column . '_custom_field'] = json_decode($order_query->row[$column . '_custom_field'], true);
|
||||
|
||||
$order_data[$column . '_custom_field'] = json_decode($order_query->row[$column . '_custom_field'], true);
|
||||
|
||||
// Payment and shipping method details
|
||||
$order_data[$column . '_method'] = json_decode($order_query->row[$column . '_method'], true);
|
||||
}
|
||||
|
||||
return $order_data;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptions(array $data): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "subscription`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_date_next'])) {
|
||||
$implode[] = "DATE(`date_next`) <= DATE('" . $this->db->escape($data['filter_date_next']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_subscription_status_id'])) {
|
||||
$implode[] = "`subscription_status_id` = '" . (int)$data['filter_subscription_status_id'] . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'pd.name',
|
||||
'p.model',
|
||||
'p.price',
|
||||
'p.quantity',
|
||||
'p.status',
|
||||
'p.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY o.`order_id`";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $order_status_id
|
||||
* @param string $comment
|
||||
* @param bool $notify
|
||||
* @param bool $override
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory(int $order_id, int $order_status_id, string $comment = '', bool $notify = false, bool $override = false): void {
|
||||
$order_info = $this->getOrder($order_id);
|
||||
|
||||
if ($order_info) {
|
||||
// Load subscription model
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$customer_info = $this->model_account_customer->getCustomer($order_info['customer_id']);
|
||||
|
||||
// Fraud Detection Enable / Disable
|
||||
if ($customer_info && $customer_info['safe']) {
|
||||
$safe = true;
|
||||
} else {
|
||||
$safe = false;
|
||||
}
|
||||
|
||||
// Only do the fraud check if the customer is not on the safe list and the order status is changing into the complete or process order status
|
||||
if (!$safe && !$override && in_array($order_status_id, array_merge((array)$this->config->get('config_processing_status'), (array)$this->config->get('config_complete_status')))) {
|
||||
// Anti-Fraud
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('fraud');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if ($this->config->get('fraud_' . $extension['code'] . '_status')) {
|
||||
$this->load->model('extension/' . $extension['extension'] . '/fraud/' . $extension['code']);
|
||||
|
||||
if (isset($this->{'model_extension_' . $extension['extension'] . '_fraud_' . $extension['code']}->check)) {
|
||||
$fraud_status_id = $this->{'model_extension_' . $extension['extension'] . '_fraud_' . $extension['code']}->check($order_info);
|
||||
|
||||
if ($fraud_status_id) {
|
||||
$order_status_id = $fraud_status_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Products
|
||||
$order_products = $this->getProducts($order_id);
|
||||
|
||||
// Totals
|
||||
$order_totals = $this->getTotals($order_id);
|
||||
|
||||
// If current order status is not processing or complete but new status is processing or complete then commence completing the order
|
||||
if (!in_array($order_info['order_status_id'], array_merge((array)$this->config->get('config_processing_status'), (array)$this->config->get('config_complete_status'))) && in_array($order_status_id, array_merge((array)$this->config->get('config_processing_status'), (array)$this->config->get('config_complete_status')))) {
|
||||
// Redeem coupon, vouchers and reward points
|
||||
foreach ($order_totals as $order_total) {
|
||||
$this->load->model('extension/' . $order_total['extension'] . '/total/' . $order_total['code']);
|
||||
|
||||
if (isset($this->{'model_extension_' . $order_total['extension'] . '_total_' . $order_total['code']}->confirm)) {
|
||||
// Confirm coupon, vouchers and reward points
|
||||
$fraud_status_id = $this->{'model_extension_' . $order_total['extension'] . '_total_' . $order_total['code']}->confirm($order_info, $order_total);
|
||||
|
||||
// If the balance on the coupon, vouchers and reward points is not enough to cover the transaction or has already been used then the fraud order status is returned.
|
||||
if ($fraud_status_id) {
|
||||
$order_status_id = $fraud_status_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($order_products as $order_product) {
|
||||
// Stock subtraction
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "product` SET `quantity` = (`quantity` - " . (int)$order_product['quantity'] . ") WHERE `product_id` = '" . (int)$order_product['product_id'] . "' AND `subtract` = '1'");
|
||||
|
||||
// Stock subtraction from master product
|
||||
if ($order_product['master_id']) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "product` SET `quantity` = (`quantity` - " . (int)$order_product['quantity'] . ") WHERE `product_id` = '" . (int)$order_product['master_id'] . "' AND `subtract` = '1'");
|
||||
}
|
||||
|
||||
$order_options = $this->getOptions($order_id, $order_product['order_product_id']);
|
||||
|
||||
foreach ($order_options as $order_option) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "product_option_value` SET `quantity` = (`quantity` - " . (int)$order_product['quantity'] . ") WHERE `product_option_value_id` = '" . (int)$order_option['product_option_value_id'] . "' AND `subtract` = '1'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If order status becomes complete status
|
||||
if (!in_array($order_info['order_status_id'], (array)$this->config->get('config_complete_status')) && in_array($order_status_id, (array)$this->config->get('config_complete_status'))) {
|
||||
// Affiliate add commission if complete status
|
||||
if ($order_info['affiliate_id'] && $this->config->get('config_affiliate_auto')) {
|
||||
// Add commission if sale is linked to affiliate referral.
|
||||
$this->load->model('account/customer');
|
||||
|
||||
if (!$this->model_account_customer->getTotalTransactionsByOrderId($order_id)) {
|
||||
$this->model_account_customer->addTransaction($order_info['affiliate_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['commission'], $order_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Add subscription
|
||||
$this->load->model('checkout/subscription');
|
||||
|
||||
foreach ($order_products as $order_product) {
|
||||
// Subscription
|
||||
$order_subscription_info = $this->getSubscription($order_id, $order_product['order_product_id']);
|
||||
|
||||
if ($order_subscription_info) {
|
||||
// Add subscription if one is not setup
|
||||
$subscription_info = $this->model_checkout_subscription->getSubscriptionByOrderProductId($order_id, $order_product['order_product_id']);
|
||||
|
||||
if ($subscription_info) {
|
||||
$subscription_id = $subscription_info['subscription_id'];
|
||||
} else {
|
||||
$subscription_id = $this->model_checkout_subscription->addSubscription(array_merge($order_subscription_info, $order_product, $order_info));
|
||||
}
|
||||
|
||||
// Add history and set active subscription
|
||||
$this->model_checkout_subscription->addHistory($subscription_id, (int)$this->config->get('config_subscription_active_id'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If old order status is the processing or complete status but new status is not then commence restock, and remove coupon, voucher and reward history
|
||||
if (in_array($order_info['order_status_id'], array_merge((array)$this->config->get('config_processing_status'), (array)$this->config->get('config_complete_status'))) && !in_array($order_status_id, array_merge((array)$this->config->get('config_processing_status'), (array)$this->config->get('config_complete_status')))) {
|
||||
// Restock
|
||||
foreach ($order_products as $order_product) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "product` SET `quantity` = (`quantity` + " . (int)$order_product['quantity'] . ") WHERE `product_id` = '" . (int)$order_product['product_id'] . "' AND `subtract` = '1'");
|
||||
|
||||
// Restock the master product stock level if product is a variant
|
||||
if ($order_product['master_id']) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "product` SET `quantity` = (`quantity` + " . (int)$order_product['quantity'] . ") WHERE `product_id` = '" . (int)$order_product['master_id'] . "' AND `subtract` = '1'");
|
||||
}
|
||||
|
||||
$order_options = $this->getOptions($order_id, $order_product['order_product_id']);
|
||||
|
||||
foreach ($order_options as $order_option) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "product_option_value` SET `quantity` = (`quantity` + " . (int)$order_product['quantity'] . ") WHERE `product_option_value_id` = '" . (int)$order_option['product_option_value_id'] . "' AND `subtract` = '1'");
|
||||
}
|
||||
}
|
||||
|
||||
// Remove coupon, vouchers and reward points history
|
||||
foreach ($order_totals as $order_total) {
|
||||
$this->load->model('extension/' . $order_total['extension'] . '/total/' . $order_total['code']);
|
||||
|
||||
if (isset($this->{'model_extension_' . $order_total['extension'] . '_total_' . $order_total['code']}->unconfirm)) {
|
||||
$this->{'model_extension_' . $order_total['extension'] . '_total_' . $order_total['code']}->unconfirm($order_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If order status is no longer complete status
|
||||
if (in_array($order_info['order_status_id'], (array)$this->config->get('config_complete_status')) && !in_array($order_status_id, (array)$this->config->get('config_complete_status'))) {
|
||||
// Suspend subscription
|
||||
$this->load->model('checkout/subscription');
|
||||
|
||||
foreach ($order_products as $order_product) {
|
||||
// Subscription status set to suspend
|
||||
$subscription_info = $this->model_checkout_subscription->getSubscriptionByOrderProductId($order_id, $order_product['order_product_id']);
|
||||
|
||||
if ($subscription_info) {
|
||||
// Add history and set suspended subscription
|
||||
$this->model_checkout_subscription->addHistory($subscription_info['subscription_id'], (int)$this->config->get('config_subscription_suspended_status_id'));
|
||||
}
|
||||
}
|
||||
|
||||
// Affiliate remove commission.
|
||||
if ($order_info['affiliate_id']) {
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$this->model_account_customer->deleteTransactionByOrderId($order_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the DB with the new statuses
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `order_status_id` = '" . (int)$order_status_id . "', `date_modified` = NOW() WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_history` SET `order_id` = '" . (int)$order_id . "', `order_status_id` = '" . (int)$order_status_id . "', `notify` = '" . (int)$notify . "', `comment` = '" . $this->db->escape($comment) . "', `date_added` = NOW()");
|
||||
|
||||
$this->cache->delete('product');
|
||||
}
|
||||
}
|
||||
}
|
43
catalog/model/checkout/payment_method.php
Normal file
43
catalog/model/checkout/payment_method.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Checkout;
|
||||
/**
|
||||
* Class PaymentMethod
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Checkout
|
||||
*/
|
||||
class PaymentMethod extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $payment_address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMethods(array $payment_address = []): array {
|
||||
$method_data = [];
|
||||
|
||||
$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_methods = $this->{'model_extension_' . $result['extension'] . '_payment_' . $result['code']}->getMethods($payment_address);
|
||||
|
||||
if ($payment_methods) {
|
||||
$method_data[$result['code']] = $payment_methods;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($method_data as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $method_data);
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
43
catalog/model/checkout/shipping_method.php
Normal file
43
catalog/model/checkout/shipping_method.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Checkout;
|
||||
/**
|
||||
* Class ShippingMethod
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Checkout
|
||||
*/
|
||||
class ShippingMethod extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $shipping_address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMethods(array $shipping_address): array {
|
||||
$method_data = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getExtensionsByType('shipping');
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($this->config->get('shipping_' . $result['code'] . '_status')) {
|
||||
$this->load->model('extension/' . $result['extension'] . '/shipping/' . $result['code']);
|
||||
|
||||
$quote = $this->{'model_extension_' . $result['extension'] . '_shipping_' . $result['code']}->getQuote($shipping_address);
|
||||
|
||||
if ($quote) {
|
||||
$method_data[$result['code']] = $quote;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($method_data as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $method_data);
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
208
catalog/model/checkout/subscription.php
Normal file
208
catalog/model/checkout/subscription.php
Normal file
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Checkout;
|
||||
/**
|
||||
* Class Subscription
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Checkout
|
||||
*/
|
||||
class Subscription extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addSubscription(array $data): int {
|
||||
if ($data['trial_status'] && $data['trial_duration']) {
|
||||
$trial_remaining = $data['trial_duration'] - 1;
|
||||
$remaining = $data['duration'];
|
||||
} elseif ($data['duration']) {
|
||||
$trial_remaining = $data['trial_duration'];
|
||||
$remaining = $data['duration'] - 1;
|
||||
} else {
|
||||
$trial_remaining = $data['trial_duration'];
|
||||
$remaining = $data['duration'];
|
||||
}
|
||||
|
||||
if ($data['trial_status'] && $data['trial_duration']) {
|
||||
$date_next = date('Y-m-d', strtotime('+' . $data['trial_cycle'] . ' ' . $data['trial_frequency']));
|
||||
} else {
|
||||
$date_next = date('Y-m-d', strtotime('+' . $data['cycle'] . ' ' . $data['frequency']));
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription` SET
|
||||
`order_product_id` = '" . (int)$data['order_product_id'] . "',
|
||||
`order_id` = '" . (int)$data['order_id'] . "',
|
||||
`store_id` = '" . (int)$data['store_id'] . "',
|
||||
`customer_id` = '" . (int)$data['customer_id'] . "',
|
||||
`payment_address_id` = '" . (int)$data['payment_address_id'] . "',
|
||||
`payment_method` = '" . $this->db->escape($data['payment_method'] ? json_encode($data['payment_method']) : '') . "',
|
||||
`shipping_address_id` = '" . (int)$data['shipping_address_id'] . "',
|
||||
`shipping_method` = '" . $this->db->escape($data['shipping_method'] ? json_encode($data['shipping_method']) : '') . "',
|
||||
`product_id` = '" . (int)$data['product_id'] . "',
|
||||
`quantity` = '" . (int)$data['quantity'] . "',
|
||||
`subscription_plan_id` = '" . (int)$data['subscription_plan_id'] . "',
|
||||
`trial_price` = '" . (float)$data['trial_price'] . "',
|
||||
`trial_frequency` = '" . $this->db->escape($data['trial_frequency']) . "',
|
||||
`trial_cycle` = '" . (int)$data['trial_cycle'] . "',
|
||||
`trial_duration` = '" . (int)$data['trial_duration'] . "',
|
||||
`trial_remaining` = '" . (int)$trial_remaining . "',
|
||||
`trial_status` = '" . (int)$data['trial_status'] . "',
|
||||
`price` = '" . (float)$data['price'] . "',
|
||||
`frequency` = '" . $this->db->escape($data['frequency']) . "',
|
||||
`cycle` = '" . (int)$data['cycle'] . "',
|
||||
`duration` = '" . (int)$data['duration'] . "',
|
||||
`remaining` = '" . (int)$trial_remaining . "',
|
||||
`date_next` = '" . $this->db->escape($date_next) . "',
|
||||
`comment` = '" . $this->db->escape($data['comment']) . "',
|
||||
`affiliate_id` = '" . (int)$data['affiliate_id'] . "',
|
||||
`marketing_id` = '" . (int)$data['marketing_id'] . "',
|
||||
`tracking` = '" . $this->db->escape($data['tracking']) . "',
|
||||
`language_id` = '" . (int)$data['language_id'] . "',
|
||||
`currency_id` = '" . (int)$data['currency_id'] . "',
|
||||
`ip` = '" . $this->db->escape($data['ip']) . "',
|
||||
`forwarded_ip` = '" . $this->db->escape($data['forwarded_ip']) . "',
|
||||
`user_agent` = '" . $this->db->escape($data['user_agent']) . "',
|
||||
`accept_language` = '" . $this->db->escape($data['accept_language']) . "',
|
||||
`date_added` = NOW(),
|
||||
`date_modified` = NOW()
|
||||
");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSubscription(int $subscription_id, array $data): void {
|
||||
if ($data['trial_status'] && $data['trial_duration']) {
|
||||
$trial_remaining = $data['trial_duration'] - 1;
|
||||
$remaining = $data['duration'];
|
||||
} elseif ($data['duration']) {
|
||||
$trial_remaining = $data['trial_duration'];
|
||||
$remaining = $data['duration'] - 1;
|
||||
} else {
|
||||
$trial_remaining = $data['trial_duration'];
|
||||
$remaining = $data['duration'];
|
||||
}
|
||||
|
||||
if ($data['trial_status'] && $data['trial_duration']) {
|
||||
$date_next = date('Y-m-d', strtotime('+' . $data['trial_cycle'] . ' ' . $data['trial_frequency']));
|
||||
} else {
|
||||
$date_next = date('Y-m-d', strtotime('+' . $data['cycle'] . ' ' . $data['frequency']));
|
||||
}
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET
|
||||
`order_product_id` = '" . (int)$data['order_product_id'] . "',
|
||||
`order_id` = '" . (int)$data['order_id'] . "',
|
||||
`store_id` = '" . (int)$data['store_id'] . "',
|
||||
`customer_id` = '" . (int)$data['customer_id'] . "',
|
||||
`payment_address_id` = '" . (int)$data['payment_address_id'] . "',
|
||||
`payment_method` = '" . $this->db->escape($data['payment_method'] ? json_encode($data['payment_method']) : '') . "',
|
||||
`shipping_address_id` = '" . (int)$data['shipping_address_id'] . "',
|
||||
`shipping_method` = '" . $this->db->escape($data['shipping_method'] ? json_encode($data['shipping_method']) : '') . "',
|
||||
`product_id` = '" . (int)$data['product_id'] . "',
|
||||
`subscription_plan_id` = '" . (int)$data['subscription_plan_id'] . "',
|
||||
`trial_price` = '" . (float)$data['trial_price'] . "',
|
||||
`trial_frequency` = '" . $this->db->escape($data['trial_frequency']) . "',
|
||||
`trial_cycle` = '" . (int)$data['trial_cycle'] . "',
|
||||
`trial_duration` = '" . (int)$data['trial_duration'] . "',
|
||||
`trial_remaining` = '" . (int)$trial_remaining . "',
|
||||
`trial_status` = '" . (int)$data['trial_status'] . "',
|
||||
`price` = '" . (float)$data['price'] . "',
|
||||
`frequency` = '" . $this->db->escape($data['frequency']) . "',
|
||||
`cycle` = '" . (int)$data['cycle'] . "',
|
||||
`duration` = '" . (int)$data['duration'] . "',
|
||||
`remaining` = '" . (int)$remaining . "',
|
||||
`date_next` = '" . $this->db->escape($date_next) . "',
|
||||
`comment` = '" . $this->db->escape($data['comment']) . "',
|
||||
`affiliate_id` = '" . (int)$data['affiliate_id'] . "',
|
||||
`marketing_id` = '" . (int)$data['marketing_id'] . "',
|
||||
`tracking` = '" . $this->db->escape($data['tracking']) . "',
|
||||
`language_id` = '" . (int)$data['language_id'] . "',
|
||||
`currency_id` = '" . (int)$data['currency_id'] . "',
|
||||
`ip` = '" . $this->db->escape($data['ip']) . "',
|
||||
`forwarded_ip` = '" . $this->db->escape($data['forwarded_ip']) . "',
|
||||
`user_agent` = '" . $this->db->escape($data['user_agent']) . "',
|
||||
`accept_language` = '" . $this->db->escape($data['accept_language']) . "',
|
||||
`date_modified` = NOW()
|
||||
WHERE `subscription_id` = '" . (int)$subscription_id . "'
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSubscriptionByOrderId(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 . "'");
|
||||
|
||||
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 $subscription_id
|
||||
* @param int $subscription_status_id
|
||||
* @param string $comment
|
||||
* @param bool $notify
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory(int $subscription_id, int $subscription_status_id, string $comment = '', bool $notify = false): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_history` SET `subscription_id` = '" . (int)$subscription_id . "', `subscription_status_id` = '" . (int)$subscription_status_id . "', `comment` = '" . $this->db->escape($comment) . "', `notify` = '" . (int)$notify . "', `date_added` = NOW()");
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `subscription_status_id` = '" . (int)$subscription_status_id . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param bool $subscription_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSubscriptionStatus(int $subscription_id, bool $subscription_status_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `subscription_status_id` = '" . (int)$subscription_status_id . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param int $trial_remaining
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTrialRemaining(int $subscription_id, int $trial_remaining): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `trial_remaining` = '" . (int)$trial_remaining . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param string $date_next
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editDateNext(int $subscription_id, string $date_next): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `date_next` = '" . $this->db->escape($date_next) . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
}
|
105
catalog/model/checkout/voucher.php
Normal file
105
catalog/model/checkout/voucher.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Checkout;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Checkout
|
||||
*/
|
||||
class Voucher extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addVoucher(int $order_id, array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher` SET `order_id` = '" . (int)$order_id . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `from_name` = '" . $this->db->escape((string)$data['from_name']) . "', `from_email` = '" . $this->db->escape((string)$data['from_email']) . "', `to_name` = '" . $this->db->escape((string)$data['to_name']) . "', `to_email` = '" . $this->db->escape((string)$data['to_email']) . "', `voucher_theme_id` = '" . (int)$data['voucher_theme_id'] . "', `message` = '" . $this->db->escape((string)$data['message']) . "', `amount` = '" . (float)$data['amount'] . "', `status` = '1', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disableVoucher(int $order_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "voucher` SET `status` = '0' WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucher(string $code): array {
|
||||
$status = true;
|
||||
|
||||
$voucher_query = $this->db->query("SELECT *, vtd.`name` AS theme FROM `" . DB_PREFIX . "voucher` v LEFT JOIN `" . DB_PREFIX . "voucher_theme` vt ON (v.`voucher_theme_id` = vt.`voucher_theme_id`) LEFT JOIN `" . DB_PREFIX . "voucher_theme_description` vtd ON (vt.`voucher_theme_id` = vtd.`voucher_theme_id`) WHERE v.`code` = '" . $this->db->escape($code) . "' AND vtd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND v.`status` = '1'");
|
||||
|
||||
if ($voucher_query->num_rows) {
|
||||
if ($voucher_query->row['order_id']) {
|
||||
$implode = [];
|
||||
|
||||
foreach ($this->config->get('config_complete_status') as $order_status_id) {
|
||||
$implode[] = "'" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
$order_query = $this->db->query("SELECT `order_id` FROM `" . DB_PREFIX . "order` WHERE `order_id` = '" . (int)$voucher_query->row['order_id'] . "' AND `order_status_id` IN(" . implode(",", $implode) . ")");
|
||||
|
||||
if (!$order_query->num_rows) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$order_voucher_query = $this->db->query("SELECT `order_voucher_id` FROM `" . DB_PREFIX . "order_voucher` WHERE `order_id` = '" . (int)$voucher_query->row['order_id'] . "' AND `voucher_id` = '" . (int)$voucher_query->row['voucher_id'] . "'");
|
||||
|
||||
if (!$order_voucher_query->num_rows) {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
||||
$voucher_history_query = $this->db->query("SELECT SUM(`amount`) AS `total` FROM `" . DB_PREFIX . "voucher_history` vh WHERE vh.`voucher_id` = '" . (int)$voucher_query->row['voucher_id'] . "' GROUP BY vh.`voucher_id`");
|
||||
|
||||
if ($voucher_history_query->num_rows) {
|
||||
$amount = $voucher_query->row['amount'] + $voucher_history_query->row['total'];
|
||||
} else {
|
||||
$amount = $voucher_query->row['amount'];
|
||||
}
|
||||
|
||||
if ($amount <= 0) {
|
||||
$status = false;
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
return [
|
||||
'voucher_id' => $voucher_query->row['voucher_id'],
|
||||
'code' => $voucher_query->row['code'],
|
||||
'from_name' => $voucher_query->row['from_name'],
|
||||
'from_email' => $voucher_query->row['from_email'],
|
||||
'to_name' => $voucher_query->row['to_name'],
|
||||
'to_email' => $voucher_query->row['to_email'],
|
||||
'voucher_theme_id' => $voucher_query->row['voucher_theme_id'],
|
||||
'theme' => $voucher_query->row['theme'],
|
||||
'message' => $voucher_query->row['message'],
|
||||
'image' => $voucher_query->row['image'],
|
||||
'amount' => $amount,
|
||||
'status' => $voucher_query->row['status'],
|
||||
'date_added' => $voucher_query->row['date_added']
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteVoucherByOrderId(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
}
|
58
catalog/model/checkout/voucher_theme.php
Normal file
58
catalog/model/checkout/voucher_theme.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Checkout;
|
||||
/**
|
||||
* Class VoucherTheme
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Checkout
|
||||
*/
|
||||
class VoucherTheme extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $voucher_theme_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucherTheme(int $voucher_theme_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "voucher_theme` vt LEFT JOIN `" . DB_PREFIX . "voucher_theme_description` vtd ON (vt.`voucher_theme_id` = vtd.`voucher_theme_id`) WHERE vt.`voucher_theme_id` = '" . (int)$voucher_theme_id . "' AND vtd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucherThemes(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "voucher_theme` vt LEFT JOIN `" . DB_PREFIX . "voucher_theme_description` vtd ON (vt.`voucher_theme_id` = vtd.`voucher_theme_id`) WHERE vtd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY vtd.`name`";
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$voucher_theme_data = $this->cache->get('voucher_theme.' . md5($sql));
|
||||
|
||||
if (!$voucher_theme_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$voucher_theme_data = $query->rows;
|
||||
|
||||
$this->cache->set('voucher_theme.' . md5($sql), $voucher_theme_data);
|
||||
}
|
||||
|
||||
return $voucher_theme_data;
|
||||
}
|
||||
}
|
218
catalog/model/cms/article.php
Normal file
218
catalog/model/cms/article.php
Normal file
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Cms;
|
||||
/**
|
||||
* Class Article
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Cms
|
||||
*/
|
||||
class Article extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArticle(int $article_id): array {
|
||||
$sql = "SELECT DISTINCT * FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) LEFT JOIN `" . DB_PREFIX . "article_to_store` `a2s` ON (`a`.`article_id` = `a2s`.`article_id`) WHERE `a`.`article_id` = '" . (int)$article_id . "' AND `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `a2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "'";
|
||||
|
||||
$article_data = $this->cache->get('article.'. md5($sql));
|
||||
|
||||
if (!$article_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$article_data = $query->row;
|
||||
|
||||
$this->cache->set('article.'. md5($sql), $article_data);
|
||||
}
|
||||
|
||||
return $article_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArticles(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) LEFT JOIN `" . DB_PREFIX . "article_to_store` `a2s` ON (`a`.`article_id` = `a2s`.`article_id`) WHERE `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `a2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "'";
|
||||
|
||||
if (!empty($data['filter_search'])) {
|
||||
$sql .= " AND (";
|
||||
|
||||
$implode = [];
|
||||
|
||||
$words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search'])));
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`bd`.`name` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
|
||||
$sql .= " OR `bd`.`description` LIKE '" . $this->db->escape('%' . (string)$data['filter_search'] . '%') . "'";
|
||||
|
||||
$implode = [];
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`bd`.`tag` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " OR (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
|
||||
$sql .= ")";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_topic_id'])) {
|
||||
$sql .= " AND `a`.`topic_id` = '" . (int)$data['filter_topic_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_author'])) {
|
||||
$sql .= " AND `a`.`author` = '" . (int)$data['filter_author'] . "'";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `a`.`date_added` DESC";
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$article_data = $this->cache->get('article.'. md5($sql));
|
||||
|
||||
if (!$article_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$article_data = $query->rows;
|
||||
|
||||
$this->cache->set('article.'. md5($sql), $article_data);
|
||||
}
|
||||
|
||||
return $article_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalArticles(): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) LEFT JOIN `" . DB_PREFIX . "article_to_store` `a2s` ON (`a`.`article_id` = `a2s`.`article_id`) WHERE `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `a2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "'";
|
||||
|
||||
if (!empty($data['filter_search'])) {
|
||||
$sql .= " AND (";
|
||||
|
||||
$implode = [];
|
||||
|
||||
$words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search'])));
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`ad`.`name` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
|
||||
$sql .= " OR `ad`.`description` LIKE '" . $this->db->escape('%' . (string)$data['filter_search'] . '%') . "'";
|
||||
|
||||
$implode = [];
|
||||
|
||||
foreach ($words as $word) {
|
||||
$implode[] = "`ad`.`tag` LIKE '" . $this->db->escape('%' . $word . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " OR (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
|
||||
$sql .= ")";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_topic_id'])) {
|
||||
$sql .= " AND `a`.`topic_id` = '" . (int)$data['filter_topic_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_author'])) {
|
||||
$sql .= " AND `a`.`author` = '" . (int)$data['filter_author'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayoutId(int $article_id): int {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "article_to_layout` WHERE `article_id` = '" . (int)$article_id . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['layout_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addComment(int $article_id, array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_comment` SET `article_id` = '" . (int)$article_id . "', `customer_id` = '" . (int)$this->customer->getId() . "', `author` = '" . $this->db->escape((string)$data['author']) . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "', `status` = '" . (bool)!empty($data['status']) . "', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComments(int $article_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "article_comment` WHERE `article_id` = '" . (int)$article_id . "' AND `status` = '1' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit;
|
||||
|
||||
$comment_data = $this->cache->get('comment.'. md5($sql));
|
||||
|
||||
if (!$comment_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$comment_data = $query->rows;
|
||||
|
||||
$this->cache->set('comment.'. md5($sql), $comment_data);
|
||||
}
|
||||
|
||||
return $comment_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalComments(int $article_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article_comment` WHERE `article_id` = '" . (int)$article_id . "' AND `status` = '1'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
48
catalog/model/cms/topic.php
Normal file
48
catalog/model/cms/topic.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Cms;
|
||||
/**
|
||||
* Class Topic
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Cms
|
||||
*/
|
||||
class Topic extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTopic(int $topic_id): array {
|
||||
$sql = "SELECT DISTINCT * FROM `" . DB_PREFIX . "topic` `t` LEFT JOIN `" . DB_PREFIX . "topic_description` `td` ON (`t`.`topic_id` = `td`.`topic_id`) LEFT JOIN `" . DB_PREFIX . "topic_to_store` `t2s` ON (`t`.`topic_id` = `t2s`.`topic_id`) WHERE `t`.`topic_id` = '" . (int)$topic_id . "' AND `td`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `t2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "'";
|
||||
|
||||
$topic_data = $this->cache->get('topic.'. md5($sql));
|
||||
|
||||
if (!$topic_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$topic_data = $query->rows;
|
||||
|
||||
$this->cache->set('topic.'. md5($sql), $topic_data);
|
||||
}
|
||||
|
||||
return $topic_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTopics(): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "topic` `t` LEFT JOIN `" . DB_PREFIX . "topic_description` `td` ON (`t`.`topic_id` = `td`.`topic_id`) LEFT JOIN `" . DB_PREFIX . "topic_to_store` `t2s` ON (`t`.`topic_id` = `t2s`.`topic_id`) WHERE `td`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `t2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' ORDER BY `t`.`sort_order` DESC";
|
||||
|
||||
$topic_data = $this->cache->get('topic.'. md5($sql));
|
||||
|
||||
if (!$topic_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$topic_data = $query->rows;
|
||||
|
||||
$this->cache->set('topic.'. md5($sql), $topic_data);
|
||||
}
|
||||
|
||||
return $topic_data;
|
||||
}
|
||||
}
|
19
catalog/model/design/banner.php
Normal file
19
catalog/model/design/banner.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Design;
|
||||
/**
|
||||
* Class Banner
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Design
|
||||
*/
|
||||
class Banner extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $banner_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBanner(int $banner_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "banner` b LEFT JOIN `" . DB_PREFIX . "banner_image` bi ON (b.`banner_id` = bi.`banner_id`) WHERE b.`banner_id` = '" . (int)$banner_id . "' AND b.`status` = '1' AND bi.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY bi.`sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
35
catalog/model/design/layout.php
Normal file
35
catalog/model/design/layout.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Design;
|
||||
/**
|
||||
* Class Layout
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Design
|
||||
*/
|
||||
class Layout extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $route
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLayout(string $route): int {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "layout_route` WHERE '" . $this->db->escape($route) . "' LIKE `route` AND `store_id` = '" . (int)$this->config->get('config_store_id') . "' ORDER BY `route` DESC LIMIT 1");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['layout_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
* @param string $position
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModules(int $layout_id, string $position): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "layout_module` WHERE `layout_id` = '" . (int)$layout_id . "' AND `position` = '" . $this->db->escape($position) . "' ORDER BY `sort_order`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
31
catalog/model/design/seo_url.php
Normal file
31
catalog/model/design/seo_url.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Design;
|
||||
/**
|
||||
* Class Seo Url
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Design
|
||||
*/
|
||||
class SeoUrl extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $keyword
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrlByKeyword(string $keyword): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE (`keyword` = '" . $this->db->escape($keyword) . "' OR `keyword` LIKE '" . $this->db->escape('%/' . $keyword) . "') AND `store_id` = '" . (int)$this->config->get('config_store_id') . "' LIMIT 1");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrlByKeyValue(string $key, string $value): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = '" . $this->db->escape($key) . "' AND `value` = '" . $this->db->escape($value) . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
19
catalog/model/design/theme.php
Normal file
19
catalog/model/design/theme.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Design;
|
||||
/**
|
||||
* Class Theme
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Design
|
||||
*/
|
||||
class Theme extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTheme(string $route): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "theme` WHERE `store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `route` = '" . $this->db->escape($route) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
19
catalog/model/design/translation.php
Normal file
19
catalog/model/design/translation.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Design;
|
||||
/**
|
||||
* Class Translation
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Design
|
||||
*/
|
||||
class Translation extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTranslations(string $route): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "translation` WHERE `store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `route` = '" . $this->db->escape($route) . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
80
catalog/model/localisation/country.php
Normal file
80
catalog/model/localisation/country.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Country extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountry(int $country_id): array {
|
||||
$query = $this->db->query("SELECT *, `c`.`name` FROM `" . DB_PREFIX . "country` `c` LEFT JOIN `" . DB_PREFIX . "address_format` af ON (`c`.`address_format_id` = `af`.`address_format_id`) WHERE `c`.`country_id` = '" . (int)$country_id . "' AND `c`.`status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode2($iso_code_2): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "country` WHERE `iso_code_2` = '" . $this->db->escape($iso_code_2) . "' AND `status` = '1'";
|
||||
|
||||
$country_data = $this->cache->get('country.'. md5($sql));
|
||||
|
||||
if (!$country_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$country_data = $query->rows;
|
||||
|
||||
$this->cache->set('country.'. md5($sql), $country_data);
|
||||
}
|
||||
|
||||
return $country_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode3($iso_code_3): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "country` WHERE `iso_code_3` = '" . $this->db->escape($iso_code_3) . "' AND `status` = '1'";
|
||||
|
||||
$country_data = $this->cache->get('country.'. md5($sql));
|
||||
|
||||
if (!$country_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$country_data = $query->rows;
|
||||
|
||||
$this->cache->set('country.'. md5($sql), $country_data);
|
||||
}
|
||||
|
||||
return $country_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCountries(): array {
|
||||
$sql = "SELECT *, c.`name` FROM `" . DB_PREFIX . "country` c LEFT JOIN `" . DB_PREFIX . "address_format` `af` ON (c.`address_format_id` = af.`address_format_id`) WHERE `c`.`status` = '1' ORDER BY `c`.`name` ASC";
|
||||
|
||||
$country_data = $this->cache->get('country.'. md5($sql));
|
||||
|
||||
if (!$country_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$country_data = $query->rows;
|
||||
|
||||
$this->cache->set('country.'. md5($sql), $country_data);
|
||||
}
|
||||
|
||||
return $country_data;
|
||||
}
|
||||
}
|
75
catalog/model/localisation/currency.php
Normal file
75
catalog/model/localisation/currency.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editValueByCode(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "currency` SET `value` = '" . (float)$value . "', `date_modified` = NOW() WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currency_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrency(int $currency_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `currency_id` = '" . $this->db->escape($currency_id) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencyByCode(string $currency): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `code` = '" . $this->db->escape($currency) . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencies(): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "currency` WHERE `status` = '1' ORDER BY `title` ASC";
|
||||
|
||||
$currency_data = $this->cache->get('currency.' . md5($sql));
|
||||
|
||||
if (!$currency_data) {
|
||||
$currency_data = [];
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$currency_data[$result['code']] = [
|
||||
'currency_id' => $result['currency_id'],
|
||||
'title' => $result['title'],
|
||||
'code' => $result['code'],
|
||||
'symbol_left' => $result['symbol_left'],
|
||||
'symbol_right' => $result['symbol_right'],
|
||||
'decimal_place' => $result['decimal_place'],
|
||||
'value' => $result['value'],
|
||||
'status' => $result['status'],
|
||||
'date_modified' => $result['date_modified']
|
||||
];
|
||||
}
|
||||
|
||||
$this->cache->set('currency.' . md5($sql), $currency_data);
|
||||
}
|
||||
|
||||
return $currency_data;
|
||||
}
|
||||
}
|
117
catalog/model/localisation/language.php
Normal file
117
catalog/model/localisation/language.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $data = [];
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguage(int $language_id): array {
|
||||
if (isset($this->data[$language_id])) {
|
||||
return $this->data[$language_id];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_SERVER;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
$this->data[$language_id] = $language;
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageByCode(string $code): array {
|
||||
if (isset($this->data[$code])) {
|
||||
return $this->data[$code];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_SERVER;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
$this->data[$code] = $language;
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguages(): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "language` WHERE `status` = '1' ORDER BY `sort_order`, `name`";
|
||||
|
||||
$results = (array)$this->cache->get('language.' . md5($sql));
|
||||
|
||||
if (!$results) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$results = $query->rows;
|
||||
|
||||
$this->cache->set('language.' . md5($sql), $results);
|
||||
}
|
||||
|
||||
$language_data = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
$image = HTTP_SERVER;
|
||||
|
||||
if (!$result['extension']) {
|
||||
$image .= 'catalog/';
|
||||
} else {
|
||||
$image .= 'extension/' . $result['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language_data[$result['code']] = [
|
||||
'language_id' => $result['language_id'],
|
||||
'name' => $result['name'],
|
||||
'code' => $result['code'],
|
||||
'image' => $image . 'language/' . $result['code'] . '/' . $result['code'] . '.png',
|
||||
'locale' => $result['locale'],
|
||||
'extension' => $result['extension'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'status' => $result['status']
|
||||
];
|
||||
}
|
||||
|
||||
return $language_data;
|
||||
}
|
||||
}
|
19
catalog/model/localisation/location.php
Normal file
19
catalog/model/localisation/location.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Location
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Location extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $location_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocation(int $location_id): array {
|
||||
$query = $this->db->query("SELECT `location_id`, `name`, `address`, `geocode`, `telephone`, `image`, `open`, `comment` FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
38
catalog/model/localisation/order_status.php
Normal file
38
catalog/model/localisation/order_status.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class OrderStatus
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class OrderStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatus(int $order_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatuses(): array {
|
||||
$sql = "SELECT `order_status_id`, `name` FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
$order_status_data = $this->cache->get('order_status.' . md5($sql));
|
||||
|
||||
if (!$order_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$order_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('order_status.' . md5($sql), $order_status_data);
|
||||
}
|
||||
|
||||
return $order_status_data;
|
||||
}
|
||||
}
|
47
catalog/model/localisation/return_reason.php
Normal file
47
catalog/model/localisation/return_reason.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnReason
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class ReturnReason extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnReasons(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
if (isset($data['return']) && ($data['return'] == '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'];
|
||||
}
|
||||
|
||||
$return_reason_data = $this->cache->get('return_reason.' . md5($sql));
|
||||
|
||||
if (!$return_reason_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$return_reason_data = $query->rows;
|
||||
|
||||
$this->cache->set('return_reason.' . md5($sql), $return_reason_data);
|
||||
}
|
||||
|
||||
return $return_reason_data;
|
||||
}
|
||||
}
|
58
catalog/model/localisation/stock_status.php
Normal file
58
catalog/model/localisation/stock_status.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class StockStatus
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class StockStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStockStatus(int $stock_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStockStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$stock_status_data = $this->cache->get('stock_status.'. md5($sql));
|
||||
|
||||
if (!$stock_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$stock_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('stock_status.'. md5($sql), $stock_status_data);
|
||||
}
|
||||
|
||||
return $stock_status_data;
|
||||
}
|
||||
}
|
38
catalog/model/localisation/subscription_status.php
Normal file
38
catalog/model/localisation/subscription_status.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class SubscriptionStatus
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class SubscriptionStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionStatus(int $subscription_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionStatuses(): array {
|
||||
$sql = "SELECT `subscription_status_id`, `name` FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
$subscription_status_data = $this->cache->get('subscription_status.'. md5($sql));
|
||||
|
||||
if (!$subscription_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$subscription_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('subscription_status.'. md5($sql), $subscription_status_data);
|
||||
}
|
||||
|
||||
return $subscription_status_data;
|
||||
}
|
||||
}
|
40
catalog/model/localisation/zone.php
Normal file
40
catalog/model/localisation/zone.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Zone
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Zone extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZone(int $zone_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$zone_id . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZonesByCountryId(int $country_id): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "zone` WHERE `country_id` = '" . (int)$country_id . "' AND `status` = '1' ORDER BY `name`";
|
||||
|
||||
$zone_data = $this->cache->get('zone.' . md5($sql));
|
||||
|
||||
if (!$zone_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$zone_data = $query->rows;
|
||||
|
||||
$this->cache->set('zone.' . md5($sql), $zone_data);
|
||||
}
|
||||
|
||||
return $zone_data;
|
||||
}
|
||||
}
|
133
catalog/model/marketing/coupon.php
Normal file
133
catalog/model/marketing/coupon.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Marketing;
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Marketing
|
||||
*/
|
||||
class Coupon extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCoupon(string $code): array {
|
||||
$status = true;
|
||||
|
||||
$coupon_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "coupon` WHERE `code` = '" . $this->db->escape($code) . "' AND ((`date_start` = '0000-00-00' OR `date_start` < NOW()) AND (`date_end` = '0000-00-00' OR `date_end` > NOW())) AND `status` = '1'");
|
||||
|
||||
if ($coupon_query->num_rows) {
|
||||
if ($coupon_query->row['total'] > $this->cart->getSubTotal()) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$coupon_total = $this->getTotalHistoriesByCoupon($code);
|
||||
|
||||
if ($coupon_query->row['uses_total'] > 0 && ($coupon_total >= $coupon_query->row['uses_total'])) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($coupon_query->row['logged'] && !$this->customer->getId()) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($this->customer->getId()) {
|
||||
$customer_total = $this->getTotalHistoriesByCustomerId($code, $this->customer->getId());
|
||||
|
||||
if ($coupon_query->row['uses_customer'] > 0 && ($customer_total >= $coupon_query->row['uses_customer'])) {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Products
|
||||
$coupon_product_data = [];
|
||||
|
||||
$coupon_product_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "coupon_product` WHERE `coupon_id` = '" . (int)$coupon_query->row['coupon_id'] . "'");
|
||||
|
||||
foreach ($coupon_product_query->rows as $product) {
|
||||
$coupon_product_data[] = $product['product_id'];
|
||||
}
|
||||
|
||||
// Categories
|
||||
$coupon_category_data = [];
|
||||
|
||||
$coupon_category_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "coupon_category` cc LEFT JOIN `" . DB_PREFIX . "category_path` cp ON (cc.`category_id` = cp.`path_id`) WHERE cc.`coupon_id` = '" . (int)$coupon_query->row['coupon_id'] . "'");
|
||||
|
||||
foreach ($coupon_category_query->rows as $category) {
|
||||
$coupon_category_data[] = $category['category_id'];
|
||||
}
|
||||
|
||||
$product_data = [];
|
||||
|
||||
if ($coupon_product_data || $coupon_category_data) {
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if (in_array($product['product_id'], $coupon_product_data)) {
|
||||
$product_data[] = $product['product_id'];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($coupon_category_data as $category_id) {
|
||||
$coupon_category_query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "product_to_category` WHERE `product_id` = '" . (int)$product['product_id'] . "' AND `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
if ($coupon_category_query->row['total']) {
|
||||
$product_data[] = $product['product_id'];
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$product_data) {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
return [
|
||||
'coupon_id' => $coupon_query->row['coupon_id'],
|
||||
'code' => $coupon_query->row['code'],
|
||||
'name' => $coupon_query->row['name'],
|
||||
'type' => $coupon_query->row['type'],
|
||||
'discount' => $coupon_query->row['discount'],
|
||||
'shipping' => $coupon_query->row['shipping'],
|
||||
'total' => $coupon_query->row['total'],
|
||||
'product' => $product_data,
|
||||
'date_start' => $coupon_query->row['date_start'],
|
||||
'date_end' => $coupon_query->row['date_end'],
|
||||
'uses_total' => $coupon_query->row['uses_total'],
|
||||
'uses_customer' => $coupon_query->row['uses_customer'],
|
||||
'status' => $coupon_query->row['status'],
|
||||
'date_added' => $coupon_query->row['date_added']
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $coupon
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistoriesByCoupon(string $coupon): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "coupon_history` ch LEFT JOIN `" . DB_PREFIX . "coupon` c ON (ch.`coupon_id` = c.`coupon_id`) WHERE c.`code` = '" . $this->db->escape($coupon) . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $coupon
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistoriesByCustomerId(string $coupon, int $customer_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "coupon_history` ch LEFT JOIN `" . DB_PREFIX . "coupon` c ON (ch.`coupon_id` = c.`coupon_id`) WHERE c.`code` = '" . $this->db->escape($coupon) . "' AND ch.`customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
30
catalog/model/marketing/marketing.php
Normal file
30
catalog/model/marketing/marketing.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Marketing;
|
||||
/**
|
||||
* Class Marketing
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Marketing
|
||||
*/
|
||||
class Marketing extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMarketingByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "marketing` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $marketing_id
|
||||
* @param string $ip
|
||||
* @param string $country
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReport(int $marketing_id, string $ip, string $country = ''): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "marketing_report` SET `marketing_id` = '" . (int)$marketing_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
|
||||
}
|
||||
}
|
62
catalog/model/report/statistics.php
Normal file
62
catalog/model/report/statistics.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Report;
|
||||
/**
|
||||
* Class Statistics
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Report
|
||||
*/
|
||||
class Statistics extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStatistics(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "statistics`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getValue(string $code): float {
|
||||
$query = $this->db->query("SELECT `value` FROM `" . DB_PREFIX . "statistics` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->row['value'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = (`value` + '" . (float)$value . "') WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = (`value` - '" . (float)$value . "') WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = '" . (float)$value . "' WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
}
|
70
catalog/model/setting/api.php
Normal file
70
catalog/model/setting/api.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Api
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
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` a LEFT JOIN `" . DB_PREFIX . "api_ip` ai ON (a.`api_id` = ai.`api_id`) WHERE a.`username` = '" . $this->db->escape($username) . "' AND a.`key` = '" . $this->db->escape($key) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApiByToken(string $token): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` a LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.`api_id` = `as`.`api_id`) LEFT JOIN `" . DB_PREFIX . "api_ip` ai ON (a.`api_id` = ai.`api_id`) WHERE a.`status` = '1' AND `as`.`session_id` = '" . $this->db->escape((string)$token) . "' AND ai.`ip` = '" . $this->db->escape((string)$this->request->server['REMOTE_ADDR']) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSessions(int $api_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW() AND `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function deleteSessions(int $api_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW() AND `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $api_session_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateSession(string $api_session_id): void {
|
||||
// keep the session alive
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "api_session` SET `date_modified` = NOW() WHERE `api_session_id` = '" . (int)$api_session_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function cleanSessions(): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW()");
|
||||
}
|
||||
}
|
67
catalog/model/setting/cron.php
Normal file
67
catalog/model/setting/cron.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Cron
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Cron extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $cron_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCron(int $cron_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `date_modified` = NOW() WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $cron_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `status` = '" . (bool)$status . "' WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCron(int $cron_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCronByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCrons(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "cron` ORDER BY `date_modified` DESC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCrons(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "cron`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
17
catalog/model/setting/event.php
Normal file
17
catalog/model/setting/event.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Event extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getEvents(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "event` WHERE `status` = '1' ORDER BY `sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
40
catalog/model/setting/extension.php
Normal file
40
catalog/model/setting/extension.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Extension
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Extension extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensions(): array {
|
||||
$query = $this->db->query("SELECT DISTINCT `extension` FROM `" . DB_PREFIX . "extension`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensionsByType(string $type): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensionByCode(string $type, string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
23
catalog/model/setting/module.php
Normal file
23
catalog/model/setting/module.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Module
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Module extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $module_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModule(int $module_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
|
||||
|
||||
if ($query->row) {
|
||||
return json_decode($query->row['setting'], true);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
57
catalog/model/setting/setting.php
Normal file
57
catalog/model/setting/setting.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Setting
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Setting extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings(int $store_id = 0): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' OR `store_id` = 0 ORDER BY `store_id` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSetting(string $code, int $store_id = 0): array {
|
||||
$setting_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
if (!$result['serialized']) {
|
||||
$setting_data[$result['key']] = $result['value'];
|
||||
} else {
|
||||
$setting_data[$result['key']] = json_decode($result['value'], true);
|
||||
}
|
||||
}
|
||||
|
||||
return $setting_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(string $key, int $store_id = 0): string {
|
||||
$query = $this->db->query("SELECT `value` FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `key` = '" . $this->db->escape($key) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->row['value'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
17
catalog/model/setting/startup.php
Normal file
17
catalog/model/setting/startup.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Startup
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Startup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
function getStartups() {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "startup` WHERE `status` = '1' ORDER BY `sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
180
catalog/model/setting/store.php
Normal file
180
catalog/model/setting/store.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class StoreStore
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Store extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStore(int $store_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStoreByHostname(string $url): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "store` WHERE REPLACE(`url`, 'www.', '') = '" . $this->db->escape($url) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "store` ORDER BY `url`";
|
||||
|
||||
$store_data = $this->cache->get('store.' . md5($sql));
|
||||
|
||||
if (!$store_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$store_data = $query->rows;
|
||||
|
||||
$this->cache->set('store.' . md5($sql), $store_data);
|
||||
}
|
||||
|
||||
return $store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
* @param string $language
|
||||
* @param string $session_id
|
||||
*
|
||||
* @return \Opencart\System\Engine\Registry
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createStoreInstance(int $store_id = 0, string $language = '', string $session_id = ''): object {
|
||||
// Autoloader
|
||||
$this->autoloader->register('Opencart\Catalog', DIR_CATALOG);
|
||||
|
||||
// Registry
|
||||
$registry = new \Opencart\System\Engine\Registry();
|
||||
$registry->set('autoloader', $this->autoloader);
|
||||
|
||||
// Config
|
||||
$config = new \Opencart\System\Engine\Config();
|
||||
$registry->set('config', $config);
|
||||
|
||||
// Load the default config
|
||||
$config->addPath(DIR_CONFIG);
|
||||
$config->load('default');
|
||||
$config->set('application', 'Catalog');
|
||||
|
||||
// Store
|
||||
$config->set('config_store_id', $store_id);
|
||||
|
||||
// Logging
|
||||
$registry->set('log', $this->log);
|
||||
|
||||
// Event
|
||||
$event = new \Opencart\System\Engine\Event($registry);
|
||||
$registry->set('event', $event);
|
||||
|
||||
// Event Register
|
||||
if ($config->has('action_event')) {
|
||||
foreach ($config->get('action_event') as $key => $value) {
|
||||
foreach ($value as $priority => $action) {
|
||||
$event->register($key, new \Opencart\System\Engine\Action($action), $priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loader
|
||||
$loader = new \Opencart\System\Engine\Loader($registry);
|
||||
$registry->set('load', $loader);
|
||||
|
||||
// Create a dummy request class so we can feed the data to the order editor
|
||||
$request = new \stdClass();
|
||||
$request->get = [];
|
||||
$request->post = [];
|
||||
$request->server = $this->request->server;
|
||||
$request->cookie = [];
|
||||
|
||||
// Request
|
||||
$registry->set('request', $request);
|
||||
|
||||
// Response
|
||||
$response = new \Opencart\System\Library\Response();
|
||||
$registry->set('response', $response);
|
||||
|
||||
// Database
|
||||
$registry->set('db', $this->db);
|
||||
|
||||
// Cache
|
||||
$registry->set('cache', $this->cache);
|
||||
|
||||
// Session
|
||||
$session = new \Opencart\System\Library\Session($config->get('session_engine'), $registry);
|
||||
$registry->set('session', $session);
|
||||
|
||||
// Start session
|
||||
$session->start($session_id);
|
||||
|
||||
// Template
|
||||
$template = new \Opencart\System\Library\Template($config->get('template_engine'));
|
||||
$template->addPath(DIR_TEMPLATE);
|
||||
$registry->set('template', $template);
|
||||
|
||||
// Language
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguageByCode($language);
|
||||
|
||||
if ($language_info) {
|
||||
$config->set('config_language_id', $language_info['language_id']);
|
||||
$config->set('config_language', $language_info['code']);
|
||||
} else {
|
||||
$config->set('config_language_id', $this->config->get('config_language_id'));
|
||||
$config->set('config_language', $this->config->get('config_language'));
|
||||
}
|
||||
|
||||
$language = new \Opencart\System\Library\Language($this->config->get('config_language'));
|
||||
$registry->set('language', $language);
|
||||
|
||||
if (!$language_info['extension']) {
|
||||
$language->addPath(DIR_LANGUAGE);
|
||||
} else {
|
||||
$language->addPath(DIR_EXTENSION . $language_info['extension'] . '/catalog/language/');
|
||||
}
|
||||
|
||||
// Load default language file
|
||||
$language->load('default');
|
||||
|
||||
// Url
|
||||
$registry->set('url', new \Opencart\System\Library\Url($config->get('site_url')));
|
||||
|
||||
// Document
|
||||
$registry->set('document', new \Opencart\System\Library\Document());
|
||||
|
||||
// Run pre actions to load key settings and classes.
|
||||
$pre_actions = [
|
||||
'startup/setting',
|
||||
'startup/extension',
|
||||
'startup/customer',
|
||||
'startup/tax',
|
||||
'startup/currency',
|
||||
'startup/application',
|
||||
'startup/startup',
|
||||
'startup/event'
|
||||
];
|
||||
|
||||
// Pre Actions
|
||||
foreach ($pre_actions as $pre_action) {
|
||||
$loader->controller($pre_action);
|
||||
}
|
||||
|
||||
return $registry;
|
||||
}
|
||||
}
|
64
catalog/model/tool/image.php
Normal file
64
catalog/model/tool/image.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Tool;
|
||||
/**
|
||||
* Class Image
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Tool
|
||||
*/
|
||||
class Image extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $filename
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @param string $default
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function resize(string $filename, int $width, int $height, string $default = ''): string {
|
||||
if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
$image_old = $filename;
|
||||
$image_new = 'cache/' . oc_substr($filename, 0, oc_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '.' . $extension;
|
||||
|
||||
if (!is_file(DIR_IMAGE . $image_new) || (filemtime(DIR_IMAGE . $image_old) > filemtime(DIR_IMAGE . $image_new))) {
|
||||
list($width_orig, $height_orig, $image_type) = getimagesize(DIR_IMAGE . $image_old);
|
||||
|
||||
if (!in_array($image_type, [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_WEBP])) {
|
||||
return $this->config->get('config_url') . 'image/' . $image_old;
|
||||
}
|
||||
|
||||
$path = '';
|
||||
|
||||
$directories = explode('/', dirname($image_new));
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
if (!$path) {
|
||||
$path = $directory;
|
||||
} else {
|
||||
$path = $path . '/' . $directory;
|
||||
}
|
||||
|
||||
if (!is_dir(DIR_IMAGE . $path)) {
|
||||
@mkdir(DIR_IMAGE . $path, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
if ($width_orig != $width || $height_orig != $height) {
|
||||
$image = new \Opencart\System\Library\Image(DIR_IMAGE . $image_old);
|
||||
$image->resize($width, $height, $default);
|
||||
$image->save(DIR_IMAGE . $image_new);
|
||||
} else {
|
||||
copy(DIR_IMAGE . $image_old, DIR_IMAGE . $image_new);
|
||||
}
|
||||
}
|
||||
|
||||
$image_new = str_replace(' ', '%20', $image_new); // fix bug when attach image on email (gmail.com). it is automatically changing space from " " to +
|
||||
|
||||
return $this->config->get('config_url') . 'image/' . $image_new;
|
||||
}
|
||||
}
|
22
catalog/model/tool/online.php
Normal file
22
catalog/model/tool/online.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Tool;
|
||||
/**
|
||||
* Class Online
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Tool
|
||||
*/
|
||||
class Online extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $ip
|
||||
* @param int $customer_id
|
||||
* @param string $url
|
||||
* @param string $referer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addOnline(string $ip, int $customer_id, string $url, string $referer): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_online` WHERE `date_added` < '" . date('Y-m-d H:i:s', strtotime('-' . (int)$this->config->get('config_customer_online_expire') . ' hour')) . "'");
|
||||
|
||||
$this->db->query("REPLACE INTO `" . DB_PREFIX . "customer_online` SET `ip` = '" . $this->db->escape($ip) . "', `customer_id` = '" . (int)$customer_id . "', `url` = '" . $this->db->escape($url) . "', `referer` = '" . $this->db->escape($referer) . "', `date_added` = '" . $this->db->escape(date('Y-m-d H:i:s')) . "'");
|
||||
}
|
||||
}
|
33
catalog/model/tool/upload.php
Normal file
33
catalog/model/tool/upload.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Tool;
|
||||
/**
|
||||
* Class Upload
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Tool
|
||||
*/
|
||||
class Upload extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function addUpload(string $name, string $filename): string {
|
||||
$code = oc_token(32);
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "upload` SET `name` = '" . $this->db->escape($name) . "', `filename` = '" . $this->db->escape($filename) . "', `code` = '" . $this->db->escape($code) . "', `date_added` = NOW()");
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUploadByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "upload` WHERE code = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user