first commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalCoupon extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('total_coupon_status')) {
|
||||
$this->load->language('extension/total/coupon');
|
||||
|
||||
if (isset($this->session->data['coupon'])) {
|
||||
$data['coupon'] = $this->session->data['coupon'];
|
||||
} else {
|
||||
$data['coupon'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/coupon', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function coupon() {
|
||||
$this->load->language('extension/total/coupon');
|
||||
|
||||
$json = array();
|
||||
|
||||
$this->load->model('extension/total/coupon');
|
||||
|
||||
if (isset($this->request->post['coupon'])) {
|
||||
$coupon = $this->request->post['coupon'];
|
||||
} else {
|
||||
$coupon = '';
|
||||
}
|
||||
|
||||
$coupon_info = $this->model_extension_total_coupon->getCoupon($coupon);
|
||||
|
||||
if (empty($this->request->post['coupon'])) {
|
||||
$json['error'] = $this->language->get('error_empty');
|
||||
|
||||
unset($this->session->data['coupon']);
|
||||
} elseif ($coupon_info) {
|
||||
$this->session->data['coupon'] = $this->request->post['coupon'];
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_coupon');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalReward extends Controller {
|
||||
public function index() {
|
||||
$points = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($points && $points_total && $this->config->get('total_reward_status')) {
|
||||
$this->load->language('extension/total/reward');
|
||||
|
||||
$data['heading_title'] = sprintf($this->language->get('heading_title'), $points);
|
||||
|
||||
$data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
|
||||
|
||||
if (isset($this->session->data['reward'])) {
|
||||
$data['reward'] = $this->session->data['reward'];
|
||||
} else {
|
||||
$data['reward'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/reward', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function reward() {
|
||||
$this->load->language('extension/total/reward');
|
||||
|
||||
$json = array();
|
||||
|
||||
$points = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->request->post['reward']) || !is_numeric($this->request->post['reward']) || ($this->request->post['reward'] <= 0)) {
|
||||
$json['error'] = $this->language->get('error_reward');
|
||||
}
|
||||
|
||||
if ($this->request->post['reward'] > $points) {
|
||||
$json['error'] = sprintf($this->language->get('error_points'), $this->request->post['reward']);
|
||||
}
|
||||
|
||||
if ($this->request->post['reward'] > $points_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_maximum'), $points_total);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['reward'] = abs($this->request->post['reward']);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
if (isset($this->request->post['redirect'])) {
|
||||
$json['redirect'] = $this->url->link($this->request->post['redirect']);
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalShipping extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('total_shipping_status') && $this->config->get('total_shipping_estimator') && $this->cart->hasShipping()) {
|
||||
$this->load->language('extension/total/shipping');
|
||||
|
||||
if (isset($this->session->data['shipping_address']['country_id'])) {
|
||||
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
|
||||
} else {
|
||||
$data['country_id'] = $this->config->get('config_country_id');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
if (isset($this->session->data['shipping_address']['zone_id'])) {
|
||||
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
|
||||
} else {
|
||||
$data['zone_id'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_address']['postcode'])) {
|
||||
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
|
||||
} else {
|
||||
$data['postcode'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_method'])) {
|
||||
$data['shipping_method'] = $this->session->data['shipping_method']['code'];
|
||||
} else {
|
||||
$data['shipping_method'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/shipping', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function quote() {
|
||||
$this->load->language('extension/total/shipping');
|
||||
|
||||
$json = array();
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
if ($this->request->post['country_id'] == '') {
|
||||
$json['error']['country'] = $this->language->get('error_country');
|
||||
}
|
||||
|
||||
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) {
|
||||
$json['error']['zone'] = $this->language->get('error_zone');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
|
||||
|
||||
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
|
||||
$json['error']['postcode'] = $this->language->get('error_postcode');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->tax->setShippingAddress($this->request->post['country_id'], $this->request->post['zone_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($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'] = array(
|
||||
'firstname' => '',
|
||||
'lastname' => '',
|
||||
'company' => '',
|
||||
'address_1' => '',
|
||||
'address_2' => '',
|
||||
'postcode' => $this->request->post['postcode'],
|
||||
'city' => '',
|
||||
'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,
|
||||
'address_format' => $address_format
|
||||
);
|
||||
|
||||
$quote_data = array();
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getExtensions('shipping');
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($this->config->get('shipping_' . $result['code'] . '_status')) {
|
||||
if (!is_file(DIR_APPLICATION . 'model/extension/shipping/' . $result['code'] . '.php')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->load->model('extension/shipping/' . $result['code']);
|
||||
|
||||
$quote = $this->{'model_extension_shipping_' . $result['code']}->getQuote($this->session->data['shipping_address']);
|
||||
|
||||
if ($quote) {
|
||||
$quote_data[$result['code']] = array(
|
||||
'title' => $quote['title'],
|
||||
'quote' => $quote['quote'],
|
||||
'sort_order' => $quote['sort_order'],
|
||||
'error' => $quote['error']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($quote_data as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $quote_data);
|
||||
|
||||
$this->session->data['shipping_methods'] = $quote_data;
|
||||
|
||||
if ($this->session->data['shipping_methods']) {
|
||||
$json['shipping_method'] = $this->session->data['shipping_methods'];
|
||||
} else {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function shipping() {
|
||||
$this->load->language('extension/total/shipping');
|
||||
|
||||
$json = array();
|
||||
|
||||
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['warning'] = $this->language->get('error_shipping');
|
||||
}
|
||||
} else {
|
||||
$json['warning'] = $this->language->get('error_shipping');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$shipping = explode('.', $this->request->post['shipping_method']);
|
||||
|
||||
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function country() {
|
||||
$json = array();
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
|
||||
|
||||
if ($country_info) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$json = array(
|
||||
'country_id' => $country_info['country_id'],
|
||||
'name' => $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'],
|
||||
'postcode_required' => $country_info['postcode_required'],
|
||||
'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
|
||||
'status' => $country_info['status']
|
||||
);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalVoucher extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('total_voucher_status')) {
|
||||
$this->load->language('extension/total/voucher');
|
||||
|
||||
if (isset($this->session->data['voucher'])) {
|
||||
$data['voucher'] = $this->session->data['voucher'];
|
||||
} else {
|
||||
$data['voucher'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/voucher', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function voucher() {
|
||||
$this->load->language('extension/total/voucher');
|
||||
|
||||
$json = array();
|
||||
|
||||
$this->load->model('extension/total/voucher');
|
||||
|
||||
if (isset($this->request->post['voucher'])) {
|
||||
$voucher = $this->request->post['voucher'];
|
||||
} else {
|
||||
$voucher = '';
|
||||
}
|
||||
|
||||
$voucher_info = $this->model_extension_total_voucher->getVoucher($voucher);
|
||||
|
||||
if (empty($this->request->post['voucher'])) {
|
||||
$json['error'] = $this->language->get('error_empty');
|
||||
} elseif ($voucher_info) {
|
||||
$this->session->data['voucher'] = $this->request->post['voucher'];
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_voucher');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function send($route, $args, $output) {
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($args[0]);
|
||||
|
||||
// If order status in the complete range create any vouchers that where in the order need to be made available.
|
||||
if (in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) {
|
||||
$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.order_id = '" . (int)$order_info['order_id'] . "' AND vtd.language_id = '" . (int)$order_info['language_id'] . "'");
|
||||
|
||||
if ($voucher_query->num_rows) {
|
||||
// Send out any gift voucher mails
|
||||
$language = new Language($order_info['language_code']);
|
||||
$language->load($order_info['language_code']);
|
||||
$language->load('mail/voucher');
|
||||
|
||||
foreach ($voucher_query->rows as $voucher) {
|
||||
// HTML Mail
|
||||
$data = array();
|
||||
|
||||
$data['title'] = sprintf($language->get('text_subject'), $voucher['from_name']);
|
||||
|
||||
$data['text_greeting'] = sprintf($language->get('text_greeting'), $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']));
|
||||
$data['text_from'] = sprintf($language->get('text_from'), $voucher['from_name']);
|
||||
$data['text_message'] = $language->get('text_message');
|
||||
$data['text_redeem'] = sprintf($language->get('text_redeem'), $voucher['code']);
|
||||
$data['text_footer'] = $language->get('text_footer');
|
||||
|
||||
if (is_file(DIR_IMAGE . $voucher['image'])) {
|
||||
$data['image'] = $this->config->get('config_url') . 'image/' . $voucher['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$data['store_name'] = $order_info['store_name'];
|
||||
$data['store_url'] = $order_info['store_url'];
|
||||
$data['message'] = nl2br($voucher['message']);
|
||||
|
||||
$mail = new Mail($this->config->get('config_mail_engine'));
|
||||
$mail->parameter = $this->config->get('config_mail_parameter');
|
||||
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
|
||||
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
|
||||
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
|
||||
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
|
||||
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
|
||||
|
||||
$mail->setTo($voucher['to_email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setSubject(html_entity_decode(sprintf($language->get('text_subject'), $voucher['from_name']), ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setHtml($this->load->view('mail/voucher', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user