<?php
class ModelTotalShipping extends Model {
	public function getTotal(&$total_data, &$total) {
		if ($this->cart->hasShipping() && isset($this->session->data['shipping_method'])) {
            $isShippingFree = (boolean)Type_DsimDnao::Tp_Nao;

            if (isset($this->session->data['coupon'])){
                $this->load->model('checkout/coupon');
                $coupon_info = $this->model_checkout_coupon->getCoupon($this->session->data['coupon']);
                $isShippingFree = (int)$coupon_info['shipping']===(int)Type_DsimDnao::Tp_Sim;
                if($isShippingFree && $this->session->data['shipping_method']['cost']>0 ){

                    $this->session->data['shipping_method']['shipping_free_cost'] = $this->session->data['shipping_method']['cost'];
                    $this->session->data['shipping_method']['cost'] = 0;

                } else if ((!$isShippingFree) && ($this->session->data['shipping_method']['cost']==0) && (isset($this->session->data['shipping_method']['shipping_free_cost']))){
                    $this->session->data['shipping_method']['cost'] = $this->session->data['shipping_method']['shipping_free_cost'];
                }
            }

            $total_data[] = array(
                'code'       => 'shipping',
                'title'      => $this->session->data['shipping_method']['title'],
                'text'       => !$isShippingFree ? $this->session->data['shipping_method']['text'] : $this->currency->format(0),
                'value'      => !$isShippingFree ? $this->session->data['shipping_method']['cost'] : 0,
                'sort_order' => $this->config->get('shipping_sort_order')
            );
            $total += !$isShippingFree ? $this->session->data['shipping_method']['cost'] : 0;

		}
	}
}
