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.

244 lines
9.8 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  3. if (!defined("CHECKOUTEDITMODULE.CLASS.PHP")){
  4. define("CHECKOUTEDITMODULE.CLASS.PHP",1);
  5. /**
  6. * Class CheckOutEditModule - a module providing the modiflable display of order information
  7. *
  8. * This class displays the list of items in an Order with modiflable quantity fields, and two
  9. * address fields (shipping and billing) that may also be modified. It also displays the totals
  10. * for the Order including an estimated shipping charge based on the default shipping address
  11. * and the cheapest method available for that address.
  12. *
  13. * This class is displayed by the CheckOutModule for the first part of the check out process. It
  14. * presents the user with a view of the items in the Order, Addresses, and a selection of shipping
  15. * and payment methods. Each of these may be modified here.
  16. *
  17. *
  18. *@author Erik Winn <sidewalksoftware@gmail.com>
  19. *
  20. *@version 0.3
  21. *
  22. *@package Quinta
  23. * @subpackage Modules
  24. */
  25. class CheckOutEditModule extends QPanel{
  26. /**
  27. * ContentBlock contains the data and main functions for the check out module.
  28. * @var CheckOutModule - both the DOM parent object and the control block passed to submodules
  29. */
  30. protected $objControlBlock;
  31. protected $objShippingAddress;
  32. protected $objBillingAddress;
  33. /**
  34. * This module shows a panel containing the items on the order with modifiable quantity fields
  35. * and a remove button.
  36. * @var CheckOutItemListModule - lists order items
  37. */
  38. public $objCheckOutItemListModule;
  39. /**
  40. * @var CheckOutTotalsController - module to display shipping, handling and total price for order
  41. */
  42. public $objCheckOutTotalsController;
  43. /**
  44. * This module shows a panel containing the address for the order
  45. * @var AddressController
  46. */
  47. public $objShippingAddressController;
  48. public $objBillingAddressController;
  49. /**
  50. * This module shows a panel for editting the addresses for the order. It is called with a parameter
  51. * to determine which of the addresses to edit (Billing | Shipping)
  52. * @var AddressController
  53. */
  54. public $objAddressEditPanel;
  55. /**
  56. * @var QButton control buttons to edit the address fields
  57. */
  58. public $btnChangeShipping;
  59. public $btnChangeBilling;
  60. /**
  61. * This is here only because technically PayPal requires that you have two points of entry into their
  62. * scheme .. one is supposed to be on the "shopping cart page" - that is a pain to set up and putting
  63. * it here makes more sense as we want to offer shipping options. Besides, I don't like the idea
  64. * of sending the customer to approve a payment amount and _then_ adding shipping - too sleazy
  65. * for my troublesome sense of ethics ...
  66. * @var QImageButton button to show on the first panel to support PayPal Express Checkout
  67. */
  68. public $btnPayPalExpressButton;
  69. /**
  70. * Module constructor
  71. * NOTE: This module ignores the required extra parameters ..
  72. *@param ContentBlock - parent controller object.
  73. *@param mixed - extra parameters, ignored
  74. */
  75. public function __construct( CheckOutModule $objControlBlock, $mixParameters=null){
  76. try {
  77. parent::__construct($objControlBlock);
  78. } catch (QCallerException $objExc) {
  79. $objExc->IncrementOffset();
  80. throw $objExc;
  81. }
  82. $this->objControlBlock =& $objControlBlock;
  83. $this->objShippingAddress =& $this->objControlBlock->objShippingAddress;
  84. $this->objBillingAddress =& $this->objControlBlock->objBillingAddress;
  85. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/CheckOutEditModule.tpl.php';
  86. $this->objCheckOutItemListModule = new CheckOutItemListModule($this, $objControlBlock);
  87. $this->objCheckOutItemListModule->initItemList($objControlBlock->aryOrderItems);
  88. $this->objShippingAddressController = new AddressController($this,
  89. $this->objShippingAddress->Id,
  90. 'ShippingAddress: ',
  91. 'ShippingAddressController'
  92. );
  93. $this->objBillingAddressController = new AddressController($this,
  94. $this->objBillingAddress->Id,
  95. 'BillingAddress: ',
  96. 'BillingAddressController'
  97. );
  98. $this->objShippingAddressController->AutoRenderChildren = true;
  99. $this->objBillingAddressController->AutoRenderChildren = true;
  100. $this->objCheckOutTotalsController = new CheckOutTotalsController($this);
  101. // grab shipping charges from shipping module if possible..
  102. if( $this->objControlBlock->ShippingModule instanceof ShippingModule
  103. && $this->objControlBlock->ShippingMethod instanceof ShippingMethod)
  104. $this->objCheckOutTotalsController->ShippingCharge = $this->objShippingModule->SelectedMethod->Rate;
  105. else
  106. $this->objCheckOutTotalsController->ShippingCharge = 0;
  107. /// @todo make handling charge configurable.
  108. $this->objCheckOutTotalsController->HandlingCharge = 10.0;
  109. $this->objCheckOutTotalsController->TotalItemsCharge = $this->objCheckOutItemListModule->ItemsTotalPrice;
  110. $this->objCheckOutTotalsController->RefreshTotal();
  111. $this->btnChangeShipping = new QButton($this->objShippingAddressController);
  112. $this->btnChangeShipping->Text = Quinta::Translate('Change');
  113. if(IndexPage::$blnAjaxOk)
  114. $this->btnChangeShipping->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnChangeAddress_Click'));
  115. else
  116. $this->btnChangeShipping->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnChangeAddress_Click'));
  117. $this->btnChangeShipping->ActionParameter = 'Shipping';
  118. $this->btnChangeShipping->CausesValidation = $this;
  119. $this->btnChangeBilling = new QButton($this->objBillingAddressController);
  120. $this->btnChangeBilling->Text = Quinta::Translate('Change');
  121. if(IndexPage::$blnAjaxOk)
  122. $this->btnChangeBilling->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnChangeAddress_Click'));
  123. else
  124. $this->btnChangeBilling->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnChangeAddress_Click'));
  125. $this->btnChangeBilling->ActionParameter = 'Billing';
  126. $this->btnChangeBilling->CausesValidation = $this;
  127. }
  128. public function btnChangeAddress_Click($strFormId, $strControlId, $strParameters){
  129. $aryParameters = explode(',',$strParameters);
  130. switch($aryParameters[0]){
  131. case 'Billing':
  132. $this->ShowAddressEditPanel($this->objBillingAddress->Id);
  133. break;
  134. case 'Shipping':
  135. $this->ShowAddressEditPanel($this->objShippingAddress->Id);
  136. break;
  137. case 'New':
  138. $this->ShowAddressEditPanel();
  139. break;
  140. default:
  141. throw new QCallerException('Unknown Address change - ' . $aryParameters[0] );
  142. }
  143. }
  144. /**
  145. * Shows the panel to the selected shipping address, hiding all the others.
  146. */
  147. public function ShowAddressEditPanel($intAddressId=null){
  148. $this->objCheckOutItemListModule->Visible = false;
  149. $this->objShippingAddressController->Visible = false;
  150. $this->objBillingAddressController->Visible = false;
  151. $this->objControlBlock->btnContinue->Visible = false;
  152. $this->objControlBlock->ShippingModule->Visible = false;
  153. $this->objAddressEditPanel = new AccountAddressEditPanel($this, $this, 'CloseAddressEditPanel', $intAddressId );
  154. //set a template that doesn't show the delete button ..
  155. $this->objAddressEditPanel->Template = __QUINTA_CORE_VIEWS__ . '/CheckOutAddressEditPanel.tpl.php';
  156. $this->objAddressEditPanel->Visible = true;
  157. }
  158. /**
  159. * Closes the address editting panel, updates the addresses and shows the CheckOutEditModule again.
  160. *@todo implement reloading the address data, for now its just a brute force kludge to update the page.
  161. */
  162. public function CloseAddressEditPanel($blnUpdatesMade){
  163. Quinta::Redirect(__QUINTA_SUBDIRECTORY__ . '/index.php/CheckOut');
  164. /*
  165. $this->objAddressEditPanel->Visible = false;
  166. // update the addresses
  167. $this->objShippingAddressController = new AddressController($this, $this->objShippingAddress->Id, 'ShippingAddress: ', 'ShippingAddressController' );
  168. $this->objBillingAddressController = new AddressController($this, $this->objBillingAddress->Id, 'BillingAddress: ', 'BillingAddressController' );
  169. $this->objShippingAddressController->Visible = true;
  170. $this->objBillingAddressController->Visible = true;
  171. $this->objCheckOutItemListModule->Visible = true;
  172. */
  173. }
  174. /**
  175. * This Function is called when any input is sent - on failure the
  176. * fields are redrawn with optional error messages.
  177. */
  178. public function Validate(){
  179. $blnToReturn = true;
  180. // validate input here
  181. return $blnToReturn;
  182. }
  183. public function __get($strName){
  184. switch ($strName){
  185. //Note: this (like all __get magic) returns a copy ..)
  186. case 'ItemListModule':
  187. return $this->objCheckOutItemListModule ;
  188. case 'ShoppingCart':
  189. return $this->objShoppingCart ;
  190. case 'ShippingAddress':
  191. return $this->objShippingAddress ;
  192. case 'BillingAddress':
  193. return $this->objBillingAddress ;
  194. case 'Account':
  195. return IndexPage::$objAccount ;
  196. case 'TotalItemsCharge':
  197. return $this->objCheckOutTotalsController->ShippingCharge ;
  198. case 'ShippingCharge':
  199. return $this->objCheckOutTotalsController->ShippingCharge ;
  200. case 'HandlingCharge':
  201. return $this->objCheckOutTotalsController->HandlingCharge ;
  202. default:
  203. try {
  204. return parent::__get($strName);
  205. } catch (QCallerException $objExc) {
  206. $objExc->IncrementOffset();
  207. throw $objExc;
  208. }
  209. }
  210. }
  211. public function __set($strName, $mixValue){
  212. switch ($strName){
  213. case 'ShippingCharge':
  214. return ($this->objCheckOutTotalsController->ShippingCharge = $mixValue);
  215. case 'TotalItemsCharge':
  216. return ($this->objCheckOutTotalsController->TotalItemsCharge = $mixValue);
  217. default:
  218. try {
  219. return (parent::__set($strName, $mixValue));
  220. } catch (QCallerException $objExc) {
  221. $objExc->IncrementOffset();
  222. throw $objExc;
  223. }
  224. }
  225. }
  226. }//end class
  227. }//end define
  228. ?>