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.

246 lines
10 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("SHOPPINGCARTVIEWMODULE.CLASS.PHP")){
  4. define("SHOPPINGCARTVIEWMODULE.CLASS.PHP",1);
  5. /** Class ShoppingCartViewModule - provides display/modification of the list of items in an order
  6. *
  7. * ShoppingCartViewModule is a center page module displayed on the ShoppingCart page.
  8. * It shows a detailed list of the items in an Order with quantity modification fields and a
  9. * button to go directly to the CheckOut page.
  10. *
  11. *
  12. *@author Erik Winn <erikwinnmail@yahoo.com>
  13. *
  14. *
  15. * $Id: ShoppingCartViewModule.class.php 462 2008-12-30 17:14:49Z erikwinn $
  16. *@version 0.1
  17. *
  18. *@copyright (C) 2008 by Erik Winn
  19. *@license GPL v.2
  20. This program is free software; you can redistribute it and/or modify
  21. it under the terms of the GNU General Public License as published by
  22. the Free Software Foundation; either version 2 of the License, or
  23. (at your option) any later version.
  24. This program is distributed in the hope that it will be useful,
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. GNU General Public License for more details.
  28. You should have received a copy of the GNU General Public License
  29. along with this program; if not, write to the Free Software
  30. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  31. *
  32. * @package Quasi
  33. * @subpackage Views
  34. *
  35. */
  36. class ShoppingCartViewModule extends QPanel
  37. {
  38. /**
  39. * @var ContentBlock objParentObject - the DOM parent,
  40. */
  41. protected $objParentObject;
  42. /**
  43. * @var Order objOrder - order created from cart items for account,
  44. */
  45. protected $objOrder;
  46. /**
  47. * @var ShoppingCart objShoppingCart - local reference to the current user's cart
  48. */
  49. protected $objShoppingCart;
  50. /**
  51. * @var float fltItemsTotalPrice - the total of all the line items in the cart, aka subtotal
  52. */
  53. protected $fltItemsTotalPrice;
  54. /**
  55. * @var boolean blnLoggedIn - indicate if the user is logged in.
  56. */
  57. protected $blnLoggedIn = false;
  58. /**
  59. * @var array ShoppingCartItems - a list of products as cart item Views.
  60. */
  61. public $aryShoppingCartItemViews = array();
  62. /**
  63. * @var OrderTotalsView objOrderTotalsView - panel that displays the order summary ..
  64. */
  65. public $objOrderTotalsView;
  66. ///Controls ..
  67. /**
  68. * @var QLabel lblMessage - a text label to relay messages to the user
  69. */
  70. public $lblMessage;
  71. /**
  72. * @var QLabel lblProgressBar - a progress bar depicting the first (Shopping cart) stage of checkout
  73. */
  74. public $lblProgressBar;
  75. public $btnSave;
  76. public $btnCheckOut;
  77. public function __construct( ContentBlockView $objParentObject, $intShoppingCartId=null)
  78. {
  79. $this->objParentObject =& $objParentObject;
  80. $this->objShoppingCart =& IndexPage::$objShoppingCart;
  81. try {
  82. parent::__construct($this->objParentObject);
  83. } catch (QCallerException $objExc) {
  84. $objExc->IncrementOffset();
  85. throw $objExc;
  86. }
  87. $this->Template = __QUASI_CORE_TEMPLATES__ . '/ShoppingCartViewModule.tpl.php';
  88. // if not logged in show nothing ..
  89. if( ! IndexPage::$objAccount instanceof Account )
  90. return;
  91. else
  92. $this->blnLoggedIn = true;
  93. $this->aryShoppingCartItemViews = array();
  94. $this->fltItemsTotalPrice = 0;
  95. if($this->objShoppingCart instanceof ShoppingCart )
  96. {
  97. foreach ( $this->objShoppingCart->GetShoppingCartItemArray() as $objShoppingCartItem )
  98. {
  99. $objItemView = new ShoppingCartItemView( $this, $objShoppingCartItem );
  100. $this->aryShoppingCartItemViews[] = $objItemView;
  101. }
  102. $this->objOrder = $this->objShoppingCart->CreateNewOrder(true);
  103. if($this->objOrder instanceof Order)
  104. $this->objOrderTotalsView = new OrderTotalsView($this, $this->objOrder);
  105. }
  106. $this->lblMessage = new QLabel($this);
  107. $this->lblProgressBar = new QLabel($this);
  108. $this->lblProgressBar->HtmlEntities = false;
  109. $this->lblProgressBar->CssClass = 'ProgressBarShoppingCart';
  110. $this->lblProgressBar->Text = sprintf('<span class="heading">%s</span><span class="label">%s</span>
  111. <span class="label">%s</span><span class="label">%s</span>
  112. <span class="label">%s</span><span class="label">%s</span>',
  113. STORE_NAME . ' ' . Quasi::Translate('Checkout Process') . ':',
  114. Quasi::Translate('cart'),
  115. Quasi::Translate('shipping'),
  116. Quasi::Translate('payment'),
  117. Quasi::Translate('review order'),
  118. Quasi::Translate('receipt'));
  119. $this->btnSave = new QButton($this);
  120. $this->btnSave->Text = Quasi::Translate('Update');
  121. if(IndexPage::$blnAjaxOk)
  122. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  123. else
  124. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click'));
  125. $this->btnSave->CausesValidation = QCausesValidation::SiblingsAndChildren;
  126. $this->btnCheckOut = new QLabel($this);
  127. $this->btnCheckOut->AddCssClass('button');
  128. $this->btnCheckOut->HtmlEntities = false;
  129. $this->btnCheckOut->Text = '<a href="https://' . Quasi::$ServerName . __QUASI_SUBDIRECTORY__ . '/index.php/CheckOut">'
  130. . Quasi::Translate('CheckOut') . '</a>';
  131. /* yes, it would be nice to make sure that we saved, but IE cannot redirect correctly to https
  132. so we must use a hard link until somebody figures out a way around this.
  133. $this->btnCheckOut->Text = Quasi::Translate('CheckOut');
  134. if(IndexPage::$blnAjaxOk)
  135. $this->btnCheckOut->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCheckOut_Click'));
  136. else
  137. $this->btnCheckOut->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCheckOut_Click'));
  138. */
  139. }
  140. public function RefreshTotals()
  141. {
  142. if( ! $this->objOrder instanceof Order )
  143. return;
  144. $this->fltItemsTotalPrice = 0;
  145. foreach($this->aryShoppingCartItemViews as $objItemView)
  146. $this->fltItemsTotalPrice += $objItemView->ItemTotal;
  147. $this->objOrder->ProductTotalCharged = $this->fltItemsTotalPrice;
  148. $this->objOrderTotalsView->SetTotals($this->objOrder);
  149. }
  150. public function btnSave_Click($strFormId, $strControlId, $strParameter)
  151. {
  152. foreach($this->aryShoppingCartItemViews as &$objItemView)
  153. {
  154. $objItemView->ShoppingCartItem->Quantity = $objItemView->Quantity;
  155. if($objItemView->Quantity <= 0)
  156. $objItemView->ShoppingCartItem->Delete();
  157. else
  158. $objItemView->ShoppingCartItem->Save();
  159. }
  160. $this->objShoppingCart->Reload();
  161. $this->RefreshTotals();
  162. $this->lblMessage->Text = Quasi::Translate('Shopping Cart Saved') . '!';
  163. }
  164. //Note: unused due to IE ssl redirect incompetence ..
  165. public function btnCheckOut_Click($strFormId, $strControlId, $strParameter)
  166. {
  167. foreach($this->aryShoppingCartItemViews as &$objItemView)
  168. {
  169. $objItemView->ShoppingCartItem->Quantity = $objItemView->Quantity;
  170. $objItemView->ShoppingCartItem->Save();
  171. }
  172. Quasi::Redirect('https://' . Quasi::$ServerName . __QUASI_SUBDIRECTORY__ . '/index.php/CheckOut');
  173. }
  174. public function __get($strName)
  175. {
  176. switch ($strName)
  177. {
  178. case 'ShoppingCart':
  179. return $this->objShoppingCart ;
  180. case 'ItemsTotalPrice':
  181. return $this->fltItemsTotalPrice ;
  182. case 'Tax':
  183. return $this->objOrder->Tax;
  184. case 'LoggedIn':
  185. return $this->blnLoggedIn;
  186. default:
  187. try {
  188. return parent::__get($strName);
  189. } catch (QCallerException $objExc) {
  190. $objExc->IncrementOffset();
  191. throw $objExc;
  192. }
  193. }
  194. }
  195. public function __set($strName, $mixValue)
  196. {
  197. switch ($strName)
  198. {
  199. case 'ShoppingCart':
  200. try {
  201. return ($this->objShoppingCart = QType::Cast($mixValue, 'ShoppingCart'));
  202. } catch (QInvalidCastException $objExc) {
  203. $objExc->IncrementOffset();
  204. throw $objExc;
  205. }
  206. default:
  207. try {
  208. return (parent::__set($strName, $mixValue));
  209. } catch (QCallerException $objExc) {
  210. $objExc->IncrementOffset();
  211. throw $objExc;
  212. }
  213. }
  214. }
  215. }// end class
  216. }//end define shield
  217. ?>