A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
13 KiB

13 years ago
  1. <?php
  2. /**
  3. * AccountOrderViewPanel - provides a panel for user viewing a specific
  4. * order in the user account area.
  5. *
  6. *@author Erik Winn <erikwinnmail@yahoo.com>
  7. *
  8. *
  9. * $Id: AccountOrderViewPanel.class.php 507 2009-03-10 15:54:02Z erikwinn $
  10. *@version 0.1
  11. *
  12. *@copyright (C) 2008 by Erik Winn
  13. *@license GPL v.2
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 2 of the License, or
  17. (at your option) any later version.
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  25. *
  26. * @package Quasi
  27. * @subpackage Classes
  28. */
  29. class AccountOrderViewPanel extends QPanel
  30. {
  31. /**
  32. * @var QPanel objControlBlock - the DOM parent panel
  33. */
  34. protected $objControlBlock;
  35. /**
  36. * @var Order objOrder - local reference to the order
  37. */
  38. public $objOrder;
  39. /**
  40. * @var OrderTotalsView - module to display shipping, handling and total price for order
  41. */
  42. public $objOrderTotalsView;
  43. /**
  44. * @var AddressView objShippingAddressView - display for the shipping address
  45. */
  46. public $objShippingAddressView;
  47. /**
  48. * @var AddressView objBillingAddressView - display for the billing address
  49. */
  50. public $objBillingAddressView;
  51. /**
  52. * @var QPanel pnlPaymentMethod - panel to display information about the selected method
  53. */
  54. public $pnlPaymentMethod;
  55. /**
  56. * @var QPanel pnlShippinggMethod - panel to display information about the selected method
  57. */
  58. public $pnlShippingMethod;
  59. /**
  60. * @var QDataGrid dtgOrderItems - datagrid for displaying the order items
  61. */
  62. public $dtgOrderItems;
  63. /**
  64. * @var QDataGrid dtgOrderStatusHistory - datagrid for displaying the order history
  65. */
  66. public $dtgOrderStatusHistory;
  67. /**
  68. * @var QControlProxy pxyProductName - a proxy for making the product column active (clickable)
  69. */
  70. public $pxyProductName;
  71. /**
  72. * @var string strTrackingNumbers - tracking numbers for order shipping
  73. */
  74. public $strTrackingNumbers;
  75. /**
  76. * @var QPaginator paginator for the order history items
  77. */
  78. public $objOrderStatusHistoryPaginator;
  79. public $objOrderItemsPaginator;
  80. // Other Controls
  81. public $btnBack;
  82. // Callback
  83. protected $strClosePanelMethod;
  84. public function __construct($objParentObject,
  85. $objControlBlock,
  86. $strClosePanelMethod,
  87. $intOrderId = null,
  88. $strControlId = null)
  89. {
  90. try {
  91. parent::__construct($objParentObject, $strControlId);
  92. } catch (QCallerException $objExc) {
  93. $objExc->IncrementOffset();
  94. throw $objExc;
  95. }
  96. $this->objControlBlock =& $objControlBlock;
  97. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/AccountOrderViewPanel.tpl.php';
  98. $this->strClosePanelMethod = $strClosePanelMethod;
  99. $this->objOrder = Order::Load($intOrderId);
  100. $aryNumbers = TrackingNumber::LoadArrayByOrderId($this->objOrder->Id);
  101. if(!empty($aryNumbers))
  102. foreach($aryNumbers as $objNumber )
  103. {
  104. if('' != $this->strTrackingNumbers)
  105. $this->strTrackingNumbers .= ', ';
  106. $this->strTrackingNumbers .= $objNumber->Number;
  107. }
  108. $this->dtgOrderItems = new OrderItemDataGrid($this);
  109. $this->dtgOrderItems->SetDataBinder('OrderItemsDataBinder', $this);
  110. $this->dtgOrderItems->CssClass = 'datagrid';
  111. $this->dtgOrderItems->AlternateRowStyle->CssClass = 'alternate';
  112. /*
  113. $this->objOrderItemsPaginator = new QPaginator($this->dtgOrderItems);
  114. $this->dtgOrderItems->Paginator = $this->objOrderItemsPaginator;
  115. $this->dtgOrderItems->ItemsPerPage = 20;
  116. */
  117. $this->pxyProductName = new QControlProxy($this);
  118. if(IndexPage::$blnAjaxOk)
  119. $this->pxyProductName->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyProductName_Click'));
  120. else
  121. $this->pxyProductName->AddAction(new QClickEvent(), new QServerControlAction($this, 'pxyProductName_Click'));
  122. /* $this->dtgOrderItems->MetaAddProxyColumn($this->pxyProductName, QQN::OrderItem()->Product, '<?= $_ITEM->Product ?>');*/
  123. $this->dtgOrderItems->MetaAddProxyColumn( $this->pxyProductName, QQN::OrderItem()->Product);
  124. $this->dtgOrderItems->MetaAddColumn(QQN::OrderItem()->Product->RetailPrice);
  125. $this->dtgOrderItems->MetaAddColumn('Quantity');
  126. $dtgTotalColumn = new QDataGridColumn('Total', '<?= money_format("%n", $_ITEM->Product->RetailPrice * $_ITEM->Quantity ) ?>');
  127. $this->dtgOrderItems->AddColumn($dtgTotalColumn);
  128. $this->dtgOrderStatusHistory = new OrderStatusHistoryDataGrid($this);
  129. $this->dtgOrderStatusHistory->SetDataBinder('OrderStatusHistoryDataBinder', $this);
  130. $this->dtgOrderStatusHistory->CssClass = 'datagrid';
  131. $this->dtgOrderStatusHistory->AlternateRowStyle->CssClass = 'alternate';
  132. $this->objOrderStatusHistoryPaginator = new QPaginator($this->dtgOrderStatusHistory);
  133. $this->dtgOrderStatusHistory->Paginator = $this->objOrderStatusHistoryPaginator;
  134. $this->dtgOrderStatusHistory->ItemsPerPage = 4;
  135. $this->dtgOrderStatusHistory->MetaAddColumn('Date');
  136. $this->dtgOrderStatusHistory->MetaAddTypeColumn('StatusId', 'OrderStatusType');
  137. $this->dtgOrderStatusHistory->MetaAddColumn('Notes');
  138. $this->objOrderTotalsView = new OrderTotalsView($this, $this->objOrder, false);
  139. $this->objShippingAddressView = new AddressView($this,
  140. $this->objOrder->GetShippingAddress()->Id,
  141. 'ShippingAddress: ');
  142. $this->objShippingAddressView->CssClass = 'ShippingAddressReview';
  143. $this->objShippingAddressView->AutoRenderChildren = true;
  144. $this->objBillingAddressView = new AddressView($this,
  145. $this->objOrder->GetBillingAddress()->Id,
  146. 'BillingAddress: ');
  147. $this->objBillingAddressView->CssClass = 'BillingAddressReview';
  148. $this->objBillingAddressView->AutoRenderChildren = true;
  149. if($this->objOrder->PaymentMethodId)
  150. {
  151. $objPaymentMethod = PaymentMethod::LoadById( $this->objOrder->PaymentMethodId );
  152. $this->pnlPaymentMethod = new QPanel($this);
  153. $this->pnlPaymentMethod->HtmlEntities = false;
  154. $this->pnlPaymentMethod->CssClass = 'PaymentMethodReview';
  155. $this->pnlPaymentMethod->AutoRenderChildren = true;
  156. $strText = '<div class="heading">' . Quasi::Translate('Payment Method') . ':</div>'
  157. . sprintf( '<div class="heading"> %s </div> <br /> %s ',
  158. $objPaymentMethod->Title,
  159. $objPaymentMethod->Description
  160. );
  161. $this->pnlPaymentMethod->Text = $strText;
  162. }
  163. if($this->objOrder->ShippingMethodId)
  164. {
  165. $objShippingMethod = ShippingMethod::LoadById( $this->objOrder->ShippingMethodId );
  166. $this->pnlShippingMethod = new QPanel($this);
  167. $this->pnlShippingMethod->HtmlEntities = false;
  168. $this->pnlShippingMethod->CssClass = 'ShippingMethodReview';
  169. $this->pnlShippingMethod->AutoRenderChildren = true;
  170. $strText = '<div class="heading">' . Quasi::Translate('Shipping Method') . ':</div>'
  171. . sprintf( '<div class="heading"> %s </div> <br /> %s ',
  172. $objShippingMethod->Title,
  173. $objShippingMethod->Description
  174. );
  175. $this->pnlShippingMethod->Text = $strText;
  176. }
  177. $this->btnBack = new QButton($this);
  178. $this->btnBack->Text = Quasi::Translate('Back');
  179. if(IndexPage::$blnAjaxOk)
  180. $this->btnBack->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnBack_Click'));
  181. else
  182. $this->btnBack->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnBack_Click'));
  183. }
  184. /**
  185. * This binds the OrderItemDatagrid data retrieval to this Order, the items listed in the Datagrid will be those
  186. * associated with this order in the database.
  187. *
  188. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  189. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  190. */
  191. public function OrderItemsDataBinder()
  192. {
  193. if ($this->objOrderItemsPaginator)
  194. $this->dtgOrderItems->TotalItemCount = OrderItem::CountByOrderId($this->objOrder->Id) ;
  195. $objClauses = array();
  196. if ($objClause = $this->dtgOrderItems->OrderByClause)
  197. array_push($objClauses, $objClause);
  198. if ($objClause = $this->dtgOrderItems->LimitClause)
  199. array_push($objClauses, $objClause);
  200. // array_push($objClauses, QQ::OrderBy(QQN::Order()->CreationDate, false) );
  201. $this->dtgOrderItems->DataSource = OrderItem::LoadArrayByOrderId($this->objOrder->Id, $objClauses);
  202. }
  203. /**
  204. * This binds the OrderStatusHistoryDatagrid data retrieval to this Order, the items listed in the Datagrid will be those
  205. * associated with this order in the database.
  206. *
  207. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  208. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  209. */
  210. public function OrderStatusHistoryDataBinder()
  211. {
  212. if ($this->objOrderStatusHistoryPaginator)
  213. $this->dtgOrderStatusHistory->TotalItemCount = OrderStatusHistory::CountByOrderId($this->objOrder->Id) ;
  214. $objClauses = array();
  215. if ($objClause = $this->dtgOrderStatusHistory->OrderByClause)
  216. array_push($objClauses, $objClause);
  217. if ($objClause = $this->dtgOrderStatusHistory->LimitClause)
  218. array_push($objClauses, $objClause);
  219. array_push($objClauses, QQ::OrderBy(QQN::OrderStatusHistory()->Date, false) );
  220. $this->dtgOrderStatusHistory->DataSource = OrderStatusHistory::LoadArrayByOrderId($this->objOrder->Id, $objClauses);
  221. }
  222. public function pxyProductName_Click($strFormId, $strControlId, $strParameters)
  223. {
  224. $pos = strpos( $strParameters, ',' );
  225. $intProductId = substr( $strParameters, 0, $pos );
  226. Quasi::Redirect( __QUASI_SUBDIRECTORY__ . '/index.php/Products/' . $intProductId );
  227. }
  228. public function btnBack_Click($strFormId, $strControlId, $strParameter)
  229. {
  230. $this->CloseSelf(false);
  231. }
  232. protected function CloseSelf($blnChangesMade)
  233. {
  234. $strMethod = $this->strClosePanelMethod;
  235. $this->objControlBlock->$strMethod($blnChangesMade);
  236. }
  237. }
  238. ?>