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.

238 lines
8.9 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  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 <sidewalksoftware@gmail.com>
  8. *
  9. *@version 0.3
  10. *
  11. *@package Quinta
  12. * @subpackage Modules
  13. */
  14. class CheckOutReviewModule extends QPanel{
  15. /**
  16. *@var CheckOutModule objControlBlock - the main control block for the check out module
  17. */
  18. protected $objControlBlock;
  19. /**
  20. *@var Order objOrder - local reference to the order
  21. */
  22. protected $objOrder;
  23. /**
  24. * @var array CheckOutItems - a list of products as cart items.
  25. */
  26. public $aryCheckOutItemControllers;
  27. /**
  28. * @var OrderTotalsController - module to display shipping, handling and total price for order
  29. */
  30. public $objOrderTotalsController;
  31. /**
  32. * @var AddressController objShippingAddressController - display for the shipping address
  33. */
  34. public $objShippingAddressController;
  35. /**
  36. * @var AddressController objBillingAddressController - display for the billing address
  37. */
  38. public $objBillingAddressController;
  39. /**
  40. * @var QPanel pnlPaymentMethod - panel to display information about the selected method
  41. */
  42. public $pnlPaymentMethod;
  43. /**
  44. * @var QPanel pnlShippinggMethod - panel to display information about the selected method
  45. */
  46. public $pnlShippingMethod;
  47. ///Buttons attached to the address and payment views for callback ..
  48. public $btnEditShippingAddress;
  49. public $btnEditBillingAddress;
  50. public $btnEditShippingMethod;
  51. public $btnEditPaymentMethod;
  52. /**
  53. * Module constructor
  54. *@param QPanel pnlParentObject - the DOM parent
  55. *@param CheckOutModule objControlBlock - parent controller module.
  56. *@param Order objOrder - the Order being reviewed.
  57. */
  58. public function __construct( QPanel $pnlParentObject, $objControlBlock, Order $objOrder){
  59. try {
  60. parent::__construct($pnlParentObject, 'CheckOutReviewModule');
  61. } catch (QCallerException $objExc) {
  62. $objExc->IncrementOffset();
  63. throw $objExc;
  64. }
  65. $this->objOrder =& $objOrder;
  66. $this->objControlBlock =& $objControlBlock;
  67. $this->AutoRenderChildren = true;
  68. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/CheckOutReviewModule.tpl.php';
  69. $this->init();
  70. }
  71. /**
  72. * This function is called when the user clicks "Edit" by the Shipping address, it returns the user to the
  73. * Shipping information panel.
  74. *@param string strFormId - a string representation of the CSS Id for the main form
  75. *@param string strControlId - a string representation of the CSS Id for the control calling this function
  76. *@param string strParameter - a string containing optionally set parameters
  77. */
  78. public function btnEditShippingAddress_Click($strFormId, $strControlId, $strParameter){
  79. $this->objControlBlock->GoBack(CheckOutStage::Shipping);
  80. }
  81. /**
  82. * This function is called when the user clicks "Edit" by the Billing address, it returns the user to the
  83. * Billing information panel.
  84. *@param string strFormId - a string representation of the CSS Id for the main form
  85. *@param string strControlId - a string representation of the CSS Id for the control calling this function
  86. *@param string strParameter - a string containing optionally set parameters
  87. */
  88. public function btnEditBillingAddress_Click($strFormId, $strControlId, $strParameter){
  89. $this->objControlBlock->GoBack(CheckOutStage::Payment);
  90. }
  91. protected function init(){
  92. $this->aryCheckOutItemControllers = array();
  93. //construct the list of items
  94. $aryOrderItems = $this->objOrder->GetNewOrderItemsArray();
  95. foreach( $aryOrderItems as $objOrderItem){
  96. $objItemView = new CheckOutItemController( $this, $objOrderItem, false );
  97. $this->aryCheckOutItemControllers[] = $objItemView;
  98. }
  99. $this->objOrderTotalsController = new OrderTotalsController($this, $this->objOrder, false);
  100. $this->objShippingAddressController = new AddressController($this,
  101. $this->objOrder->ShippingAddressId,
  102. 'ShippingAddress: ');
  103. $this->objShippingAddressController->CssClass = 'ShippingAddressReview';
  104. $this->objShippingAddressController->AutoRenderChildren = true;
  105. $this->objBillingAddressController = new AddressController($this,
  106. $this->objOrder->BillingAddressId,
  107. 'BillingAddress: ');
  108. $this->objBillingAddressController->CssClass = 'BillingAddressReview';
  109. $this->objBillingAddressController->AutoRenderChildren = true;
  110. $this->pnlPaymentMethod_Create();
  111. $this->pnlShippingMethod_Create();
  112. $this->btnEditShippingAddress = new QButton($this->objShippingAddressController);
  113. $this->btnEditShippingAddress->Text = Quinta::Translate('Edit');
  114. if(IndexPage::$blnAjaxOk)
  115. $this->btnEditShippingAddress->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditShippingAddress_Click'));
  116. else
  117. $this->btnEditShippingAddress->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditShippingAddress_Click'));
  118. $this->btnEditBillingAddress = new QButton($this->objBillingAddressController);
  119. $this->btnEditBillingAddress->Text = Quinta::Translate('Edit');
  120. if(IndexPage::$blnAjaxOk)
  121. $this->btnEditBillingAddress->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditBillingAddress_Click'));
  122. else
  123. $this->btnEditBillingAddress->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditBillingAddress_Click'));
  124. }
  125. public function RefreshView($objOrder){
  126. $this->RemoveChildControls(true);
  127. $this->objOrder = $objOrder;
  128. $this->init();
  129. }
  130. protected function pnlPaymentMethod_Create(){
  131. if($this->objControlBlock->PaymentMethod instanceof PaymentMethod){
  132. $objPaymentMethod = $this->objControlBlock->PaymentMethod;
  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. $this->btnEditPaymentMethod = new QButton($this->pnlPaymentMethod);
  144. $this->btnEditPaymentMethod->Text = Quinta::Translate('Change');
  145. if(IndexPage::$blnAjaxOk)
  146. $this->btnEditPaymentMethod->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditBillingAddress_Click'));
  147. else
  148. $this->btnEditPaymentMethod->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditBillingAddress_Click'));
  149. }
  150. }
  151. protected function pnlShippingMethod_Create(){
  152. if($this->objControlBlock->ShippingMethod instanceof ShippingMethod){
  153. $objShippingMethod = $this->objControlBlock->ShippingMethod;
  154. $this->pnlShippingMethod = new QPanel($this);
  155. $this->pnlShippingMethod->HtmlEntities = false;
  156. $this->pnlShippingMethod->CssClass = 'ShippingMethodReview';
  157. $this->pnlShippingMethod->AutoRenderChildren = true;
  158. $strText = '<div class="heading">' . Quinta::Translate('Shipping Method') . ':</div>'
  159. . sprintf( '<div class="heading"> %s </div> <br /> %s ',
  160. $objShippingMethod->Title,
  161. $objShippingMethod->Description
  162. );
  163. $this->pnlShippingMethod->Text = $strText;
  164. $this->btnEditShippingMethod = new QButton($this->pnlShippingMethod);
  165. $this->btnEditShippingMethod->Text = Quinta::Translate('Change');
  166. if(IndexPage::$blnAjaxOk)
  167. $this->btnEditShippingMethod->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnEditShippingAddress_Click'));
  168. else
  169. $this->btnEditShippingMethod->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnEditShippingAddress_Click'));
  170. }
  171. }
  172. /**
  173. * This Function is called when any input is sent - on failure the
  174. * fields are redrawn with optional error messages.
  175. */
  176. public function Validate(){
  177. $blnToReturn = true;
  178. // validate input here
  179. return $blnToReturn;
  180. }
  181. public function __get($strName){
  182. switch ($strName){
  183. case 'Order':
  184. return $this->objOrder ;
  185. default:
  186. try {
  187. return parent::__get($strName);
  188. } catch (QCallerException $objExc) {
  189. $objExc->IncrementOffset();
  190. throw $objExc;
  191. }
  192. }
  193. }
  194. public function __set($strName, $mixValue){
  195. switch ($strName){
  196. case 'Order':
  197. try {
  198. return ($this->objOrder = QType::Cast($mixValue, 'Order' ));
  199. } catch (QInvalidCastException $objExc) {
  200. $objExc->IncrementOffset();
  201. throw $objExc;
  202. }
  203. default:
  204. try {
  205. return (parent::__set($strName, $mixValue));
  206. } catch (QCallerException $objExc) {
  207. $objExc->IncrementOffset();
  208. throw $objExc;
  209. }
  210. }
  211. }
  212. }//end class
  213. }//end define
  214. ?>