A QCodo powered CMS
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.

258 lines
9.5 KiB

  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 <sidewalksoftware@gmail.com>
  7. *
  8. *@version 0.3
  9. *
  10. * @package Quinta
  11. * @subpackage Classes
  12. */
  13. class AccountOrderViewPanel extends QPanel{
  14. /**
  15. * @var QPanel objControlBlock - the DOM parent panel
  16. */
  17. protected $objControlBlock;
  18. /**
  19. * @var Order objOrder - local reference to the order
  20. */
  21. public $objOrder;
  22. /**
  23. * @var OrderTotalsController - module to display shipping, handling and total price for order
  24. */
  25. public $objOrderTotalsController;
  26. /**
  27. * @var AddressController objShippingAddressController - display for the shipping address
  28. */
  29. public $objShippingAddressController;
  30. /**
  31. * @var AddressController objBillingAddressController - display for the billing address
  32. */
  33. public $objBillingAddressController;
  34. /**
  35. * @var QPanel pnlPaymentMethod - panel to display information about the selected method
  36. */
  37. public $pnlPaymentMethod;
  38. /**
  39. * @var QPanel pnlShippinggMethod - panel to display information about the selected method
  40. */
  41. public $pnlShippingMethod;
  42. /**
  43. * @var QDataGrid dtgOrderItems - datagrid for displaying the order items
  44. */
  45. public $dtgOrderItems;
  46. /**
  47. * @var QDataGrid dtgOrderStatusHistory - datagrid for displaying the order history
  48. */
  49. public $dtgOrderStatusHistory;
  50. /**
  51. * @var QControlProxy pxyProductName - a proxy for making the product column active (clickable)
  52. */
  53. public $pxyProductName;
  54. /**
  55. * @var string strTrackingNumbers - tracking numbers for order shipping
  56. */
  57. public $strTrackingNumbers;
  58. /**
  59. * @var QPaginator paginator for the order history items
  60. */
  61. public $objOrderStatusHistoryPaginator;
  62. public $objOrderItemsPaginator;
  63. // Other Controls
  64. public $btnBack;
  65. // Callback
  66. protected $strClosePanelMethod;
  67. public function __construct($objParentObject,
  68. $objControlBlock,
  69. $strClosePanelMethod,
  70. $intOrderId = null,
  71. $strControlId = null)
  72. {
  73. try {
  74. parent::__construct($objParentObject, $strControlId);
  75. } catch (QCallerException $objExc) {
  76. $objExc->IncrementOffset();
  77. throw $objExc;
  78. }
  79. $this->objControlBlock =& $objControlBlock;
  80. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/AccountOrderViewPanel.tpl.php';
  81. $this->strClosePanelMethod = $strClosePanelMethod;
  82. $this->objOrder = Order::Load($intOrderId);
  83. $aryNumbers = TrackingNumber::LoadArrayByOrderId($this->objOrder->Id);
  84. if(!empty($aryNumbers))
  85. foreach($aryNumbers as $objNumber ){
  86. if('' != $this->strTrackingNumbers)
  87. $this->strTrackingNumbers .= ', ';
  88. $this->strTrackingNumbers .= $objNumber->Number;
  89. }
  90. $this->dtgOrderItems = new OrderItemDataGrid($this);
  91. $this->dtgOrderItems->SetDataBinder('OrderItemsDataBinder', $this);
  92. $this->dtgOrderItems->CssClass = 'datagrid';
  93. $this->dtgOrderItems->AlternateRowStyle->CssClass = 'alternate';
  94. /*
  95. $this->objOrderItemsPaginator = new QPaginator($this->dtgOrderItems);
  96. $this->dtgOrderItems->Paginator = $this->objOrderItemsPaginator;
  97. $this->dtgOrderItems->ItemsPerPage = 20;
  98. */
  99. $this->pxyProductName = new QControlProxy($this);
  100. if(IndexPage::$blnAjaxOk)
  101. $this->pxyProductName->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyProductName_Click'));
  102. else
  103. $this->pxyProductName->AddAction(new QClickEvent(), new QServerControlAction($this, 'pxyProductName_Click'));
  104. /* $this->dtgOrderItems->MetaAddProxyColumn($this->pxyProductName, QQN::OrderItem()->Product, '<?= $_ITEM->Product ?>');*/
  105. $this->dtgOrderItems->MetaAddProxyColumn( $this->pxyProductName, QQN::OrderItem()->Product);
  106. $this->dtgOrderItems->MetaAddColumn(QQN::OrderItem()->Product->RetailPrice);
  107. $this->dtgOrderItems->MetaAddColumn('Quantity');
  108. $dtgTotalColumn = new QDataGridColumn('Total', '<?= money_format("%n", $_ITEM->Product->RetailPrice * $_ITEM->Quantity ) ?>');
  109. $this->dtgOrderItems->AddColumn($dtgTotalColumn);
  110. $this->dtgOrderStatusHistory = new OrderStatusHistoryDataGrid($this);
  111. $this->dtgOrderStatusHistory->SetDataBinder('OrderStatusHistoryDataBinder', $this);
  112. $this->dtgOrderStatusHistory->CssClass = 'datagrid';
  113. $this->dtgOrderStatusHistory->AlternateRowStyle->CssClass = 'alternate';
  114. $this->objOrderStatusHistoryPaginator = new QPaginator($this->dtgOrderStatusHistory);
  115. $this->dtgOrderStatusHistory->Paginator = $this->objOrderStatusHistoryPaginator;
  116. $this->dtgOrderStatusHistory->ItemsPerPage = 4;
  117. $this->dtgOrderStatusHistory->MetaAddColumn('Date');
  118. $this->dtgOrderStatusHistory->MetaAddTypeColumn('StatusId', 'OrderStatusType');
  119. $this->dtgOrderStatusHistory->MetaAddColumn('Notes');
  120. $this->objOrderTotalsController = new OrderTotalsController($this, $this->objOrder, false);
  121. $this->objShippingAddressController = new AddressController($this,
  122. $this->objOrder->GetShippingAddress()->Id,
  123. 'ShippingAddress: ');
  124. $this->objShippingAddressController->CssClass = 'ShippingAddressReview';
  125. $this->objShippingAddressController->AutoRenderChildren = true;
  126. $this->objBillingAddressController = new AddressController($this,
  127. $this->objOrder->GetBillingAddress()->Id,
  128. 'BillingAddress: ');
  129. $this->objBillingAddressController->CssClass = 'BillingAddressReview';
  130. $this->objBillingAddressController->AutoRenderChildren = true;
  131. if($this->objOrder->PaymentMethodId){
  132. $objPaymentMethod = PaymentMethod::LoadById( $this->objOrder->PaymentMethodId );
  133. $this->pnlPaymentMethod = new QPanel($this);
  134. $this->pnlPaymentMethod->HtmlEntities = false;
  135. $this->pnlPaymentMethod->CssClass = 'PaymentMethodReview';
  136. $this->pnlPaymentMethod->AutoRenderChildren = true;
  137. $strText = '<div class="heading">' . Quinta::Translate('Payment Method') . ':</div>'
  138. . sprintf( '<div class="heading"> %s </div> <br /> %s ',
  139. $objPaymentMethod->Title,
  140. $objPaymentMethod->Description
  141. );
  142. $this->pnlPaymentMethod->Text = $strText;
  143. }
  144. if($this->objOrder->ShippingMethodId){
  145. $objShippingMethod = ShippingMethod::LoadById( $this->objOrder->ShippingMethodId );
  146. $this->pnlShippingMethod = new QPanel($this);
  147. $this->pnlShippingMethod->HtmlEntities = false;
  148. $this->pnlShippingMethod->CssClass = 'ShippingMethodReview';
  149. $this->pnlShippingMethod->AutoRenderChildren = true;
  150. $strText = '<div class="heading">' . Quinta::Translate('Shipping Method') . ':</div>'
  151. . sprintf( '<div class="heading"> %s </div> <br /> %s ',
  152. $objShippingMethod->Title,
  153. $objShippingMethod->Description
  154. );
  155. $this->pnlShippingMethod->Text = $strText;
  156. }
  157. $this->btnBack = new QButton($this);
  158. $this->btnBack->Text = Quinta::Translate('Back');
  159. if(IndexPage::$blnAjaxOk)
  160. $this->btnBack->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnBack_Click'));
  161. else
  162. $this->btnBack->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnBack_Click'));
  163. }
  164. /**
  165. * This binds the OrderItemDatagrid data retrieval to this Order, the items listed in the Datagrid will be those
  166. * associated with this order in the database.
  167. *
  168. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  169. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  170. */
  171. public function OrderItemsDataBinder(){
  172. if ($this->objOrderItemsPaginator)
  173. $this->dtgOrderItems->TotalItemCount = OrderItem::CountByOrderId($this->objOrder->Id) ;
  174. $objClauses = array();
  175. if ($objClause = $this->dtgOrderItems->OrderByClause)
  176. array_push($objClauses, $objClause);
  177. if ($objClause = $this->dtgOrderItems->LimitClause)
  178. array_push($objClauses, $objClause);
  179. // array_push($objClauses, QQ::OrderBy(QQN::Order()->CreationDate, false) );
  180. $this->dtgOrderItems->DataSource = OrderItem::LoadArrayByOrderId($this->objOrder->Id, $objClauses);
  181. }
  182. /**
  183. * This binds the OrderStatusHistoryDatagrid data retrieval to this Order, the items listed in the Datagrid will be those
  184. * associated with this order in the database.
  185. *
  186. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  187. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  188. */
  189. public function OrderStatusHistoryDataBinder(){
  190. if ($this->objOrderStatusHistoryPaginator)
  191. $this->dtgOrderStatusHistory->TotalItemCount = OrderStatusHistory::CountByOrderId($this->objOrder->Id) ;
  192. $objClauses = array();
  193. if ($objClause = $this->dtgOrderStatusHistory->OrderByClause)
  194. array_push($objClauses, $objClause);
  195. if ($objClause = $this->dtgOrderStatusHistory->LimitClause)
  196. array_push($objClauses, $objClause);
  197. array_push($objClauses, QQ::OrderBy(QQN::OrderStatusHistory()->Date, false) );
  198. $this->dtgOrderStatusHistory->DataSource = OrderStatusHistory::LoadArrayByOrderId($this->objOrder->Id, $objClauses);
  199. }
  200. public function pxyProductName_Click($strFormId, $strControlId, $strParameters){
  201. $pos = strpos( $strParameters, ',' );
  202. $intProductId = substr( $strParameters, 0, $pos );
  203. Quinta::Redirect( __QUINTA_SUBDIRECTORY__ . '/index.php/Products/' . $intProductId );
  204. }
  205. public function btnBack_Click($strFormId, $strControlId, $strParameter){
  206. $this->CloseSelf(false);
  207. }
  208. protected function CloseSelf($blnChangesMade){
  209. $strMethod = $this->strClosePanelMethod;
  210. $this->objControlBlock->$strMethod($blnChangesMade);
  211. }
  212. }
  213. ?>