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.

275 lines
13 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  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 <erikwinnmail@yahoo.com>
  19. *
  20. *
  21. * $Id: CheckOutEditModule.class.php 286 2008-10-10 23:33:36Z erikwinn $
  22. *@version 0.1
  23. *
  24. *@copyright (C) 2008 by Erik Winn
  25. *@license GPL v.2
  26. This program is free software; you can redistribute it and/or modify
  27. it under the terms of the GNU General Public License as published by
  28. the Free Software Foundation; either version 2 of the License, or
  29. (at your option) any later version.
  30. This program is distributed in the hope that it will be useful,
  31. but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. GNU General Public License for more details.
  34. You should have received a copy of the GNU General Public License
  35. along with this program; if not, write to the Free Software
  36. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  37. *
  38. *@package Quasi
  39. * @subpackage Modules
  40. */
  41. class CheckOutEditModule extends QPanel
  42. {
  43. /**
  44. * ContentBlock contains the data and main functions for the check out module.
  45. * @var CheckOutModule - both the DOM parent object and the control block passed to submodules
  46. */
  47. protected $objControlBlock;
  48. protected $objShippingAddress;
  49. protected $objBillingAddress;
  50. /**
  51. * This module shows a panel containing the items on the order with modifiable quantity fields
  52. * and a remove button.
  53. * @var CheckOutItemListModule - lists order items
  54. */
  55. public $objCheckOutItemListModule;
  56. /**
  57. * @var CheckOutTotalsView - module to display shipping, handling and total price for order
  58. */
  59. public $objCheckOutTotalsView;
  60. /**
  61. * This module shows a panel containing the address for the order
  62. * @var AddressView
  63. */
  64. public $objShippingAddressView;
  65. public $objBillingAddressView;
  66. /**
  67. * This module shows a panel for editting the addresses for the order. It is called with a parameter
  68. * to determine which of the addresses to edit (Billing | Shipping)
  69. * @var AddressView
  70. */
  71. public $objAddressEditPanel;
  72. /**
  73. * @var QButton control buttons to edit the address fields
  74. */
  75. public $btnChangeShipping;
  76. public $btnChangeBilling;
  77. /**
  78. * This is here only because technically PayPal requires that you have two points of entry into their
  79. * scheme .. one is supposed to be on the "shopping cart page" - that is a pain to set up and putting
  80. * it here makes more sense as we want to offer shipping options. Besides, I don't like the idea
  81. * of sending the customer to approve a payment amount and _then_ adding shipping - too sleazy
  82. * for my troublesome sense of ethics ...
  83. * @var QImageButton button to show on the first panel to support PayPal Express Checkout
  84. */
  85. public $btnPayPalExpressButton;
  86. /**
  87. * Module constructor
  88. * NOTE: This module ignores the required extra parameters ..
  89. *@param ContentBlock - parent controller object.
  90. *@param mixed - extra parameters, ignored
  91. */
  92. public function __construct( CheckOutModule $objControlBlock, $mixParameters=null)
  93. {
  94. try {
  95. parent::__construct($objControlBlock);
  96. } catch (QCallerException $objExc) {
  97. $objExc->IncrementOffset();
  98. throw $objExc;
  99. }
  100. $this->objControlBlock =& $objControlBlock;
  101. $this->objShippingAddress =& $this->objControlBlock->objShippingAddress;
  102. $this->objBillingAddress =& $this->objControlBlock->objBillingAddress;
  103. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/CheckOutEditModule.tpl.php';
  104. $this->objCheckOutItemListModule = new CheckOutItemListModule($this, $objControlBlock);
  105. $this->objCheckOutItemListModule->initItemList($objControlBlock->aryOrderItems);
  106. $this->objShippingAddressView = new AddressView($this,
  107. $this->objShippingAddress->Id,
  108. 'ShippingAddress: ',
  109. 'ShippingAddressView'
  110. );
  111. $this->objBillingAddressView = new AddressView($this,
  112. $this->objBillingAddress->Id,
  113. 'BillingAddress: ',
  114. 'BillingAddressView'
  115. );
  116. $this->objShippingAddressView->AutoRenderChildren = true;
  117. $this->objBillingAddressView->AutoRenderChildren = true;
  118. $this->objCheckOutTotalsView = new CheckOutTotalsView($this);
  119. // grab shipping charges from shipping module if possible..
  120. if( $this->objControlBlock->ShippingModule instanceof ShippingModule
  121. && $this->objControlBlock->ShippingMethod instanceof ShippingMethod)
  122. $this->objCheckOutTotalsView->ShippingCharge = $this->objShippingModule->SelectedMethod->Rate;
  123. else
  124. $this->objCheckOutTotalsView->ShippingCharge = 0;
  125. /// @todo make handling charge configurable.
  126. $this->objCheckOutTotalsView->HandlingCharge = 10.0;
  127. $this->objCheckOutTotalsView->TotalItemsCharge = $this->objCheckOutItemListModule->ItemsTotalPrice;
  128. $this->objCheckOutTotalsView->RefreshTotal();
  129. $this->btnChangeShipping = new QButton($this->objShippingAddressView);
  130. $this->btnChangeShipping->Text = Quasi::Translate('Change');
  131. if(IndexPage::$blnAjaxOk)
  132. $this->btnChangeShipping->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnChangeAddress_Click'));
  133. else
  134. $this->btnChangeShipping->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnChangeAddress_Click'));
  135. $this->btnChangeShipping->ActionParameter = 'Shipping';
  136. $this->btnChangeShipping->CausesValidation = $this;
  137. $this->btnChangeBilling = new QButton($this->objBillingAddressView);
  138. $this->btnChangeBilling->Text = Quasi::Translate('Change');
  139. if(IndexPage::$blnAjaxOk)
  140. $this->btnChangeBilling->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnChangeAddress_Click'));
  141. else
  142. $this->btnChangeBilling->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnChangeAddress_Click'));
  143. $this->btnChangeBilling->ActionParameter = 'Billing';
  144. $this->btnChangeBilling->CausesValidation = $this;
  145. }
  146. public function btnChangeAddress_Click($strFormId, $strControlId, $strParameters)
  147. {
  148. $aryParameters = explode(',',$strParameters);
  149. switch($aryParameters[0])
  150. {
  151. case 'Billing':
  152. $this->ShowAddressEditPanel($this->objBillingAddress->Id);
  153. break;
  154. case 'Shipping':
  155. $this->ShowAddressEditPanel($this->objShippingAddress->Id);
  156. break;
  157. case 'New':
  158. $this->ShowAddressEditPanel();
  159. break;
  160. default:
  161. throw new QCallerException('Unknown Address change - ' . $aryParameters[0] );
  162. }
  163. }
  164. /**
  165. * Shows the panel to the selected shipping address, hiding all the others.
  166. */
  167. public function ShowAddressEditPanel($intAddressId=null)
  168. {
  169. $this->objCheckOutItemListModule->Visible = false;
  170. $this->objShippingAddressView->Visible = false;
  171. $this->objBillingAddressView->Visible = false;
  172. $this->objControlBlock->btnContinue->Visible = false;
  173. $this->objControlBlock->ShippingModule->Visible = false;
  174. $this->objAddressEditPanel = new AccountAddressEditPanel($this, $this, 'CloseAddressEditPanel', $intAddressId );
  175. //set a template that doesn't show the delete button ..
  176. $this->objAddressEditPanel->Template = __QUASI_CORE_TEMPLATES__ . '/CheckOutAddressEditPanel.tpl.php';
  177. $this->objAddressEditPanel->Visible = true;
  178. }
  179. /**
  180. * Closes the address editting panel, updates the addresses and shows the CheckOutEditModule again.
  181. *@todo implement reloading the address data, for now its just a brute force kludge to update the page.
  182. */
  183. public function CloseAddressEditPanel($blnUpdatesMade)
  184. {
  185. Quasi::Redirect(__QUASI_SUBDIRECTORY__ . '/index.php/CheckOut');
  186. /*
  187. $this->objAddressEditPanel->Visible = false;
  188. // update the addresses
  189. $this->objShippingAddressView = new AddressView($this, $this->objShippingAddress->Id, 'ShippingAddress: ', 'ShippingAddressView' );
  190. $this->objBillingAddressView = new AddressView($this, $this->objBillingAddress->Id, 'BillingAddress: ', 'BillingAddressView' );
  191. $this->objShippingAddressView->Visible = true;
  192. $this->objBillingAddressView->Visible = true;
  193. $this->objCheckOutItemListModule->Visible = true;
  194. */
  195. }
  196. /**
  197. * This Function is called when any input is sent - on failure the
  198. * fields are redrawn with optional error messages.
  199. */
  200. public function Validate()
  201. {
  202. $blnToReturn = true;
  203. // validate input here
  204. return $blnToReturn;
  205. }
  206. public function __get($strName)
  207. {
  208. switch ($strName)
  209. {
  210. //Note: this (like all __get magic) returns a copy ..)
  211. case 'ItemListModule':
  212. return $this->objCheckOutItemListModule ;
  213. case 'ShoppingCart':
  214. return $this->objShoppingCart ;
  215. case 'ShippingAddress':
  216. return $this->objShippingAddress ;
  217. case 'BillingAddress':
  218. return $this->objBillingAddress ;
  219. case 'Account':
  220. return IndexPage::$objAccount ;
  221. case 'TotalItemsCharge':
  222. return $this->objCheckOutTotalsView->ShippingCharge ;
  223. case 'ShippingCharge':
  224. return $this->objCheckOutTotalsView->ShippingCharge ;
  225. case 'HandlingCharge':
  226. return $this->objCheckOutTotalsView->HandlingCharge ;
  227. default:
  228. try {
  229. return parent::__get($strName);
  230. } catch (QCallerException $objExc) {
  231. $objExc->IncrementOffset();
  232. throw $objExc;
  233. }
  234. }
  235. }
  236. public function __set($strName, $mixValue)
  237. {
  238. switch ($strName)
  239. {
  240. case 'ShippingCharge':
  241. return ($this->objCheckOutTotalsView->ShippingCharge = $mixValue);
  242. case 'TotalItemsCharge':
  243. return ($this->objCheckOutTotalsView->TotalItemsCharge = $mixValue);
  244. default:
  245. try {
  246. return (parent::__set($strName, $mixValue));
  247. } catch (QCallerException $objExc) {
  248. $objExc->IncrementOffset();
  249. throw $objExc;
  250. }
  251. }
  252. }
  253. }//end class
  254. }//end define
  255. ?>