first commit
This commit is contained in:
45
extension/opencart/catalog/model/fraud/ip.php
Normal file
45
extension/opencart/catalog/model/fraud/ip.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Fraud;
|
||||
/**
|
||||
* Class Ip
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Ip extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $order_info
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function check(array $order_info): int {
|
||||
$status = false;
|
||||
|
||||
if ($order_info['customer_id']) {
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$results = $this->model_account_customer->getIps($order_info['customer_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "fraud_ip` WHERE `ip` = '" . $this->db->escape($result['ip']) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$status = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "fraud_ip` WHERE `ip` = '" . $this->db->escape($order_info['ip']) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
return (int)$this->config->get('fraud_ip_order_status_id');
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
30
extension/opencart/catalog/model/module/bestseller.php
Normal file
30
extension/opencart/catalog/model/module/bestseller.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Bestseller
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Bestseller extends \Opencart\Catalog\Model\Catalog\Product {
|
||||
/**
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBestSellers(int $limit): array {
|
||||
// Storing some sub queries so that we are not typing them out multiple times.
|
||||
$sql = "SELECT *, `pd`.`name`, `p`.`image`, `pb`.`total`, " . $this->statement['discount'] . ", " . $this->statement['special'] . ", " . $this->statement['reward'] . ", " . $this->statement['review'] . " FROM `" . DB_PREFIX . "product_bestseller` `pb` LEFT JOIN `" . DB_PREFIX . "product_to_store` `p2s` ON (`p2s`.`product_id` = `pb`.`product_id` AND p2s.`store_id` = '" . (int)$this->config->get('config_store_id') . "') LEFT JOIN `" . DB_PREFIX . "product` `p` ON (`p`.`product_id` = `pb`.`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') . "' ORDER BY `pb`.`total` DESC LIMIT 0," . (int)$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;
|
||||
}
|
||||
}
|
29
extension/opencart/catalog/model/module/latest.php
Normal file
29
extension/opencart/catalog/model/module/latest.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Latest
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Latest extends \Opencart\Catalog\Model\Catalog\Product {
|
||||
/**
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLatest(int $limit): array {
|
||||
$sql = "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 `p2s`.`store_id` = '" . (int)$this->config->get('config_store_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 `pd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `p`.`date_added` DESC LIMIT 0," . (int)$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;
|
||||
}
|
||||
}
|
51
extension/opencart/catalog/model/payment/bank_transfer.php
Normal file
51
extension/opencart/catalog/model/payment/bank_transfer.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class BankTransfer
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class BankTransfer extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMethods(array $address = []): array {
|
||||
$this->load->language('extension/opencart/payment/bank_transfer');
|
||||
|
||||
if ($this->cart->hasSubscription()) {
|
||||
$status = false;
|
||||
} elseif (!$this->config->get('config_checkout_payment_address')) {
|
||||
$status = true;
|
||||
} elseif (!$this->config->get('payment_bank_transfer_geo_zone_id')) {
|
||||
$status = true;
|
||||
} else {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('payment_bank_transfer_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$option_data['bank_transfer'] = [
|
||||
'code' => 'bank_transfer.bank_transfer',
|
||||
'name' => $this->language->get('heading_title')
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'bank_transfer',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'option' => $option_data,
|
||||
'sort_order' => $this->config->get('payment_bank_transfer_sort_order')
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
51
extension/opencart/catalog/model/payment/cheque.php
Normal file
51
extension/opencart/catalog/model/payment/cheque.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class Cheque
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Cheque extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMethods(array $address = []): array {
|
||||
$this->load->language('extension/opencart/payment/cheque');
|
||||
|
||||
if ($this->cart->hasSubscription()) {
|
||||
$status = false;
|
||||
} elseif (!$this->config->get('config_checkout_payment_address')) {
|
||||
$status = true;
|
||||
} elseif (!$this->config->get('payment_cheque_geo_zone_id')) {
|
||||
$status = true;
|
||||
} else {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('payment_cheque_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$option_data['cheque'] = [
|
||||
'code' => 'cheque.cheque',
|
||||
'name' => $this->language->get('heading_title')
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'cheque',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'option' => $option_data,
|
||||
'sort_order' => $this->config->get('payment_cheque_sort_order')
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
53
extension/opencart/catalog/model/payment/cod.php
Normal file
53
extension/opencart/catalog/model/payment/cod.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class COD
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class COD extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMethods(array $address = []): array {
|
||||
$this->load->language('extension/opencart/payment/cod');
|
||||
|
||||
if ($this->cart->hasSubscription()) {
|
||||
$status = false;
|
||||
} elseif (!$this->cart->hasShipping()) {
|
||||
$status = false;
|
||||
} elseif (!$this->config->get('config_checkout_payment_address')) {
|
||||
$status = true;
|
||||
} elseif (!$this->config->get('payment_cod_geo_zone_id')) {
|
||||
$status = true;
|
||||
} else {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('payment_cod_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$option_data['cod'] = [
|
||||
'code' => 'cod.cod',
|
||||
'name' => $this->language->get('heading_title')
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'cod',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'option' => $option_data,
|
||||
'sort_order' => $this->config->get('payment_cod_sort_order')
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
53
extension/opencart/catalog/model/payment/free_checkout.php
Normal file
53
extension/opencart/catalog/model/payment/free_checkout.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class FreeCheckout
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class FreeCheckout extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMethods(array $address = []): array {
|
||||
$this->load->language('extension/opencart/payment/free_checkout');
|
||||
|
||||
$total = $this->cart->getTotal();
|
||||
|
||||
if (!empty($this->session->data['vouchers'])) {
|
||||
$amounts = array_column($this->session->data['vouchers'], 'amount');
|
||||
} else {
|
||||
$amounts = [];
|
||||
}
|
||||
|
||||
$total = $total + array_sum($amounts);
|
||||
|
||||
if ((float)$total <= 0.00) {
|
||||
$status = true;
|
||||
} elseif ($this->cart->hasSubscription()) {
|
||||
$status = false;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$option_data['free_checkout'] = [
|
||||
'code' => 'free_checkout.free_checkout',
|
||||
'name' => $this->language->get('heading_title')
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'free_checkout',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'option' => $option_data,
|
||||
'sort_order' => $this->config->get('payment_free_checkout_sort_order')
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
51
extension/opencart/catalog/model/shipping/flat.php
Normal file
51
extension/opencart/catalog/model/shipping/flat.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Shipping;
|
||||
/**
|
||||
* Class Flat
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Flat extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getQuote(array $address): array {
|
||||
$this->load->language('extension/opencart/shipping/flat');
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('shipping_flat_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if (!$this->config->get('shipping_flat_geo_zone_id')) {
|
||||
$status = true;
|
||||
} elseif ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$quote_data = [];
|
||||
|
||||
$quote_data['flat'] = [
|
||||
'code' => 'flat.flat',
|
||||
'name' => $this->language->get('text_description'),
|
||||
'cost' => $this->config->get('shipping_flat_cost'),
|
||||
'tax_class_id' => $this->config->get('shipping_flat_tax_class_id'),
|
||||
'text' => $this->currency->format($this->tax->calculate($this->config->get('shipping_flat_cost'), $this->config->get('shipping_flat_tax_class_id'), $this->config->get('config_tax')), $this->session->data['currency'])
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'flat',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'quote' => $quote_data,
|
||||
'sort_order' => $this->config->get('shipping_flat_sort_order'),
|
||||
'error' => false
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
55
extension/opencart/catalog/model/shipping/free.php
Normal file
55
extension/opencart/catalog/model/shipping/free.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Shipping;
|
||||
/**
|
||||
* Class Free
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Free extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getQuote(array $address): array {
|
||||
$this->load->language('extension/opencart/shipping/free');
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('shipping_free_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if (!$this->config->get('shipping_free_geo_zone_id')) {
|
||||
$status = true;
|
||||
} elseif ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($this->cart->getSubTotal() < $this->config->get('shipping_free_total')) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$quote_data = [];
|
||||
|
||||
$quote_data['free'] = [
|
||||
'code' => 'free.free',
|
||||
'name' => $this->language->get('text_description'),
|
||||
'cost' => 0.00,
|
||||
'tax_class_id' => 0,
|
||||
'text' => $this->currency->format(0.00, $this->session->data['currency'])
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'free',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'quote' => $quote_data,
|
||||
'sort_order' => $this->config->get('shipping_free_sort_order'),
|
||||
'error' => false
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
62
extension/opencart/catalog/model/shipping/item.php
Normal file
62
extension/opencart/catalog/model/shipping/item.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Shipping;
|
||||
/**
|
||||
* Class Item
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Item extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getQuote(array $address): array {
|
||||
$this->load->language('extension/opencart/shipping/item');
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('shipping_item_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if (!$this->config->get('shipping_item_geo_zone_id')) {
|
||||
$status = true;
|
||||
} elseif ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$items = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['shipping']) {
|
||||
$items += $product['quantity'];
|
||||
}
|
||||
}
|
||||
|
||||
$cost = (float)$this->config->get('shipping_item_cost');
|
||||
$tax_class_id = (int)$this->config->get('shipping_item_tax_class_id');
|
||||
|
||||
$quote_data = [];
|
||||
|
||||
$quote_data['item'] = [
|
||||
'code' => 'item.item',
|
||||
'name' => $this->language->get('text_description'),
|
||||
'cost' => $cost * $items,
|
||||
'tax_class_id' => $tax_class_id,
|
||||
'text' => $this->currency->format($this->tax->calculate($cost * $items, $tax_class_id, $this->config->get('config_tax')), $this->session->data['currency'])
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'item',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'quote' => $quote_data,
|
||||
'sort_order' => $this->config->get('shipping_item_sort_order'),
|
||||
'error' => false
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
51
extension/opencart/catalog/model/shipping/pickup.php
Normal file
51
extension/opencart/catalog/model/shipping/pickup.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Shipping;
|
||||
/**
|
||||
* Class Pickup
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Pickup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getQuote(array $address): array {
|
||||
$this->load->language('extension/opencart/shipping/pickup');
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('shipping_pickup_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if (!$this->config->get('shipping_pickup_geo_zone_id')) {
|
||||
$status = true;
|
||||
} elseif ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($status) {
|
||||
$quote_data = [];
|
||||
|
||||
$quote_data['pickup'] = [
|
||||
'code' => 'pickup.pickup',
|
||||
'name' => $this->language->get('text_description'),
|
||||
'cost' => 0.00,
|
||||
'tax_class_id' => 0,
|
||||
'text' => $this->currency->format(0.00, $this->session->data['currency'])
|
||||
];
|
||||
|
||||
$method_data = [
|
||||
'code' => 'pickup',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'quote' => $quote_data,
|
||||
'sort_order' => $this->config->get('shipping_pickup_sort_order'),
|
||||
'error' => false
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
79
extension/opencart/catalog/model/shipping/weight.php
Normal file
79
extension/opencart/catalog/model/shipping/weight.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Shipping;
|
||||
/**
|
||||
* Class Weight
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Weight extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQuote(array $address): array {
|
||||
$this->load->language('extension/opencart/shipping/weight');
|
||||
|
||||
$quote_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "geo_zone` ORDER BY `name`");
|
||||
|
||||
$weight = $this->cart->getWeight();
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
if ($this->config->get('shipping_weight_' . $result['geo_zone_id'] . '_status')) {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$result['geo_zone_id'] . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$cost = '';
|
||||
|
||||
$rates = explode(',', $this->config->get('shipping_weight_' . $result['geo_zone_id'] . '_rate'));
|
||||
|
||||
foreach ($rates as $rate) {
|
||||
$data = explode(':', $rate);
|
||||
|
||||
if ($data[0] >= $weight) {
|
||||
if (isset($data[1])) {
|
||||
$cost = $data[1];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((string)$cost != '') {
|
||||
$quote_data['weight_' . $result['geo_zone_id']] = [
|
||||
'code' => 'weight.weight_' . $result['geo_zone_id'],
|
||||
'name' => $result['name'] . ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('config_weight_class_id')) . ')',
|
||||
'cost' => $cost,
|
||||
'tax_class_id' => $this->config->get('shipping_weight_tax_class_id'),
|
||||
'text' => $this->currency->format($this->tax->calculate($cost, $this->config->get('shipping_weight_tax_class_id'), $this->config->get('config_tax')), $this->session->data['currency'])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$method_data = [];
|
||||
|
||||
if ($quote_data) {
|
||||
$method_data = [
|
||||
'code' => 'weight',
|
||||
'name' => $this->language->get('heading_title'),
|
||||
'quote' => $quote_data,
|
||||
'sort_order' => $this->config->get('shipping_weight_sort_order'),
|
||||
'error' => false
|
||||
];
|
||||
}
|
||||
|
||||
return $method_data;
|
||||
}
|
||||
}
|
168
extension/opencart/catalog/model/total/coupon.php
Normal file
168
extension/opencart/catalog/model/total/coupon.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Coupon extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
if (isset($this->session->data['coupon'])) {
|
||||
$this->load->language('extension/opencart/total/coupon', 'coupon');
|
||||
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$coupon_info = $this->model_marketing_coupon->getCoupon($this->session->data['coupon']);
|
||||
|
||||
if ($coupon_info) {
|
||||
$discount_total = 0;
|
||||
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
if (!$coupon_info['product']) {
|
||||
$sub_total = $this->cart->getSubTotal();
|
||||
} else {
|
||||
$sub_total = 0;
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (in_array($product['product_id'], $coupon_info['product'])) {
|
||||
$sub_total += $product['total'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($coupon_info['type'] == 'F') {
|
||||
$coupon_info['discount'] = min($coupon_info['discount'], $sub_total);
|
||||
}
|
||||
|
||||
foreach ($products as $product) {
|
||||
$discount = 0;
|
||||
|
||||
if (!$coupon_info['product']) {
|
||||
$status = true;
|
||||
} else {
|
||||
$status = in_array($product['product_id'], $coupon_info['product']);
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
if ($coupon_info['type'] == 'F') {
|
||||
$discount = $coupon_info['discount'] * ($product['total'] / $sub_total);
|
||||
} elseif ($coupon_info['type'] == 'P') {
|
||||
$discount = $product['total'] / 100 * $coupon_info['discount'];
|
||||
}
|
||||
|
||||
if ($product['tax_class_id']) {
|
||||
$tax_rates = $this->tax->getRates($product['total'] - ($product['total'] - $discount), $product['tax_class_id']);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if ($tax_rate['type'] == 'P') {
|
||||
$taxes[$tax_rate['tax_rate_id']] -= $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$discount_total += $discount;
|
||||
}
|
||||
|
||||
if ($coupon_info['shipping'] && isset($this->session->data['shipping_method']['cost']) && isset($this->session->data['shipping_method']['tax_class_id'])) {
|
||||
if (!empty($this->session->data['shipping_method']['tax_class_id'])) {
|
||||
$tax_rates = $this->tax->getRates($this->session->data['shipping_method']['cost'], $this->session->data['shipping_method']['tax_class_id']);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if ($tax_rate['type'] == 'P') {
|
||||
$taxes[$tax_rate['tax_rate_id']] -= $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$discount_total += $this->session->data['shipping_method']['cost'];
|
||||
}
|
||||
|
||||
// If discount greater than total
|
||||
if ($discount_total > $total) {
|
||||
$discount_total = $total;
|
||||
}
|
||||
|
||||
if ($discount_total > 0) {
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'coupon',
|
||||
'title' => sprintf($this->language->get('coupon_text_coupon'), $this->session->data['coupon']),
|
||||
'value' => -$discount_total,
|
||||
'sort_order' => (int)$this->config->get('total_coupon_sort_order')
|
||||
];
|
||||
|
||||
$total -= $discount_total;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $order_info
|
||||
* @param array $order_total
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function confirm(array $order_info, array $order_total): int {
|
||||
$code = '';
|
||||
|
||||
$start = strpos($order_total['title'], '(') + 1;
|
||||
$end = strrpos($order_total['title'], ')');
|
||||
|
||||
if ($start && $end) {
|
||||
$code = substr($order_total['title'], $start, $end - $start);
|
||||
}
|
||||
|
||||
if ($code) {
|
||||
$status = true;
|
||||
|
||||
$coupon_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "coupon` WHERE `code` = '" . $this->db->escape($code) . "' AND `status` = '1'");
|
||||
|
||||
if ($coupon_query->num_rows) {
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$coupon_total = $this->model_marketing_coupon->getTotalHistoriesByCoupon($code);
|
||||
|
||||
if ($coupon_query->row['uses_total'] > 0 && ($coupon_total >= $coupon_query->row['uses_total'])) {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($order_info['customer_id']) {
|
||||
$customer_total = $this->model_marketing_coupon->getTotalHistoriesByCustomerId($code, $order_info['customer_id']);
|
||||
|
||||
if ($coupon_query->row['uses_customer'] > 0 && ($customer_total >= $coupon_query->row['uses_customer'])) {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_history` SET `coupon_id` = '" . (int)$coupon_query->row['coupon_id'] . "', `order_id` = '" . (int)$order_info['order_id'] . "', `customer_id` = '" . (int)$order_info['customer_id'] . "', `amount` = '" . (float)$order_total['value'] . "', `date_added` = NOW()");
|
||||
} else {
|
||||
return $this->config->get('config_fraud_status_id');
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unconfirm(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon_history` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
}
|
60
extension/opencart/catalog/model/total/credit.php
Normal file
60
extension/opencart/catalog/model/total/credit.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Credit
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Credit extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
$this->load->language('extension/opencart/total/credit');
|
||||
|
||||
$balance = $this->customer->getBalance();
|
||||
|
||||
if ((float)$balance) {
|
||||
$credit = min($balance, $total);
|
||||
|
||||
if ((float)$credit > 0) {
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'credit',
|
||||
'title' => $this->language->get('text_credit'),
|
||||
'value' => -$credit,
|
||||
'sort_order' => (int)$this->config->get('total_credit_sort_order')
|
||||
];
|
||||
|
||||
$total -= $credit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $order_info
|
||||
* @param array $order_total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(array $order_info, array $order_total): void {
|
||||
$this->load->language('extension/opencart/total/credit');
|
||||
|
||||
if ($order_info['customer_id']) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_transaction` SET `customer_id` = '" . (int)$order_info['customer_id'] . "', `order_id` = '" . (int)$order_info['order_id'] . "', `description` = '" . $this->db->escape(sprintf($this->language->get('text_order_id'), (int)$order_info['order_id'])) . "', `amount` = '" . (float)$order_total['value'] . "', `date_added` = NOW()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unconfirm(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
}
|
43
extension/opencart/catalog/model/total/handling.php
Normal file
43
extension/opencart/catalog/model/total/handling.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Handling
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Handling extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
if (($this->cart->getSubTotal() > (float)$this->config->get('total_handling_total')) && ($this->cart->getSubTotal() > 0)) {
|
||||
$this->load->language('extension/opencart/total/handling');
|
||||
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'handling',
|
||||
'title' => $this->language->get('text_handling'),
|
||||
'value' => (float)$this->config->get('total_handling_fee'),
|
||||
'sort_order' => (int)$this->config->get('total_handling_sort_order')
|
||||
];
|
||||
|
||||
if ($this->config->get('total_handling_tax_class_id')) {
|
||||
$tax_rates = $this->tax->getRates((float)$this->config->get('total_handling_fee'), (int)$this->config->get('total_handling_tax_class_id'));
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if (!isset($taxes[$tax_rate['tax_rate_id']])) {
|
||||
$taxes[$tax_rate['tax_rate_id']] = $tax_rate['amount'];
|
||||
} else {
|
||||
$taxes[$tax_rate['tax_rate_id']] += $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$total += (float)$this->config->get('total_handling_fee');
|
||||
}
|
||||
}
|
||||
}
|
43
extension/opencart/catalog/model/total/low_order_fee.php
Normal file
43
extension/opencart/catalog/model/total/low_order_fee.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class LowOrderFee
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class LowOrderFee extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
if ($this->cart->getSubTotal() && ($this->cart->getSubTotal() < (float)$this->config->get('total_low_order_fee_total'))) {
|
||||
$this->load->language('extension/opencart/total/low_order_fee');
|
||||
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'low_order_fee',
|
||||
'title' => $this->language->get('text_low_order_fee'),
|
||||
'value' => (float)$this->config->get('total_low_order_fee_fee'),
|
||||
'sort_order' => (int)$this->config->get('total_low_order_fee_sort_order')
|
||||
];
|
||||
|
||||
if ($this->config->get('total_low_order_fee_tax_class_id')) {
|
||||
$tax_rates = $this->tax->getRates($this->config->get('total_low_order_fee_fee'), $this->config->get('total_low_order_fee_tax_class_id'));
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if (!isset($taxes[$tax_rate['tax_rate_id']])) {
|
||||
$taxes[$tax_rate['tax_rate_id']] = $tax_rate['amount'];
|
||||
} else {
|
||||
$taxes[$tax_rate['tax_rate_id']] += $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$total += $this->config->get('total_low_order_fee_fee');
|
||||
}
|
||||
}
|
||||
}
|
105
extension/opencart/catalog/model/total/reward.php
Normal file
105
extension/opencart/catalog/model/total/reward.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Reward
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Reward extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
if (isset($this->session->data['reward'])) {
|
||||
$this->load->language('extension/opencart/total/reward', 'reward');
|
||||
|
||||
$points = $this->customer->getRewardPoints();
|
||||
|
||||
if ($this->session->data['reward'] <= $points) {
|
||||
$discount_total = 0;
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
$points = min($points, $points_total);
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
$discount = 0;
|
||||
|
||||
if ($product['points']) {
|
||||
$discount = $product['total'] * ($this->session->data['reward'] / $points_total);
|
||||
|
||||
if ($product['tax_class_id']) {
|
||||
$tax_rates = $this->tax->getRates($product['total'] - ($product['total'] - $discount), $product['tax_class_id']);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if ($tax_rate['type'] == 'P') {
|
||||
$taxes[$tax_rate['tax_rate_id']] -= $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$discount_total += $discount;
|
||||
}
|
||||
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'reward',
|
||||
'title' => sprintf($this->language->get('reward_text_reward'), $this->session->data['reward']),
|
||||
'value' => -$discount_total,
|
||||
'sort_order' => (int)$this->config->get('total_reward_sort_order')
|
||||
];
|
||||
|
||||
$total -= $discount_total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $order_info
|
||||
* @param array $order_total
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function confirm(array $order_info, array $order_total): int {
|
||||
$this->load->language('extension/opencart/total/reward');
|
||||
|
||||
$points = 0;
|
||||
|
||||
$start = strpos($order_total['title'], '(') + 1;
|
||||
$end = strrpos($order_total['title'], ')');
|
||||
|
||||
if ($start && $end) {
|
||||
$points = substr($order_total['title'], $start, $end - $start);
|
||||
}
|
||||
|
||||
$this->load->model('account/customer');
|
||||
|
||||
if ($order_info['customer_id'] && $this->model_account_customer->getRewardTotal($order_info['customer_id']) >= $points) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_reward` SET `customer_id` = '" . (int)$order_info['customer_id'] . "', `order_id` = '" . (int)$order_info['order_id'] . "', `description` = '" . $this->db->escape(sprintf($this->language->get('text_order_id'), (int)$order_info['order_id'])) . "', `points` = '" . (float) - $points . "', `date_added` = NOW()");
|
||||
} else {
|
||||
return $this->config->get('config_fraud_status_id');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unconfirm(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_reward` WHERE `order_id` = '" . (int)$order_id . "' AND `points` < '0'");
|
||||
}
|
||||
}
|
41
extension/opencart/catalog/model/total/shipping.php
Normal file
41
extension/opencart/catalog/model/total/shipping.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Shipping
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Shipping extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
if ($this->cart->hasShipping() && isset($this->session->data['shipping_method'])) {
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'shipping',
|
||||
'title' => $this->session->data['shipping_method']['name'],
|
||||
'value' => $this->session->data['shipping_method']['cost'],
|
||||
'sort_order' => (int)$this->config->get('total_shipping_sort_order')
|
||||
];
|
||||
|
||||
if (isset($this->session->data['shipping_method']['tax_class_id'])) {
|
||||
$tax_rates = $this->tax->getRates($this->session->data['shipping_method']['cost'], $this->session->data['shipping_method']['tax_class_id']);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if (!isset($taxes[$tax_rate['tax_rate_id']])) {
|
||||
$taxes[$tax_rate['tax_rate_id']] = $tax_rate['amount'];
|
||||
} else {
|
||||
$taxes[$tax_rate['tax_rate_id']] += $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$total += $this->session->data['shipping_method']['cost'];
|
||||
}
|
||||
}
|
||||
}
|
37
extension/opencart/catalog/model/total/sub_total.php
Normal file
37
extension/opencart/catalog/model/total/sub_total.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class SubTotal
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class SubTotal extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
$this->load->language('extension/opencart/total/sub_total');
|
||||
|
||||
$sub_total = $this->cart->getSubTotal();
|
||||
|
||||
if (!empty($this->session->data['vouchers'])) {
|
||||
foreach ($this->session->data['vouchers'] as $voucher) {
|
||||
$sub_total += $voucher['amount'];
|
||||
}
|
||||
}
|
||||
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'sub_total',
|
||||
'title' => $this->language->get('text_sub_total'),
|
||||
'value' => $sub_total,
|
||||
'sort_order' => (int)$this->config->get('total_sub_total_sort_order')
|
||||
];
|
||||
|
||||
$total += $sub_total;
|
||||
}
|
||||
}
|
31
extension/opencart/catalog/model/total/tax.php
Normal file
31
extension/opencart/catalog/model/total/tax.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Tax
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Tax extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
foreach ($taxes as $key => $value) {
|
||||
if ($value > 0) {
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'tax',
|
||||
'title' => $this->tax->getRateName($key),
|
||||
'value' => $value,
|
||||
'sort_order' => (int)$this->config->get('total_tax_sort_order')
|
||||
];
|
||||
|
||||
$total += $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
extension/opencart/catalog/model/total/total.php
Normal file
27
extension/opencart/catalog/model/total/total.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Total
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Total extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
$this->load->language('extension/opencart/total/total');
|
||||
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'total',
|
||||
'title' => $this->language->get('text_total'),
|
||||
'value' => $total,
|
||||
'sort_order' => (int)$this->config->get('total_total_sort_order')
|
||||
];
|
||||
}
|
||||
}
|
85
extension/opencart/catalog/model/total/voucher.php
Normal file
85
extension/opencart/catalog/model/total/voucher.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Voucher extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $totals
|
||||
* @param array $taxes
|
||||
* @param float $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
||||
if (isset($this->session->data['voucher'])) {
|
||||
$this->load->language('extension/opencart/total/voucher', 'voucher');
|
||||
|
||||
$this->load->model('checkout/voucher');
|
||||
|
||||
$voucher_info = $this->model_checkout_voucher->getVoucher($this->session->data['voucher']);
|
||||
|
||||
if ($voucher_info) {
|
||||
$amount = min($voucher_info['amount'], $total);
|
||||
|
||||
if ($amount > 0) {
|
||||
$totals[] = [
|
||||
'extension' => 'opencart',
|
||||
'code' => 'voucher',
|
||||
'title' => sprintf($this->language->get('voucher_text_voucher'), $this->session->data['voucher']),
|
||||
'value' => -$amount,
|
||||
'sort_order' => (int)$this->config->get('total_voucher_sort_order')
|
||||
];
|
||||
|
||||
$total -= $amount;
|
||||
} else {
|
||||
unset($this->session->data['voucher']);
|
||||
}
|
||||
} else {
|
||||
unset($this->session->data['voucher']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $order_info
|
||||
* @param array $order_total
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function confirm(array $order_info, array $order_total): int {
|
||||
$code = '';
|
||||
|
||||
$start = strpos($order_total['title'], '(') + 1;
|
||||
$end = strrpos($order_total['title'], ')');
|
||||
|
||||
if ($start && $end) {
|
||||
$code = substr($order_total['title'], $start, $end - $start);
|
||||
}
|
||||
|
||||
if ($code) {
|
||||
$this->load->model('checkout/voucher');
|
||||
|
||||
$voucher_info = $this->model_checkout_voucher->getVoucher($code);
|
||||
|
||||
if ($voucher_info) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher_history` SET `voucher_id` = '" . (int)$voucher_info['voucher_id'] . "', `order_id` = '" . (int)$order_info['order_id'] . "', `amount` = '" . (float)$order_total['value'] . "', `date_added` = NOW()");
|
||||
} else {
|
||||
return $this->config->get('config_fraud_status_id');
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unconfirm(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher_history` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user