Location: PHPKode > projects > HikaShop > front/controllers/order.php
<?php
/**
 * @package		HikaShop for Joomla!
 * @version		1.4.3
 * @author		hikashop.com
 * @copyright	(C) 2010 HIKARI SOFTWARE. All rights reserved.
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php
class orderController extends hikashopController{
	function __construct($config = array()){
		parent::__construct($config);
		$this->display[]='cancel';
		$this->display[]='invoice';
		$this->display[]='download';
		$this->display[]='pay';
		$this->display[]='cancel_order';
	}
	function authorize($task){
		if($this->isIn($task,array('display'))){
			return true;
		}
		return false;
	}
	function listing(){
		$user_id = hikashop::loadUser();
		if(empty($user_id)){
			$app=&JFactory::getApplication();
			$app->enqueueMessage(JText::_('PLEASE_LOGIN_FIRST'));
			return true;
		}
		return parent::listing();
	}
	function show(){
		if($this->_check()){
			return parent::show();
		}
		return true;
	}
	function cancel_order(){
		$order_id = hikashop::getCID('order_id');
		$class = hikashop::get('class.order');
		$order = $class->get($order_id);
		$cancel_url =  hikashop::completeLink('checkout',false,true);
		if(!empty($order)){
			$user_id = hikashop::loadUser();
			if($order->order_user_id==$user_id){
				$config =& hikashop::config();
				$status = $config->get('cancelled_order_status');
				if(!empty($status)){
					$statuses = explode(',',$status);
					$newOrder = null;
					$newOrder->order_status = reset($statuses);
					$newOrder->order_id = $order_id;
					$class->save($newOrder);
				}
			}
			$db =& JFactory::getDBO();
			$query = 'SELECT * FROM '.hikashop::table('payment').' WHERE payment_type='.$db->Quote($order->order_payment_method).' AND payment_id='.$db->Quote($order->order_payment_id);
			$db->setQuery($query);
			$paymentData = $db->loadObjectList();
			$pluginsClass = hikashop::get('class.plugins');
			$pluginsClass->params($paymentData,'payment');
			$paymentOptions=reset($paymentData);
			if(!empty($paymentOptions->payment_params->cancel_url)){
				$cancel_url = $paymentOptions->payment_params->cancel_url;
			}
		}
		$app =& JFactory::getApplication();
		$app->redirect($cancel_url);
		return true;
	}
	function invoice(){
		if($this->_check()){
			JRequest::setVar( 'layout', 'invoice'  );
			return parent::display();
		}
		return true;
	}
	function pay(){
		$order_id = hikashop::getCID('order_id');
		if(empty($order_id)){
			parent::listing();
			return false;
		}
		$class = hikashop::get('class.order');
		$order = $class->loadFullOrder($order_id,true);
		if(empty($order)){
			$app =& JFactory::getApplication();
			$app->enqueueMessage('The order '.$order_id.' could not be found');
			parent::listing();
			return false;
		}
		$userClass = hikashop::get('class.user');
		$order->customer = $userClass->get($order->order_user_id);
		$db =& JFactory::getDBO();
		$query = 'SELECT * FROM '.hikashop::table('payment').' WHERE payment_type='.$db->Quote($order->order_payment_method);
		$db->setQuery($query);
		$paymentData = $db->loadObjectList('payment_id');
		$pluginsClass = hikashop::get('class.plugins');
		$pluginsClass->params($paymentData,'payment');
		if(empty($paymentData)){
			$app =& JFactory::getApplication();
			$app->enqueueMessage('The payment method '.$order->order_payment_method.' could not be found');
			parent::listing();
			return false;
		}
		$order->cart =& $order;
		$order->cart->coupon = null;
		$price = null;
		$price->price_value_with_tax = $order->order_full_price; 
		$order->cart->full_total = array($price);
		$order->cart->coupon->discount_value =& $order->order_discount_price;
		ob_start();
		$data = hikashop::import('hikashoppayment',$order->order_payment_method);
		$data->onAfterOrderConfirm($order,$paymentData,$order->order_payment_id);
		$html = ob_get_clean();
		if(empty($html)){
			$app =& JFactory::getApplication();
			$app->enqueueMessage('The payment method '.$order->order_payment_method.' does not handle payments after he order has been created');
			parent::listing();
			return false;
		}
		echo $html;
		return true;
	}
	function download(){
		$file_id = JRequest::getInt('file_id');
		if(empty($file_id)){
			$field_table = JRequest::getWord('field_table');
			$field_namekey = JRequest::getString('field_namekey');
			$name = JRequest::getString('name');
			if(empty($field_table)||empty($field_namekey)||empty($name)){
				$app=&JFactory::getApplication();
				$app->enqueueMessage(JText::_('FILE_NOT_FOUND'));
				return false;
			}else{
				$fileClass = hikashop::get('class.file');
				$fileClass->downloadFieldFile($name,$field_table,$field_namekey);
			}
		}
		$order_id = hikashop::getCID('order_id');
		if(empty($order_id)){
			parent::listing();
			return false;
		}
		$fileClass = hikashop::get('class.file');
		$fileClass->download($file_id,$order_id);
		return true;
	}
	function _check(){
		$user_id = hikashop::loadUser();
		if(empty($user_id)){
			$app=&JFactory::getApplication();
			$app->enqueueMessage(JText::_('PLEASE_LOGIN_FIRST'));
			return false;
		}
		$order_id = hikashop::getCID('order_id');
		if(empty($order_id)){
			parent::listing();
			return false;
		}
		return true;
	}
	function cancel(){
		$cancel_redirect = JRequest::getString('cancel_redirect');
		if(empty($cancel_redirect)){
			$order_id = hikashop::getCID('order_id');
			if(empty($order_id)){
				global $Itemid;
				$url = '';
				if(!empty($Itemid)){
					$url='&Itemid='.$Itemid;
				}
				$this->setRedirect(hikashop::completeLink('user'.$url,false,true));
			}else{
				return $this->listing();
			}
		}else{
			$this->setRedirect(urldecode($cancel_redirect));
		}
	}
}
Return current item: HikaShop