<?php
class CalculateTotal extends Calculate {
	function __construct(&$locator) {
		$this->cart     =& $locator->get('cart');
		$this->config   =& $locator->get('config');
		$this->currency =& $locator->get('currency');
		$this->language =& $locator->get('language');
		$this->coupon   =& $locator->get('coupon');
    	$this->language->load('extension/calculate/total.php');
    	$this->database =& $locator->get('database');
    	$this->customer  =& $locator->get('customer');
    	$this->payment   =& $locator->get('payment');
    	$this->session   =& $locator->get('session');
  	}
	
	function calculate() {
		
		$total_data = array();
		
		$customer_row=$this->database->getRow("select vip_rank from customer where customer_id='".(int)$this->customer->getId()."'");
	    $vip_row=$this->database->getRow("select discount from vip where vip_rank='".$customer_row['vip_rank']."'");
	    $dicount_pieces=explode('%',$vip_row['discount']);
		
		$usd_value=round($this->cart->getTotal()*(1-(int)$dicount_pieces[0]/100)+$this->session->get('shipping_cost'),2)-$this->coupon->getDiscount();
		
		   	   	$total_data[] = array(
		    		'title' => $this->language->get('text_total_title'), 
		    		'text'  => $this->currency->format($usd_value),
		    		'value' => $usd_value
		  		);
		 
		return $total_data;
  	}

	function getSortOrder() {
		return 4;
	}	
}
?>
