first commit
This commit is contained in:
79
extension/opencart/catalog/controller/total/coupon.php
Normal file
79
extension/opencart/catalog/controller/total/coupon.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Coupon extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_coupon_status')) {
|
||||
$this->load->language('extension/opencart/total/coupon');
|
||||
|
||||
$data['save'] = $this->url->link('extension/opencart/total/coupon.save', 'language=' . $this->config->get('config_language'), true);
|
||||
$data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
if (isset($this->session->data['coupon'])) {
|
||||
$data['coupon'] = $this->session->data['coupon'];
|
||||
} else {
|
||||
$data['coupon'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/total/coupon', $data);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/coupon');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['coupon'])) {
|
||||
$coupon = $this->request->post['coupon'];
|
||||
} else {
|
||||
$coupon = '';
|
||||
}
|
||||
|
||||
if (!$this->config->get('total_coupon_status')) {
|
||||
$json['error'] = $this->language->get('error_status');
|
||||
}
|
||||
|
||||
if ($coupon) {
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$coupon_info = $this->model_marketing_coupon->getCoupon($coupon);
|
||||
|
||||
if (!$coupon_info) {
|
||||
$json['error'] = $this->language->get('error_coupon');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($coupon) {
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$this->session->data['coupon'] = $coupon;
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
|
||||
unset($this->session->data['coupon']);
|
||||
}
|
||||
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
103
extension/opencart/catalog/controller/total/reward.php
Normal file
103
extension/opencart/catalog/controller/total/reward.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Reward
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Reward extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_reward_status')) {
|
||||
$available = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($available && $points_total) {
|
||||
$this->load->language('extension/opencart/total/reward');
|
||||
|
||||
$data['heading_title'] = sprintf($this->language->get('heading_title'), $available);
|
||||
|
||||
$data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
|
||||
|
||||
$data['save'] = $this->url->link('extension/opencart/total/reward.save', 'language=' . $this->config->get('config_language'), true);
|
||||
$data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
if (isset($this->session->data['reward'])) {
|
||||
$data['reward'] = $this->session->data['reward'];
|
||||
} else {
|
||||
$data['reward'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/total/reward', $data);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/reward');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['reward'])) {
|
||||
$reward = abs((int)$this->request->post['reward']);
|
||||
} else {
|
||||
$reward = 0;
|
||||
}
|
||||
|
||||
$available = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->config->get('total_reward_status')) {
|
||||
$json['error'] = $this->language->get('error_reward');
|
||||
}
|
||||
|
||||
if ($reward > $available) {
|
||||
$json['error'] = sprintf($this->language->get('error_points'), $reward);
|
||||
}
|
||||
|
||||
if ($reward > $points_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_maximum'), $points_total);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($reward) {
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$this->session->data['reward'] = $reward;
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
|
||||
unset($this->session->data['reward']);
|
||||
}
|
||||
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
172
extension/opencart/catalog/controller/total/shipping.php
Normal file
172
extension/opencart/catalog/controller/total/shipping.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Shipping
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Shipping extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_shipping_status') && $this->config->get('total_shipping_estimator') && $this->cart->hasShipping()) {
|
||||
$this->load->language('extension/opencart/total/shipping');
|
||||
|
||||
if (isset($this->session->data['shipping_address'])) {
|
||||
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
|
||||
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
|
||||
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
|
||||
} else {
|
||||
$data['postcode'] = '';
|
||||
$data['country_id'] = (int)$this->config->get('config_country_id');
|
||||
$data['zone_id'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_method'])) {
|
||||
$data['code'] = $this->session->data['shipping_method']['code'];
|
||||
} else {
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('extension/opencart/total/shipping', $data);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function quote(): void {
|
||||
$this->load->language('extension/opencart/total/shipping');
|
||||
|
||||
$json = [];
|
||||
|
||||
$keys = [
|
||||
'postcode',
|
||||
'country_id',
|
||||
'zone_id'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->cart->hasProducts()) {
|
||||
$json['error']['warning'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if (!$this->cart->hasShipping()) {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry((int)$this->request->post['country_id']);
|
||||
|
||||
if ($country_info && $country_info['postcode_required'] && (oc_strlen($this->request->post['postcode']) < 2 || oc_strlen($this->request->post['postcode']) > 10)) {
|
||||
$json['error']['postcode'] = $this->language->get('error_postcode');
|
||||
}
|
||||
|
||||
if ($this->request->post['country_id'] == '') {
|
||||
$json['error']['country'] = $this->language->get('error_country');
|
||||
}
|
||||
|
||||
if ($this->request->post['zone_id'] == '') {
|
||||
$json['error']['zone'] = $this->language->get('error_zone');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
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($this->request->post['zone_id']);
|
||||
|
||||
if ($zone_info) {
|
||||
$zone = $zone_info['name'];
|
||||
$zone_code = $zone_info['code'];
|
||||
} else {
|
||||
$zone = '';
|
||||
$zone_code = '';
|
||||
}
|
||||
|
||||
$this->session->data['shipping_address'] = [
|
||||
'postcode' => $this->request->post['postcode'],
|
||||
'zone_id' => $this->request->post['zone_id'],
|
||||
'zone' => $zone,
|
||||
'zone_code' => $zone_code,
|
||||
'country_id' => $this->request->post['country_id'],
|
||||
'country' => $country,
|
||||
'iso_code_2' => $iso_code_2,
|
||||
'iso_code_3' => $iso_code_3
|
||||
];
|
||||
|
||||
$this->tax->setShippingAddress($this->request->post['country_id'], $this->request->post['zone_id']);
|
||||
|
||||
// Shipping Methods
|
||||
$this->load->model('checkout/shipping_method');
|
||||
|
||||
$shipping_methods = $this->model_checkout_shipping_method->getMethods($this->session->data['shipping_address']);
|
||||
|
||||
if ($shipping_methods) {
|
||||
$json['shipping_methods'] = $this->session->data['shipping_methods'] = $shipping_methods;
|
||||
} else {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/shipping');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!empty($this->request->post['shipping_method'])) {
|
||||
$shipping = explode('.', $this->request->post['shipping_method']);
|
||||
|
||||
if (!isset($shipping[0]) || !isset($shipping[1]) || !isset($this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {
|
||||
$json['error'] = $this->language->get('error_shipping');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_shipping');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
79
extension/opencart/catalog/controller/total/voucher.php
Normal file
79
extension/opencart/catalog/controller/total/voucher.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Voucher extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_voucher_status')) {
|
||||
$this->load->language('extension/opencart/total/voucher');
|
||||
|
||||
$data['save'] = $this->url->link('extension/opencart/total/voucher.save', 'language=' . $this->config->get('config_language'), true);
|
||||
$data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
if (isset($this->session->data['voucher'])) {
|
||||
$data['voucher'] = $this->session->data['voucher'];
|
||||
} else {
|
||||
$data['voucher'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/total/voucher', $data);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/voucher');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['voucher'])) {
|
||||
$voucher = (string)$this->request->post['voucher'];
|
||||
} else {
|
||||
$voucher = '';
|
||||
}
|
||||
|
||||
if (!$this->config->get('total_voucher_status')) {
|
||||
$json['error'] = $this->language->get('error_status');
|
||||
}
|
||||
|
||||
if ($voucher) {
|
||||
$this->load->model('checkout/voucher');
|
||||
|
||||
$voucher_info = $this->model_checkout_voucher->getVoucher($voucher);
|
||||
|
||||
if (!$voucher_info) {
|
||||
$json['error'] = $this->language->get('error_voucher');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($voucher) {
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$this->session->data['voucher'] = $voucher;
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
|
||||
unset($this->session->data['voucher']);
|
||||
}
|
||||
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user