PageRenderTime 74ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website bán mỹ phẩm PHP/administrator/components/com_virtuemart/controllers/orders.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 325 lines | 137 code | 59 blank | 129 comment | 16 complexity | 130e52054e6e58463814786993b1abf4 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * Orders controller
  5. *
  6. * @package VirtueMart
  7. * @subpackage
  8. * @author RolandD
  9. * @link http://www.virtuemart.net
  10. * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  12. * VirtueMart is free software. This version may have been modified pursuant
  13. * to the GNU General Public License, and as distributed it includes or
  14. * is derivative of works licensed under the GNU General Public License or
  15. * other free or open source software licenses.
  16. * @version $Id: orders.php 6188 2012-06-29 09:38:30Z Milbo $
  17. */
  18. // Check to ensure this file is included in Joomla!
  19. defined('_JEXEC') or die('Restricted access');
  20. // Load the controller framework
  21. jimport('joomla.application.component.controller');
  22. if(!class_exists('VmController'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmcontroller.php');
  23. /**
  24. * Orders Controller
  25. *
  26. * @package VirtueMart
  27. * @author
  28. */
  29. class VirtuemartControllerOrders extends VmController {
  30. /**
  31. * Method to display the view
  32. *
  33. * @access public
  34. * @author
  35. */
  36. function __construct() {
  37. parent::__construct();
  38. }
  39. /**
  40. * Shows the order details
  41. */
  42. public function edit($layout='order'){
  43. parent::edit($layout);
  44. }
  45. /**
  46. * NextOrder
  47. * TODO rename, the name is ambigous notice by Max Milbers
  48. * @author Kohl Patrick
  49. */
  50. public function next($dir = 'ASC'){
  51. $model = VmModel::getModel('orders');
  52. $id = JRequest::getInt('virtuemart_order_id');
  53. if (!$order_id = $model->getOrderId($dir,$id)) {
  54. $order_id = $id;
  55. $msg = JText::_('COM_VIRTUEMART_NO_MORE_ORDERS');
  56. } else {
  57. $msg ='';
  58. }
  59. $this->setRedirect('index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id='.$order_id ,$msg );
  60. }
  61. /**
  62. * NextOrder
  63. * TODO rename, the name is ambigous notice by Max Milbers
  64. * @author Kohl Patrick
  65. */
  66. public function prev(){
  67. $this->next('DESC');
  68. }
  69. /**
  70. * Generic cancel task
  71. *
  72. * @author Max Milbers
  73. */
  74. public function cancel(){
  75. // back from order
  76. $this->setRedirect('index.php?option=com_virtuemart&view=orders' );
  77. }
  78. /**
  79. * Shows the order details
  80. * @deprecated
  81. */
  82. public function editOrderStatus() {
  83. /* Create the view object */
  84. $view = $this->getView('orders', 'html');
  85. /* Default model */
  86. $model = VmModel::getModel('orders');
  87. $model->updateOrderStatus();
  88. /* Now display the view. */
  89. $view->display();
  90. }
  91. /**
  92. * Update an order status
  93. *
  94. * @author RolandD
  95. */
  96. public function updatestatus() {
  97. //vmdebug('updatestatus');
  98. $mainframe = Jfactory::getApplication();
  99. $lastTask = JRequest::getWord('last_task');
  100. /* Load the view object */
  101. $view = $this->getView('orders', 'html');
  102. /* Load the helper */
  103. $view->loadHelper('vendorHelper');
  104. /* Update the statuses */
  105. $model = VmModel::getModel('orders');
  106. if ($lastTask == 'updatestatus') {
  107. // single order is in POST but we need an array
  108. $order = array() ;
  109. $virtuemart_order_id = JRequest::getInt('virtuemart_order_id');
  110. $order[$virtuemart_order_id] = (JRequest::get('post'));
  111. //vmdebug( 'order',$order);
  112. $result = $model->updateOrderStatus($order);
  113. } else {
  114. $result = $model->updateOrderStatus();
  115. }
  116. $msg='';
  117. if ($result['updated'] > 0)
  118. $msg = JText::sprintf('COM_VIRTUEMART_ORDER_UPDATED_SUCCESSFULLY', $result['updated'] );
  119. else if ($result['error'] == 0)
  120. $msg .= JText::_('COM_VIRTUEMART_ORDER_NOT_UPDATED');
  121. if ($result['error'] > 0)
  122. $msg .= JText::sprintf('COM_VIRTUEMART_ORDER_NOT_UPDATED_SUCCESSFULLY', $result['error'] , $result['total']);
  123. if ('updatestatus'== $lastTask ) {
  124. $mainframe->redirect('index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id='.$virtuemart_order_id , $msg);
  125. }
  126. else {
  127. $mainframe->redirect('index.php?option=com_virtuemart&view=orders', $msg);
  128. }
  129. }
  130. /**
  131. * Save changes to the order item status
  132. *
  133. */
  134. public function saveItemStatus() {
  135. //vmdebug('saveItemStatus');
  136. $mainframe = Jfactory::getApplication();
  137. /* Load the view object */
  138. $view = $this->getView('orders', 'html');
  139. /* Load the helper */
  140. $view->loadHelper('vendorHelper');
  141. $data = JRequest::get('post');
  142. $model = VmModel::getModel();
  143. $model->updateItemStatus(JArrayHelper::toObject($data), $data['new_status']);
  144. $mainframe->redirect('index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id='.$data['virtuemart_order_id']);
  145. }
  146. /**
  147. * Display the order item details for editing
  148. */
  149. public function editOrderItem() {
  150. //vmdebug('editOrderItem');
  151. JRequest::setVar('layout', 'orders_editorderitem');
  152. // JRequest::setVar('hidemenu', 1);
  153. parent::display();
  154. }
  155. /**
  156. * correct position, working with json? actually? WHat ist that?
  157. *
  158. * Get a list of related products
  159. * @author RolandD
  160. */
  161. public function getProducts() {
  162. /* Create the view object */
  163. $view = $this->getView('orders', 'json');
  164. $view->setLayout('orders_editorderitem');
  165. /* Now display the view. */
  166. $view->display();
  167. }
  168. /**
  169. * Update status for the selected order items
  170. */
  171. public function updateOrderItemStatus()
  172. {
  173. //vmdebug('updateOrderItemStatus');
  174. $mainframe = Jfactory::getApplication();
  175. $model = VmModel::getModel();
  176. $_items = JRequest::getVar('item_id', 0, '', 'array');
  177. //JArrayHelper::toInteger($_items);
  178. $_orderID = JRequest::getInt('virtuemart_order_id', '');
  179. foreach ($_items as $key=>$value) {
  180. //vmdebug('updateOrderItemStatus VAL ',$value);
  181. if (!isset($value['comments'])) $value['comments'] = '';
  182. $data = (object)$value;
  183. $data->virtuemart_order_id = $_orderID;
  184. // $model->updateSingleItem((int)$key, $value['order_status'],$value['comments'],$_orderID);
  185. $model->updateSingleItem((int)$key, $data);
  186. }
  187. $mainframe->redirect('index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id='.$_orderID);
  188. }
  189. /**
  190. * Update a single order item
  191. public function updateOrderItem()
  192. {
  193. //vmdebug('updateOrderItem');
  194. $mainframe = Jfactory::getApplication();
  195. $model = VmModel::getModel('orders');
  196. // $model->updateSingleItem();
  197. $mainframe->redirect('index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id='.JRequest::getInt('virtuemart_order_id', ''));
  198. }
  199. */
  200. /**
  201. * Save the given order item
  202. */
  203. public function saveOrderItem() {
  204. //vmdebug('saveOrderItem');
  205. $orderId = JRequest::getInt('virtuemart_order_id', '');
  206. $model = VmModel::getModel();
  207. $msg = '';
  208. $data = JRequest::get('post');
  209. if (!$model->saveOrderLineItem()) {
  210. $msg = $model->getError();
  211. }
  212. $editLink = 'index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id=' . $orderId;
  213. $this->setRedirect($editLink, $msg);
  214. }
  215. /**
  216. * Removes the given order item
  217. */
  218. public function removeOrderItem() {
  219. //vmdebug('removeOrderItem');
  220. $model = VmModel::getModel();
  221. $msg = '';
  222. $orderId = JRequest::getInt('orderId', '');
  223. // TODO $orderLineItem as int ???
  224. $orderLineItem = JRequest::getVar('orderLineId', '');
  225. if (!$model->removeOrderLineItem($orderLineItem)) {
  226. $msg = $model->getError();
  227. }
  228. $editLink = 'index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id=' . $orderId;
  229. $this->setRedirect($editLink, $msg);
  230. }
  231. public function exportOrdersAsCSV(){
  232. $model = VmModel::getModel();
  233. $idArray = JRequest::getVar('cid', 0, '', 'array');
  234. $orders = array();
  235. foreach($idArray as $orderId){
  236. $orders[] = $model -> getOrder($orderId);
  237. }
  238. $csv = '';
  239. $head = array('virtuemart_order_userinfo_id','virtuemart_vendor_id','order_number','order_total','order_subtotal','order_tax','order_status','user_currency_rate','customer_note');
  240. foreach($head as $item){
  241. $csv .= '"'.$item.'";"';
  242. }
  243. foreach($orders as $order){
  244. // $order = (array) $order;7
  245. // $order['details']
  246. // $order['items']
  247. // $order['calc_rules']
  248. $attribs = get_object_vars($order['details']['BT']);
  249. // $csv = '"BT"';
  250. // foreach($attribs as $k=>$v){
  251. // $csv .= ';"'.$k.':'$v;
  252. // }
  253. // $csv .= "\n";
  254. }
  255. $jUser = JFactory::getUser();
  256. $date = date("Y-m-d");
  257. $name = $jUser->name.$date.'.csv';
  258. // header("Content-Disposition: attachment; filename=\"".JFile::getName($media->file_url)."\"");
  259. // header("Content-Disposition: attachment; filename=\"".$name."\"");
  260. // echo $csv;
  261. parent::display();
  262. // jExit();
  263. }
  264. }
  265. // pure php no closing tag