<?php
class ModelTotalGiftTeaser extends Model {
  public function getTotal(&$total_data, &$total, &$taxes) {
    $this->language->load('total/gift_teaser');

    $this->load->model('module/giftTeaser');
    $setting = $this->model_module_giftTeaser->getSetting('giftTeaser', $this->config->get('store_id'));

    if($setting['giftTeaser']['Enabled'] && $setting['giftTeaser']['Enabled'] == 'yes' ) {
      $amount = 0;

      $title = $this->language->get('text_gift_teaser');
      $text_refresh_gifts = $this->language->get('text_refresh_gifts');

      if (!empty($this->session->data['gift_teaser_exclude'])) {

        if (!empty($this->request->get['route']) && $this->request->get['route'] == 'module/cart') {
          $title .= ' (<a onclick="jQuery.ajax({url:\'index.php?route=module/giftTeaser/refresh_gifts\', success: function() { location = location; }});">' . $text_refresh_gifts . '</a>)';
        } else if (!empty($this->request->get['route']) && stripos($this->request->get['route'], 'cart') !== false) {
          $title .= ' (<a onclick="jQuery.ajax({url:\'index.php?route=module/giftTeaser/refresh_gifts\', success: function() { location = location; }});">' . $text_refresh_gifts . '</a>)';
        }

      }

      $cart_products = $this->cart->getProducts();
	  $show = false;
      foreach ($cart_products as $key => $cart_product) {
        if (!empty($cart_product['gift_teaser'])) {
          $amount += $cart_product['quantity'] * (float)$this->tax->calculate($cart_product['real_price'], $cart_product['real_tax_class_id'], $this->config->get('config_tax'));
	      $show = true;
        }
      }
		if ($show==true || !empty($this->session->data['gift_teaser_exclude'])) {
		  $total_data[] = array(
			'code'       => 'gift_teaser',
			'title'      => $title,
			'text'       => '' . $this->currency->format($amount),
			'value'      => 0,
			'sort_order' => $this->config->get('gift_teaser_sort_order')
		  );
	
		  
		}
    }
  }

}
?>