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.

180 lines
6.8 KiB

12 years ago
  1. <?php
  2. /**
  3. * CheckOutItemView - provides a panel for the display of a single item in an Order
  4. *
  5. * This class displays the Order item with a field for adjusting the quantity and an
  6. * optional thumbnail image of the item.
  7. *
  8. * If Modifiable is false the quantity field is a label and not adjustable, if true it is an
  9. * input field allowing the user to change the quantity of the item.
  10. *
  11. *@todo
  12. * - implement image support
  13. * - base class most of this and use for ShoppingCartItemView as well, perhaps renaming to
  14. * the more generic term OrderItemView; this needs to provide functionality like a DataGrid
  15. * keeping an array of columns with AddColumn(foo) ..
  16. *
  17. *@author Erik Winn <erikwinnmail@yahoo.com>
  18. *
  19. * $Id: CheckOutItemView.class.php 286 2008-10-10 23:33:36Z erikwinn $
  20. *@version 0.1
  21. *
  22. *@copyright (C) 2008 by Erik Winn
  23. *@license GPL v.2
  24. This program is free software; you can redistribute it and/or modify
  25. it under the terms of the GNU General Public License as published by
  26. the Free Software Foundation; either version 2 of the License, or
  27. (at your option) any later version.
  28. This program is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. GNU General Public License for more details.
  32. You should have received a copy of the GNU General Public License
  33. along with this program; if not, write to the Free Software
  34. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  35. *
  36. * @package Quasi
  37. * @subpackage Classes
  38. */
  39. class CheckOutItemView extends QPanel
  40. {
  41. /**
  42. * @var QPanel objControlBlock - DOM parent .. usually a CheckOutItemListModule
  43. */
  44. protected $objControlBlock;
  45. /**
  46. * @var Product objProduct - local instance of the Product item
  47. */
  48. protected $objProduct;
  49. /**
  50. * @var boolean blnModifiable - if true, the quantity fields are rendered as input, otherwise as labels
  51. */
  52. protected $blnModifiable;
  53. /**
  54. * @var float fltItemTotal - total price of this line item (*quantity)
  55. */
  56. protected $fltItemTotal;
  57. /**
  58. * Note: this is public to avoid an obscure php bug that may have dissappeared by the
  59. * time you see this .. fixme if possible.
  60. * @var OrderItem objOrderItem - Local instance of the OrderItem
  61. */
  62. public $objOrderItem;
  63. public $ctlProductImage;
  64. public $lblProductName;
  65. public $lblItemPrice;
  66. public $lblTotalPrice;
  67. public $lblQuantity;
  68. public $txtQuantity;
  69. /**
  70. *
  71. *@param QPanel objParentObject - the panel in which this item view is rendered.
  72. *@param OrderItem objOrderItem - the order item to be displayed
  73. *@param boolean blnModifiable - quantity may be modified if true
  74. */
  75. public function __construct($objParentObject, $objOrderItem, $blnModifiable=true)
  76. {
  77. try {
  78. parent::__construct($objParentObject);
  79. } catch (QCallerException $objExc) {
  80. $objExc->IncrementOffset();
  81. throw $objExc;
  82. }
  83. $this->objControlBlock =& $objParentObject;
  84. $this->objOrderItem =& $objOrderItem;
  85. $this->blnModifiable = $blnModifiable;
  86. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/CheckOutItemView.tpl.php';
  87. $this->objProduct = Product::Load($this->objOrderItem->ProductId);
  88. $this->lblProductName = new QLabel($this);
  89. $this->lblProductName->CssClass = 'ProductName';
  90. $this->lblProductName->Text = $this->objProduct->Model;
  91. $this->lblItemPrice = new QLabel($this);
  92. $this->lblItemPrice->CssClass = 'ItemPrice';
  93. $this->lblItemPrice->Text = money_format('%n',$this->objProduct->RetailPrice);
  94. $this->lblTotalPrice = new QLabel($this);
  95. $this->lblTotalPrice->CssClass = 'ItemTotal';
  96. $this->fltItemTotal = $this->objProduct->RetailPrice * $this->objOrderItem->Quantity;
  97. $this->lblTotalPrice->Text = money_format('%n', $this->fltItemTotal );
  98. if($blnModifiable)
  99. {
  100. $this->txtQuantity = new QIntegerTextBox($this);
  101. $this->txtQuantity->Text = $this->objOrderItem->Quantity;
  102. $this->txtQuantity->CssClass = 'ProductQtyBox';
  103. if(IndexPage::$blnAjaxOk)
  104. $this->txtQuantity->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'InitTotal') );
  105. else
  106. $this->txtQuantity->AddAction(new QChangeEvent(), new QServerControlAction($this, 'InitTotal') );
  107. }
  108. else
  109. {
  110. $this->lblQuantity = new QLabel($this);
  111. $this->lblQuantity->Text = $this->objOrderItem->Quantity;
  112. }
  113. }
  114. /**
  115. *@param string strFormId - the main QForm's identifier
  116. *@param string strControlId - the calling Control's id
  117. *@param string strParameters - ingored, as are the above ..
  118. */
  119. public function InitTotal( $strFormId, $strControlId, $strParameters)
  120. {
  121. $this->objOrderItem->Quantity = $this->txtQuantity->Text;
  122. $this->fltItemTotal = $this->objProduct->RetailPrice * $this->objOrderItem->Quantity;
  123. $this->lblTotalPrice->Text = money_format('%n', $this->fltItemTotal );
  124. $this->MarkAsModified();
  125. $this->Refresh();
  126. if($this->objControlBlock instanceof CheckOutItemListModule )
  127. {
  128. $this->objControlBlock->MarkAsModified();
  129. $this->objControlBlock->RefreshTotalPrice();
  130. }
  131. }
  132. public function __get($strName)
  133. {
  134. switch ($strName)
  135. {
  136. case 'Modifiable':
  137. return $this->blnModifiable ;
  138. case 'OrderItem':
  139. return $this->objOrderItem ;
  140. case 'ItemTotal':
  141. return $this->fltItemTotal ;
  142. //if user modified this differs from the quantity in the OrderItem
  143. case 'Quantity':
  144. if($this->blnModifiable)
  145. return $this->txtQuantity->Text ;
  146. else
  147. return $this->lblQuantity->Text;
  148. default:
  149. try {
  150. return parent::__get($strName);
  151. } catch (QCallerException $objExc) {
  152. $objExc->IncrementOffset();
  153. throw $objExc;
  154. }
  155. }
  156. }
  157. }
  158. ?>