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.

658 lines
31 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("CHECKOUTMODULE.CLASS.PHP")){
  4. define("CHECKOUTMODULE.CLASS.PHP",1);
  5. /**
  6. * Stage Types for the Checkout process - oh for an enum type ..
  7. * These stages represent each of the parts of the checkout process - they
  8. * are both set to keep track of which module is active so that we may take
  9. * appropriate actions on forward or back movements according to what the
  10. * previous Stage was and they are passed as ActionParameters to indicate
  11. * which Stage to show next.
  12. *
  13. * Note that ShoppingCart is not actually a stage module here - it is merely
  14. * a redirect to the ShoppingCartView page. Likewise, Cancel redirects to Home.
  15. *
  16. *@package Quasi
  17. *@subpackage Modules
  18. */
  19. class CheckOutStage{
  20. /**
  21. *@var constant integer - flags for indicating current stage of the process
  22. */
  23. const ShoppingCart = 0;
  24. const Shipping = 1;
  25. const Payment = 2;
  26. const Review = 3;
  27. const Confirmation = 4;
  28. const Cancel = 6;
  29. }
  30. /**
  31. * Class CheckOutModule - a module for the checkout process
  32. * This class provides a central page module with four modules that make
  33. * up a four part checkout process.
  34. *
  35. * The first part displays the shipping options information to the user with sections
  36. * for choosing addresses and shipping methods.
  37. *
  38. * The second part shows payment options and billing address.
  39. *
  40. * The third part shows the order again and all of the choices with
  41. * final charges and a confirmation action - the user may also choose to
  42. * return to a previous step to modify the quantities in the order or other selections
  43. * (addresses, shipping method, payment, etc.). Note that if they choose to modify
  44. * the quantity they are redirected to the ShoppingCartView page and must
  45. * reinitiate the checkout process (by clicking "Check Out").
  46. *
  47. * The final module confirms the status of the payment and displays misc confirmation
  48. * messages.
  49. *
  50. *@todo
  51. * - send order email confirmation
  52. * - PayPal Express checkout button and action on CheckOutEditModule panel, this
  53. * will basically call the paypal payment action, ie. it should behave like clicking the
  54. * "purchase" button in the PaymentModule ..
  55. *
  56. *@author Erik Winn <erikwinnmail@yahoo.com>
  57. *
  58. * $Id: CheckOutModule.class.php 457 2008-12-23 20:11:54Z erikwinn $
  59. *@version 0.1
  60. *
  61. *@copyright (C) 2008 by Erik Winn
  62. *@license GPL v.2
  63. This program is free software; you can redistribute it and/or modify
  64. it under the terms of the GNU General Public License as published by
  65. the Free Software Foundation; either version 2 of the License, or
  66. (at your option) any later version.
  67. This program is distributed in the hope that it will be useful,
  68. but WITHOUT ANY WARRANTY; without even the implied warranty of
  69. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  70. GNU General Public License for more details.
  71. You should have received a copy of the GNU General Public License
  72. along with this program; if not, write to the Free Software
  73. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  74. *
  75. *@package Quasi
  76. * @subpackage Modules
  77. */
  78. class CheckOutModule extends QPanel
  79. {
  80. protected $objAccount = null;
  81. protected $objShoppingCart = null;
  82. protected $intCurrentStage = 0;
  83. /**
  84. *@var Order - the current order
  85. */
  86. protected $objOrder = null;
  87. /**
  88. *@var ShippingMethod - reference to the selected shipping method
  89. */
  90. protected $objShippingMethod = null;
  91. /**
  92. *@var PaymentMethod - reference to the selected payment method
  93. */
  94. protected $objPaymentMethod = null;
  95. /**
  96. *@var boolean blnCartEmpty - set to true if there are no items in the cart
  97. */
  98. protected $blnCartEmpty = true;
  99. /**
  100. * This indicates whether the customer has clicked "Purchase" yet - if they do this and
  101. * then hit back in the browser we want to clean up and start over ..
  102. * NOTE: this needs to be moved somewhere global to maintain state ( perhaps even $_SESSION since
  103. * the user may have been transferred offsite )
  104. *@todo - handle browser back actions when payment already initiated
  105. *@var boolean
  106. */
  107. protected $blnTransactionInitiated=false;
  108. /**
  109. *@var boolean blnTransactionApproved - indicates whether the payment was accepted or not
  110. */
  111. protected $blnTransactionApproved = false;
  112. /**
  113. *@var string strTransactionMessage - string to contain messages from the payment server
  114. */
  115. protected $strTransactionMessage;
  116. /**
  117. *@var string strErrors - general error storage ..
  118. */
  119. protected $strErrors;
  120. /**
  121. *@var Address - reference to the selected or default shipping address
  122. */
  123. public $objShippingAddress;
  124. /**
  125. *@var Address - reference to the selected or default billing address
  126. */
  127. public $objBillingAddress;
  128. /**
  129. * @var OrderTotalsView - view panel to display the order totals
  130. */
  131. public $objOrderTotalsView;
  132. /**
  133. * @var PaymentModule - module to manage the selection of a payment method
  134. */
  135. public $objPaymentModule;
  136. /**
  137. * @var ShippingModule - module to manage the selection of a shipping method
  138. */
  139. public $objShippingModule;
  140. /**
  141. * @var CheckOutReviewModule - module to display a review of the order and accept submission
  142. */
  143. public $objCheckOutReviewModule;
  144. /**
  145. * @var CheckOutConfirmationModule - module to display order/payment confirmation or errors
  146. */
  147. public $objCheckOutConfirmationModule;
  148. /**
  149. * @var Qlabel lblProgressBar - shows a progress image indicating the current stage
  150. */
  151. public $lblProgressBar;
  152. /**
  153. * This refers to the currently active module - it is assigned a module according to the current
  154. * stage of the process
  155. *@var QPanel - the current panel.
  156. */
  157. public $pnlCurrentPanel = null;
  158. /**
  159. * This panel shows the title heading for currently active module - it is assigned text according to the current
  160. * stage of the process
  161. *@var QPanel - the current panel title heading.
  162. */
  163. public $pnlHeading;
  164. public $btnContinue;
  165. public $btnCancel;
  166. public $btnBack;
  167. public $objWaitIcon;
  168. public $pnlHeading;
  169. public $lblMessages;
  170. /**
  171. * Module constructor
  172. * NOTE: This module ignores the required extra parameters ..
  173. *@param ContentBlockView - parent controller object.
  174. *@param mixed - extra parameters, ignored
  175. */
  176. public function __construct( ContentBlockView $objParentObject, $mixParameters=null)
  177. {
  178. try {
  179. parent::__construct($objParentObject);
  180. } catch (QCallerException $objExc) {
  181. $objExc->IncrementOffset();
  182. throw $objExc;
  183. }
  184. $this->objAccount =& IndexPage::$objAccount;
  185. $this->objShoppingCart =& IndexPage::$objShoppingCart;
  186. $this->AutoRenderChildren = true;
  187. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/CheckOutModule.tpl.php';
  188. $this->pnlHeading = new QPanel($this);
  189. $this->pnlHeading->HtmlEntities = false;
  190. $this->pnlHeading->AddCssClass('CheckoutHeading');
  191. $this->lblProgressBar = new QLabel($this);
  192. $this->lblProgressBar->HtmlEntities = false;
  193. $this->lblProgressBar->CssClass = 'ProgressBarShipping';
  194. $this->lblProgressBar->Text = sprintf('<span class="heading">%s</span><span class="label">%s</span>
  195. <span class="label">%s</span><span class="label">%s</span>
  196. <span class="label">%s</span><span class="label">%s</span>',
  197. STORE_NAME . ' ' . Quasi::Translate('Checkout Process') . ':',
  198. Quasi::Translate('cart'),
  199. Quasi::Translate('shipping'),
  200. Quasi::Translate('payment'),
  201. Quasi::Translate('review order'),
  202. Quasi::Translate('receipt'));
  203. $this->lblMessages = new QLabel($this);
  204. $this->lblMessages->HtmlEntities = false;
  205. $this->pnlCurrentPanel = new QPanel($this);
  206. $this->pnlCurrentPanel->AutoRenderChildren = true;
  207. // Only show anything if there is an active Account and ShoppingCart
  208. if( $this->objAccount instanceof Account && $this->objShoppingCart instanceof ShoppingCart)
  209. {
  210. $this->objOrder = $this->objShoppingCart->CreateNewOrder(true);
  211. $aryOrderItems = $this->objOrder->GetNewOrderItemsArray();
  212. if ( empty($aryOrderItems) )
  213. {
  214. $this->pnlHeading->Text = '&nbsp;&nbsp;&nbsp;' . Quasi::Translate('Empty Cart');
  215. // $this->pnlCurrentPanel = new QPanel($this);
  216. $this->pnlCurrentPanel->Text = Quasi::Translate('There are no items to check out') . '.';
  217. return;
  218. }
  219. else
  220. $this->blnCartEmpty = false;
  221. //create a display of the order summary ..
  222. $this->objOrderTotalsView = new OrderTotalsView($this, $this->objOrder);
  223. //create buttons to manage work flow between panels - the signals are handled here.
  224. // Continue goes to the next panel, Back returns to previous panel, Cancel goes Home
  225. $this->btnContinue = new QButton($this);
  226. $this->btnContinue->Text = Quasi::Translate('Continue');
  227. if(IndexPage::$blnAjaxOk)
  228. $this->btnContinue->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnContinue_Click'));
  229. else
  230. $this->btnContinue->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnContinue_Click'));
  231. $this->btnBack = new QButton($this);
  232. $this->btnBack->Text = Quasi::Translate('Back');
  233. if(IndexPage::$blnAjaxOk)
  234. $this->btnBack->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnBack_Click'));
  235. else
  236. $this->btnBack->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnBack_Click'));
  237. $this->btnCancel = new QButton($this);
  238. $this->btnCancel->Text = Quasi::Translate('Cancel');
  239. if(IndexPage::$blnAjaxOk)
  240. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  241. else
  242. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click'));
  243. $this->objWaitIcon = new QWaitIcon($this);
  244. //start out with the shipping options displayed
  245. $this->GoForward( CheckOutStage::Shipping );
  246. }
  247. else
  248. $this->pnlCurrentPanel->Text = Quasi::Translate('We are sorry, you must be logged in to check out.');
  249. }
  250. /**
  251. * This function is called when the user clicks "Back" - it checks for the current stage and
  252. * calls GoBack with the appropriate parameters.
  253. *@param string strFormId - a string representation of the CSS Id for the main form
  254. *@param string strControlId - a string representation of the CSS Id for the control calling this function
  255. *@param string strParameter - a string containing optionally set parameters
  256. */
  257. public function btnBack_Click($strFormId, $strControlId, $strParameter)
  258. {
  259. switch( $this->intCurrentStage )
  260. {
  261. case CheckOutStage::Shipping:
  262. return $this->GoBack(CheckOutStage::ShoppingCart);
  263. case CheckOutStage::Payment:
  264. return $this->GoBack(CheckOutStage::Shipping);
  265. case CheckOutStage::Review:
  266. return $this->GoBack(CheckOutStage::Payment);
  267. }
  268. }
  269. /**
  270. * This function is called when the user clicks "Continue" - it checks for the current stage and
  271. * calls GoForward with the appropriate parameters.
  272. *@param string strFormId - a string representation of the CSS Id for the main form
  273. *@param string strControlId - a string representation of the CSS Id for the control calling this function
  274. *@param string strParameter - a string containing optionally set parameters
  275. */
  276. public function btnContinue_Click($strFormId, $strControlId, $strParameter)
  277. {
  278. switch( $this->intCurrentStage )
  279. {
  280. case CheckOutStage::Shipping:
  281. return $this->GoForward(CheckOutStage::Payment);
  282. case CheckOutStage::Payment:
  283. return $this->GoForward(CheckOutStage::Review);
  284. case CheckOutStage::Review:
  285. return $this->GoForward(CheckOutStage::Confirmation);
  286. case CheckOutStage::Confirmation:
  287. QApplication::Redirect(__QUASI_SUBDIRECTORY__ . '/index.php/Home');
  288. }
  289. }
  290. /**
  291. * This function is called when the user clicks "Cancel" - it deletes the order and redirects
  292. * the user to the home page ..
  293. *@param string strFormId - a string representation of the CSS Id for the main form
  294. *@param string strControlId - a string representation of the CSS Id for the control calling this function
  295. *@param string strParameter - a string containing optionally set parameters
  296. */
  297. public function btnCancel_Click($strFormId, $strControlId, $strParameter)
  298. {
  299. //NOTE: perhaps we should clear the shopping cart here? or provide some
  300. // other way to do that somewhere ..
  301. $this->GoForward(CheckOutStage::Cancel);
  302. }
  303. public function GoBack($NextStage)
  304. {
  305. $this->pnlCurrentPanel->RemoveChildControls(false);
  306. switch($NextStage)
  307. {
  308. case CheckOutStage::ShoppingCart:
  309. Quasi::Redirect('http://' . Quasi::$ServerName . __QUASI_SUBDIRECTORY__ . '/index.php/ShoppingCart');
  310. break;
  311. case CheckOutStage::Shipping:
  312. $this->pnlHeading->Text = '&nbsp;&nbsp;&nbsp;' . Quasi::Translate('Shipping Options');
  313. $this->lblProgressBar->CssClass = 'ProgressBarShipping';
  314. $this->objShippingModule->SetParentControl($this->pnlCurrentPanel);
  315. $this->objOrderTotalsView->Visible = true;
  316. break;
  317. case CheckOutStage::Payment:
  318. $this->pnlHeading->Text = '&nbsp;&nbsp;&nbsp;' . Quasi::Translate('Payment Options');
  319. $this->lblProgressBar->CssClass = 'ProgressBarPayment';
  320. $this->objPaymentModule->SetParentControl($this->pnlCurrentPanel);
  321. /* if($this->objCheckOutReviewModule instanceof CheckOutReviewModule)
  322. $this->objCheckOutReviewModule->Visible = false;*/
  323. $this->objOrderTotalsView->Visible = true;
  324. break;
  325. }
  326. $this->btnContinue->Text = Quasi::Translate('Continue');
  327. $this->intCurrentStage = $NextStage;
  328. }
  329. private function GoForward($NextStage)
  330. {
  331. if(null !== $this->pnlCurrentPanel)
  332. {
  333. $this->pnlCurrentPanel->Visible = false;
  334. $this->pnlCurrentPanel->RemoveChildControls(false);
  335. }
  336. switch($NextStage)
  337. {
  338. case CheckOutStage::Shipping:
  339. //the spaces make room for the CSS cart image ..
  340. $this->pnlHeading->Text = '&nbsp;&nbsp;&nbsp;' . Quasi::Translate('Shipping Options');
  341. $this->lblProgressBar->CssClass = 'ProgressBarShipping';
  342. //to debug: $this->objShippingModule = new ShippingModule($this->pnlCurrentPanel, $this, $this->objOrder, true);
  343. $this->objShippingModule = new ShippingModule($this->pnlCurrentPanel, $this, $this->objOrder);
  344. $this->intCurrentStage = CheckOutStage::Shipping;
  345. break;
  346. case CheckOutStage::Payment:
  347. $this->pnlHeading->Text = '&nbsp;&nbsp;&nbsp;' . Quasi::Translate('Payment Options');
  348. $this->lblProgressBar->CssClass = 'ProgressBarPayment';
  349. if($this->objPaymentModule instanceof PaymentModule)
  350. $this->objPaymentModule->SetParentControl($this->pnlCurrentPanel);
  351. else
  352. {
  353. $this->pnlCurrentPanel->RemoveChildControls(false);
  354. $this->objPaymentModule = new PaymentModule($this->pnlCurrentPanel, $this->objOrder);
  355. }
  356. $this->intCurrentStage = CheckOutStage::Payment;
  357. break;
  358. case CheckOutStage::Review:
  359. $this->pnlHeading->Text = '&nbsp;&nbsp;&nbsp;' . Quasi::Translate('Order Review');
  360. $this->lblProgressBar->CssClass = 'ProgressBarReview';
  361. if($this->objCheckOutReviewModule instanceof CheckOutReviewModule)
  362. {
  363. $this->objCheckOutReviewModule->RefreshView($this->objOrder);
  364. $this->objCheckOutReviewModule->SetParentControl($this->pnlCurrentPanel);
  365. }
  366. else
  367. {
  368. $this->pnlCurrentPanel->RemoveChildControls(true);
  369. $this->objCheckOutReviewModule = new CheckOutReviewModule($this->pnlCurrentPanel, $this, $this->objOrder);
  370. }
  371. //the review panel draws its own order totals
  372. $this->objOrderTotalsView->Visible = false;
  373. //We have to do a server post back to allow the header(Location:) redirect for PayPal to work
  374. // in all cases, else the browser just gets it in XML and does nothing (some complain in fact) ..
  375. $this->btnContinue->RemoveAllActions(QClickEvent::EventName);
  376. $this->btnContinue->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnContinue_Click'));
  377. $this->btnContinue->Text = Quasi::Translate('Submit');
  378. $this->intCurrentStage = CheckOutStage::Review;
  379. break;
  380. case CheckOutStage::Confirmation:
  381. $this->pnlHeading->Text = '&nbsp;&nbsp;&nbsp;' . Quasi::Translate('Your order has been received') . '.';
  382. $this->lblProgressBar->CssClass = 'ProgressBarReceipt';
  383. $this->pnlCurrentPanel->RemoveChildControls(true);
  384. //submit payment ..
  385. $this->SubmitPayment();
  386. $this->btnBack->Visible = false;
  387. $this->btnCancel->Visible = false;
  388. $this->btnContinue->Text = Quasi::Translate('Continue');
  389. // set up the confirmation panel ..
  390. $this->ShowCheckOutConfirmationModule();
  391. $this->intCurrentStage = CheckOutStage::Confirmation;
  392. break;
  393. case CheckOutStage::ShoppingCart:
  394. Quasi::Redirect('http://' . Quasi::$ServerName . __QUASI_SUBDIRECTORY__ . '/index.php/ShoppingCart');
  395. break;
  396. case CheckOutStage::Cancel:
  397. //this shouldn't happen (since we don't save til the end) but maybe:
  398. if($this->objOrder instanceof Order && null != $this->objOrder->Id)
  399. $this->objOrder->Delete();
  400. QApplication::Redirect(__QUASI_SUBDIRECTORY__ . '/index.php/Home');
  401. break;
  402. default:
  403. throw new QCallerException("Unknown Upload Stage passed.");
  404. }
  405. $this->pnlCurrentPanel->Visible = true;
  406. }
  407. public function RefreshOrderTotalsView()
  408. {
  409. $this->objOrderTotalsView->SetTotals($this->objOrder);
  410. }
  411. /**
  412. * The final act - this function recieves the signal to process payment for an Order. This
  413. * is where a PaymentAction for the order is created and triggered.
  414. * Here we also first save the order and update the order status, order_status_history - initially
  415. * to "Pending" and to "Paid" on approval. Note that if a PaymentAction fails the action itself
  416. * deletes the order so no further action is taken here in that case.
  417. *
  418. * NOTE: Payment methods that require redirecting the user away from here (eg. PayPal ) or
  419. * methods that do not accept immediate payment (Pay by Mail, Fax, wire transfer etc ..)
  420. * must naturally finish the process elsewhere so status will remain "Pending" for these.
  421. */
  422. public function SubmitPayment()
  423. {
  424. ///@todo Fixme - this doesn't work if the user hits back in browser, figure out a check here ..
  425. if( $this->blnTransactionInitiated )
  426. throw new QCallerException('Error: attempt to submit payment already initiated.');
  427. if( $this->objOrder->Id )
  428. throw new QCallerException('Error: attempt to submit payment on completed order.');
  429. $this->blnTransactionInitiated = true;
  430. $this->objOrder->StatusId = OrderStatusType::Pending;
  431. $this->objOrder->Notes = $this->objShippingModule->Notes;
  432. //save the order and get an ID (reload is automatic)..
  433. $intOrderId = $this->objOrder->Save();
  434. //make an entry into the order_status_history table
  435. $objOrderStatusHistory = new OrderStatusHistory();
  436. $objOrderStatusHistory->StatusId = OrderStatusType::Pending;
  437. $objOrderStatusHistory->OrderId = $intOrderId;
  438. $objOrderStatusHistory->Notes = $this->objShippingModule->Notes;
  439. $objOrderStatusHistory->Save();
  440. //save the order items - must be done after the order id is set ..
  441. $this->objOrder->SaveNewOrderItems();
  442. //create a payment action object ..
  443. $strActionClass = $this->objPaymentModule->SelectedMethod->ActionClassName;
  444. if(!class_exists($strActionClass))
  445. throw new QCallerException( 'Missing PaymentMethod Class: ' . $strActionClass );
  446. $objPaymentAction = new $strActionClass($this->objOrder);
  447. //retrieve credit card input and initialize payment action
  448. if($this->objPaymentModule->SelectedMethod->RequiresCcNumber)
  449. {
  450. $objPaymentAction->CCNumber = $this->objPaymentModule->txtCCNumber->Text;
  451. $objPaymentAction->CCExpirationYear = $this->objPaymentModule->lstCCExpirationYear->SelectedValue;
  452. $objPaymentAction->CCExpirationMonth = $this->objPaymentModule->lstCCExpirationMonth->SelectedValue;
  453. $objPaymentAction->CCVNumber = $this->objPaymentModule->txtCCVNumber->Text;
  454. }
  455. $objPaymentAction->TestMode = $this->objPaymentModule->SelectedMethod->TestMode;
  456. //Note: at this point PayPal Express will redirect to paypal.com ..
  457. $objPaymentAction->PreProcess();
  458. $objPaymentAction->Process();
  459. $objPaymentAction->PostProcess();
  460. //set some data for the confirmation module ..
  461. $this->strTransactionMessage = $objPaymentAction->StatusText;
  462. $this->strErrors = $objPaymentAction->Errors;
  463. $this->blnTransactionApproved = $objPaymentAction->Approved;
  464. }
  465. /**
  466. * This function is called when a purchase has been completed.
  467. * Basically it hides all the other panels/modules and shows the payment confirmation message.
  468. * Any changes to the confirmation display should be done here.
  469. */
  470. public function ShowCheckOutConfirmationModule()
  471. {
  472. $this->objCheckOutConfirmationModule = new CheckOutConfirmationModule($this->pnlCurrentPanel, $this, $this->objOrder);
  473. $strApprovedText = '<div class="heading">' . Quasi::Translate("Thank You for your purchase") . '! </div>';
  474. $strApprovedText .= '</p>' . Quasi::Translate('Your Order Number is') . ': &nbsp; &nbsp; ' . $this->objOrder->Id . ' </p>';
  475. $strApprovedText .= '</p>' . Quasi::Translate('We will email you shortly with a confirmation of your order') . '. </p>'
  476. . '</p>' . Quasi::Translate('Please make sure that you have given a correct email address with which to contact you') . '. </p>';
  477. $strDeclinedText = Quasi::Translate(" We're Sorry - Your payment has been declined - the message below may help to solve the problem:") . '. <br />';
  478. if( $this->blnTransactionApproved )
  479. $this->objCheckOutConfirmationModule->Message = $strApprovedText;
  480. else
  481. {
  482. //for testing - extra error messages ..
  483. // $msg = $strDeclinedText . '<p> Transaction Errors: <br />' . $this->strErrors . '</p>' ;
  484. // $this->objCheckOutConfirmationModule->Message = $msg ;
  485. $this->objCheckOutConfirmationModule->Message = $strDeclinedText ;
  486. }
  487. if('' != $this->strTransactionMessage)
  488. $this->objCheckOutConfirmationModule->Message .= '<p> Transaction Messages: <br />' . $this->strTransactionMessage . '</p>' ;
  489. $this->objCheckOutConfirmationModule->Visible = true;
  490. }
  491. public function Validate(){return true;}
  492. ///Gettors
  493. public function __get($strName)
  494. {
  495. switch ($strName)
  496. {
  497. case 'Errors':
  498. return $this->strErrors ;
  499. case 'Order':
  500. return $this->objOrder ;
  501. case 'ShippingAddress':
  502. return $this->objShippingModule->Address;
  503. case 'BillingAddress':
  504. return $this->objPaymentModule->Address;
  505. case 'ShippingMethod':
  506. return $this->objShippingModule->SelectedMethod;
  507. case 'PaymentMethod':
  508. return $this->objPaymentModule->SelectedMethod;
  509. case 'ShippingModule':
  510. return $this->objShippingModule;
  511. case 'TotalOunces':
  512. return $this->objOrder->fltTotalOunces;
  513. case 'TotalPounds':
  514. return $this->objOrder->intTotalPounds;
  515. case 'XAxisSize':
  516. return $this->objOrder->fltXAxisSize;
  517. case 'YAxisSize':
  518. return $this->objOrder->fltYAxisSize;
  519. case 'ZAxisSize':
  520. return $this->objOrder->fltZAxisSize;
  521. case 'CartEmpty':
  522. return $this->blnCartEmpty;
  523. default:
  524. try {
  525. return parent::__get($strName);
  526. } catch (QCallerException $objExc) {
  527. $objExc->IncrementOffset();
  528. throw $objExc;
  529. }
  530. }
  531. }
  532. ///Settors
  533. public function __set($strName, $mixValue)
  534. {
  535. switch ($strName)
  536. {
  537. case 'Order':
  538. try {
  539. return ($this->objOrder = QType::Cast($mixValue, 'Order' ));
  540. } catch (QInvalidCastException $objExc) {
  541. $objExc->IncrementOffset();
  542. throw $objExc;
  543. }
  544. default:
  545. try {
  546. return (parent::__set($strName, $mixValue));
  547. } catch (QCallerException $objExc) {
  548. $objExc->IncrementOffset();
  549. throw $objExc;
  550. }
  551. }
  552. }
  553. ////////////// temp .. ////////////////////////////////////////////////////////////////
  554. /**
  555. * This function refreshes the information in the order to match user input
  556. *@todo this should update the CheckOutReviewModule.
  557. */
  558. /* private function refreshOrderItems()
  559. {
  560. // $this->lblMessages->Text='';
  561. //rebuild Order items array according to user input (quantities)
  562. $this->aryOrderItems = array();
  563. $aryItemViews =& $this->objCheckOutEditModule->ItemListModule->aryCheckOutItemViews;
  564. foreach( $aryItemViews as $objView )
  565. {
  566. $item = $objView->objOrderItem;
  567. //objView->Quantity is from the input field
  568. $item->Quantity = $objView->Quantity;
  569. $this->aryOrderItems[] = $item;
  570. }
  571. //adjust shopping cart to match.
  572. $aryCartItems =$this->objShoppingCart->GetShoppingCartItemArray();
  573. foreach($aryCartItems as &$objCartItem )
  574. {
  575. foreach($this->aryOrderItems as $oi_index => $objOrderItem )
  576. {
  577. if($objOrderItem->ProductId != $objCartItem->ProductId)
  578. continue;
  579. //if the quantity was set to zero or less, remove from both arrays .
  580. if($objOrderItem->Quantity <= 0)
  581. {
  582. $objCartItem->Delete();
  583. unset($this->aryOrderItems[$oi_index]);
  584. }
  585. else
  586. {
  587. $objCartItem->Quantity = $objOrderItem->Quantity;
  588. $objCartItem->Save();
  589. }
  590. }
  591. }
  592. //refresh the shopping cart's idea of its contents ..
  593. $this->objShoppingCart->Reload();
  594. }*/
  595. }//end class
  596. }//end define
  597. ?>