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.

273 lines
12 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("CHECKOUTREVIEWMODULE.CLASS.PHP")){
  4. define("CHECKOUTREVIEWMODULE.CLASS.PHP",1);
  5. /**
  6. * Class CheckOutReviewModule - provides display of order information for review during checkout
  7. *@author Erik Winn <erikwinnmail@yahoo.com>
  8. *
  9. *
  10. * $Id: CheckOutReviewModule.class.php 457 2008-12-23 20:11:54Z erikwinn $
  11. *@version 0.1
  12. *
  13. *@copyright (C) 2008 by Erik Winn
  14. *@license GPL v.2
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2 of the License, or
  18. (at your option) any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  26. *
  27. *@package Quasi
  28. * @subpackage Modules
  29. */
  30. class CheckOutReviewModule extends QPanel
  31. {
  32. /**
  33. *@var CheckOutModule objControlBlock - the main control block for the check out module
  34. */
  35. protected $objControlBlock;
  36. /**
  37. *@var Order objOrder - local reference to the order
  38. */
  39. protected $objOrder;
  40. /**
  41. * @var array CheckOutItems - a list of products as cart items.
  42. */
  43. public $aryCheckOutItemViews;
  44. /**
  45. * @var OrderTotalsView - module to display shipping, handling and total price for order
  46. */
  47. public $objOrderTotalsView;
  48. /**
  49. * @var AddressView objShippingAddressView - display for the shipping address
  50. */
  51. public $objShippingAddressView;
  52. /**
  53. * @var AddressView objBillingAddressView - display for the billing address
  54. */
  55. public $objBillingAddressView;
  56. /**
  57. * @var QPanel pnlPaymentMethod - panel to display information about the selected method
  58. */
  59. public $pnlPaymentMethod;
  60. /**
  61. * @var QPanel pnlShippinggMethod - panel to display information about the selected method
  62. */
  63. public $pnlShippingMethod;
  64. ///Buttons attached to the address and payment views for callback ..
  65. public $btnEditShippingAddress;
  66. public $btnEditBillingAddress;
  67. public $btnEditShippingMethod;
  68. public $btnEditPaymentMethod;
  69. /**
  70. * Module constructor
  71. *@param QPanel pnlParentObject - the DOM parent
  72. *@param CheckOutModule objControlBlock - parent controller module.
  73. *@param Order objOrder - the Order being reviewed.
  74. */
  75. public function __construct( QPanel $pnlParentObject, $objControlBlock, Order $objOrder)
  76. {
  77. try {
  78. parent::__construct($pnlParentObject, 'CheckOutReviewModule');
  79. } catch (QCallerException $objExc) {
  80. $objExc->IncrementOffset();
  81. throw $objExc;
  82. }
  83. $this->objOrder =& $objOrder;
  84. $this->objControlBlock =& $objControlBlock;
  85. $this->AutoRenderChildren = true;
  86. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/CheckOutReviewModule.tpl.php';
  87. $this->init();
  88. }
  89. /**
  90. * This function is called when the user clicks "Edit" by the Shipping address, it returns the user to the
  91. * Shipping information panel.
  92. *@param string strFormId - a string representation of the CSS Id for the main form
  93. *@param string strControlId - a string representation of the CSS Id for the control calling this function
  94. *@param string strParameter - a string containing optionally set parameters
  95. */
  96. public function btnEditShippingAddress_Click($strFormId, $strControlId, $strParameter)
  97. {
  98. $this->objControlBlock->GoBack(CheckOutStage::Shipping);
  99. }
  100. /**
  101. * This function is called when the user clicks "Edit" by the Billing address, it returns the user to the
  102. * Billing information panel.
  103. *@param string strFormId - a string representation of the CSS Id for the main form
  104. *@param string strControlId - a string representation of the CSS Id for the control calling this function
  105. *@param string strParameter - a string containing optionally set parameters
  106. */
  107. public function btnEditBillingAddress_Click($strFormId, $strControlId, $strParameter)
  108. {
  109. $this->objControlBlock->GoBack(CheckOutStage::Payment);
  110. }
  111. protected function init()
  112. {
  113. $this->aryCheckOutItemViews = array();
  114. //construct the list of items
  115. $aryOrderItems = $this->objOrder->GetNewOrderItemsArray();
  116. foreach( $aryOrderItems as $objOrderItem)
  117. {
  118. $objItemView = new CheckOutItemView( $this, $objOrderItem, false );
  119. $this->aryCheckOutItemViews[] = $objItemView;
  120. }
  121. $this->objOrderTotalsView = new OrderTotalsView($this, $this->objOrder, false);
  122. $this->objShippingAddressView = new AddressView($this,
  123. $this->objOrder->ShippingAddressId,
  124. 'ShippingAddress: ');
  125. $this->objShippingAddressView->CssClass = 'ShippingAddressReview';
  126. $this->objShippingAddressView->AutoRenderChildren = true;
  127. $this->objBillingAddressView = new AddressView($this,
  128. $this->objOrder->BillingAddressId,
  129. 'BillingAddress: ');
  130. $this->objBillingAddressView->CssClass = 'BillingAddressReview';
  131. $this->objBillingAddressView->AutoRenderChildren = true;
  132. $this->pnlPaymentMethod_Create();
  133. $this->pnlShippingMethod_Create();
  134. $this->btnEditShippingAddress = new QButton($this->objShippingAddressView);
  135. $this->btnEditShippingAddress->Text = Quasi::Translate('Edit');
  136. if(IndexPage::$blnAjaxOk)
  137. $this->btnEditShippingAddress->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditShippingAddress_Click'));
  138. else
  139. $this->btnEditShippingAddress->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditShippingAddress_Click'));
  140. $this->btnEditBillingAddress = new QButton($this->objBillingAddressView);
  141. $this->btnEditBillingAddress->Text = Quasi::Translate('Edit');
  142. if(IndexPage::$blnAjaxOk)
  143. $this->btnEditBillingAddress->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditBillingAddress_Click'));
  144. else
  145. $this->btnEditBillingAddress->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditBillingAddress_Click'));
  146. }
  147. public function RefreshView($objOrder)
  148. {
  149. $this->RemoveChildControls(true);
  150. $this->objOrder = $objOrder;
  151. $this->init();
  152. }
  153. protected function pnlPaymentMethod_Create()
  154. {
  155. if($this->objControlBlock->PaymentMethod instanceof PaymentMethod)
  156. {
  157. $objPaymentMethod = $this->objControlBlock->PaymentMethod;
  158. $this->pnlPaymentMethod = new QPanel($this);
  159. $this->pnlPaymentMethod->HtmlEntities = false;
  160. $this->pnlPaymentMethod->CssClass = 'PaymentMethodReview';
  161. $this->pnlPaymentMethod->AutoRenderChildren = true;
  162. $strText = '<div class="heading">' . Quasi::Translate('Payment Method') . ':</div>'
  163. . sprintf( '<div class="heading"> %s </div> <br /> %s ',
  164. $objPaymentMethod->Title,
  165. $objPaymentMethod->Description
  166. );
  167. $this->pnlPaymentMethod->Text = $strText;
  168. $this->btnEditPaymentMethod = new QButton($this->pnlPaymentMethod);
  169. $this->btnEditPaymentMethod->Text = Quasi::Translate('Change');
  170. if(IndexPage::$blnAjaxOk)
  171. $this->btnEditPaymentMethod->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditBillingAddress_Click'));
  172. else
  173. $this->btnEditPaymentMethod->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditBillingAddress_Click'));
  174. }
  175. }
  176. protected function pnlShippingMethod_Create()
  177. {
  178. if($this->objControlBlock->ShippingMethod instanceof ShippingMethod)
  179. {
  180. $objShippingMethod = $this->objControlBlock->ShippingMethod;
  181. $this->pnlShippingMethod = new QPanel($this);
  182. $this->pnlShippingMethod->HtmlEntities = false;
  183. $this->pnlShippingMethod->CssClass = 'ShippingMethodReview';
  184. $this->pnlShippingMethod->AutoRenderChildren = true;
  185. $strText = '<div class="heading">' . Quasi::Translate('Shipping Method') . ':</div>'
  186. . sprintf( '<div class="heading"> %s </div> <br /> %s ',
  187. $objShippingMethod->Title,
  188. $objShippingMethod->Description
  189. );
  190. $this->pnlShippingMethod->Text = $strText;
  191. $this->btnEditShippingMethod = new QButton($this->pnlShippingMethod);
  192. $this->btnEditShippingMethod->Text = Quasi::Translate('Change');
  193. if(IndexPage::$blnAjaxOk)
  194. $this->btnEditShippingMethod->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditShippingAddress_Click'));
  195. else
  196. $this->btnEditShippingMethod->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditShippingAddress_Click'));
  197. }
  198. }
  199. /**
  200. * This Function is called when any input is sent - on failure the
  201. * fields are redrawn with optional error messages.
  202. */
  203. public function Validate()
  204. {
  205. $blnToReturn = true;
  206. // validate input here
  207. return $blnToReturn;
  208. }
  209. public function __get($strName)
  210. {
  211. switch ($strName)
  212. {
  213. case 'Order':
  214. return $this->objOrder ;
  215. default:
  216. try {
  217. return parent::__get($strName);
  218. } catch (QCallerException $objExc) {
  219. $objExc->IncrementOffset();
  220. throw $objExc;
  221. }
  222. }
  223. }
  224. public function __set($strName, $mixValue)
  225. {
  226. switch ($strName)
  227. {
  228. case 'Order':
  229. try {
  230. return ($this->objOrder = QType::Cast($mixValue, 'Order' ));
  231. } catch (QInvalidCastException $objExc) {
  232. $objExc->IncrementOffset();
  233. throw $objExc;
  234. }
  235. default:
  236. try {
  237. return (parent::__set($strName, $mixValue));
  238. } catch (QCallerException $objExc) {
  239. $objExc->IncrementOffset();
  240. throw $objExc;
  241. }
  242. }
  243. }
  244. }//end class
  245. }//end define
  246. ?>