shop.balmet.com

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

divido_calculator.php (2036B)


      1 <?php
      2 class ControllerExtensionModuleDividoCalculator extends Controller {
      3 	public function index() {
      4 		$this->load->language('extension/module/divido_calculator');
      5 		$this->load->model('extension/payment/divido');
      6 		$this->load->model('catalog/product');
      7 
      8 		$product_selection = $this->config->get('payment_divido_productselection');
      9 		$product_threshold = $this->config->get('payment_divido_price_threshold');
     10 
     11 		if (!isset($this->request->get['product_id']) || !$this->config->get('payment_divido_status') || !$this->config->get('module_divido_calculator_status')) {
     12 			return false;
     13 		}
     14 
     15 		$product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
     16 
     17 		$price = 0;
     18 		if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
     19 			$base_price = !empty($product_info['special']) ? $product_info['special'] : $product_info['price'];
     20 			$price = $this->tax->calculate($base_price, $product_info['tax_class_id'], $this->config->get('config_tax'));
     21 		}
     22 
     23 		if ($product_selection == 'threshold' && $product_threshold > $price) {
     24 			return false;
     25 		}
     26 
     27 		$api_key = $this->config->get('payment_divido_api_key');
     28 		$key_parts = explode('.', $api_key);
     29 		$js_key = strtolower(array_shift($key_parts));
     30 
     31 		$this->model_extension_payment_divido->setMerchant($api_key);
     32 		$plans = $this->model_extension_payment_divido->getProductPlans($this->request->get['product_id']);
     33 
     34 		if (!$plans) {
     35 			return false;
     36 		}
     37 
     38 		$plans_ids = array_map(function ($plan) {
     39 			return $plan->id;
     40 		}, $plans);
     41 		$plans_ids = array_unique($plans_ids);
     42 		$plans_list = implode(',', $plans_ids);
     43 
     44 		$data = array(
     45 			'merchant_script'			=> "//cdn.divido.com/calculator/{$js_key}.js",
     46 			'product_price'				=> $price,
     47 			'plan_list'					=> $plans_list,
     48 			'generic_credit_req_error'	=> 'Credit request could not be initiated',
     49 		);
     50 
     51 		return $this->load->view('extension/module/divido_calculator', $data);
     52 	}
     53 }