shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

klarna_invoice.php (2678B)


      1 <?php
      2 class ModelExtensionPaymentKlarnaInvoice extends Model {
      3 	public function getMethod($address, $total) {
      4 		$this->load->language('extension/payment/klarna_invoice');
      5 
      6 		$status = true;
      7 
      8 		$klarna_invoice = $this->config->get('payment_klarna_invoice');
      9 
     10 		if (!isset($klarna_invoice[$address['iso_code_3']])) {
     11 			$status = false;
     12 		} elseif (!$klarna_invoice[$address['iso_code_3']]['status']) {
     13 			$status = false;
     14 		}
     15 
     16 		if ($status) {
     17 			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$klarna_invoice[$address['iso_code_3']]['geo_zone_id'] . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
     18 
     19 			if ($klarna_invoice[$address['iso_code_3']]['total'] > 0 && $klarna_invoice[$address['iso_code_3']]['total'] > $total) {
     20 				$status = false;
     21 			} elseif (!$klarna_invoice[$address['iso_code_3']]['geo_zone_id']) {
     22 				$status = true;
     23 			} elseif ($query->num_rows) {
     24 				$status = true;
     25 			} else {
     26 				$status = false;
     27 			}
     28 
     29 			// Maps countries to currencies
     30 			$country_to_currency = array(
     31 				'NOR' => 'NOK',
     32 				'SWE' => 'SEK',
     33 				'FIN' => 'EUR',
     34 				'DNK' => 'DKK',
     35 				'DEU' => 'EUR',
     36 				'NLD' => 'EUR',
     37 			);
     38 
     39 			if (!isset($country_to_currency[$address['iso_code_3']]) || !$this->currency->has($country_to_currency[$address['iso_code_3']])) {
     40 				$status = false;
     41 			}
     42 		}
     43 
     44 		$method = array();
     45 
     46 		if ($status) {
     47 			$klarna_fee = $this->config->get('total_klarna_fee');
     48 
     49 			if ($klarna_fee[$address['iso_code_3']]['status'] && $this->cart->getSubTotal() < $klarna_fee[$address['iso_code_3']]['total']) {
     50 				$terms = sprintf($this->language->get('text_terms_fee'), $this->currency->format($this->tax->calculate($klarna_fee[$address['iso_code_3']]['fee'], $klarna_fee[$address['iso_code_3']]['tax_class_id']), $this->session->data['currency'], ''), $klarna_invoice[$address['iso_code_3']]['merchant'], strtolower($address['iso_code_2']), $this->currency->format($this->tax->calculate($klarna_fee[$address['iso_code_3']]['fee'], $klarna_fee[$address['iso_code_3']]['tax_class_id']), $country_to_currency[$address['iso_code_3']], '', false));
     51 			} else {
     52 				$terms = sprintf($this->language->get('text_terms_no_fee'), $klarna_invoice[$address['iso_code_3']]['merchant'], strtolower($address['iso_code_2']));
     53 			}
     54 
     55 			$method = array(
     56 				'code'       => 'klarna_invoice',
     57 				'title'      => $this->language->get('text_title'),
     58 				'terms'      => $terms,
     59 				'sort_order' => $klarna_invoice[$address['iso_code_3']]['sort_order']
     60 			);
     61 		}
     62 
     63 		return $method;
     64 	}
     65 }