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.

600 lines
24 KiB

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