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.

154 lines
4.8 KiB

  1. <?php
  2. /**
  3. * CheckOutItemController - 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 ShoppingCartItemController 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 <sidewalksoftware@gmail.com>
  18. *
  19. *@version 0.3
  20. *
  21. * @package Quinta
  22. * @subpackage Classes
  23. */
  24. class CheckOutItemController extends QPanel{
  25. /**
  26. * @var QPanel objControlBlock - DOM parent .. usually a CheckOutItemListModule
  27. */
  28. protected $objControlBlock;
  29. /**
  30. * @var Product objProduct - local instance of the Product item
  31. */
  32. protected $objProduct;
  33. /**
  34. * @var boolean blnModifiable - if true, the quantity fields are rendered as input, otherwise as labels
  35. */
  36. protected $blnModifiable;
  37. /**
  38. * @var float fltItemTotal - total price of this line item (*quantity)
  39. */
  40. protected $fltItemTotal;
  41. /**
  42. * Note: this is public to avoid an obscure php bug that may have dissappeared by the
  43. * time you see this .. fixme if possible.
  44. * @var OrderItem objOrderItem - Local instance of the OrderItem
  45. */
  46. public $objOrderItem;
  47. public $ctlProductImage;
  48. public $lblProductName;
  49. public $lblItemPrice;
  50. public $lblTotalPrice;
  51. public $lblQuantity;
  52. public $txtQuantity;
  53. /**
  54. *
  55. *@param QPanel objParentObject - the panel in which this item view is rendered.
  56. *@param OrderItem objOrderItem - the order item to be displayed
  57. *@param boolean blnModifiable - quantity may be modified if true
  58. */
  59. public function __construct($objParentObject, $objOrderItem, $blnModifiable=true){
  60. try {
  61. parent::__construct($objParentObject);
  62. } catch (QCallerException $objExc) {
  63. $objExc->IncrementOffset();
  64. throw $objExc;
  65. }
  66. $this->objControlBlock =& $objParentObject;
  67. $this->objOrderItem =& $objOrderItem;
  68. $this->blnModifiable = $blnModifiable;
  69. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/CheckOutItemView.tpl.php';
  70. $this->objProduct = Product::Load($this->objOrderItem->ProductId);
  71. $this->lblProductName = new QLabel($this);
  72. $this->lblProductName->CssClass = 'ProductName';
  73. $this->lblProductName->Text = $this->objProduct->Model;
  74. $this->lblItemPrice = new QLabel($this);
  75. $this->lblItemPrice->CssClass = 'ItemPrice';
  76. $this->lblItemPrice->Text = money_format('%n',$this->objProduct->RetailPrice);
  77. $this->lblTotalPrice = new QLabel($this);
  78. $this->lblTotalPrice->CssClass = 'ItemTotal';
  79. $this->fltItemTotal = $this->objProduct->RetailPrice * $this->objOrderItem->Quantity;
  80. $this->lblTotalPrice->Text = money_format('%n', $this->fltItemTotal );
  81. if($blnModifiable)
  82. {
  83. $this->txtQuantity = new QIntegerTextBox($this);
  84. $this->txtQuantity->Text = $this->objOrderItem->Quantity;
  85. $this->txtQuantity->CssClass = 'ProductQtyBox';
  86. if(IndexPage::$blnAjaxOk)
  87. $this->txtQuantity->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'InitTotal') );
  88. else
  89. $this->txtQuantity->AddAction(new QChangeEvent(), new QServerControlAction($this, 'InitTotal') );
  90. }
  91. else
  92. {
  93. $this->lblQuantity = new QLabel($this);
  94. $this->lblQuantity->Text = $this->objOrderItem->Quantity;
  95. }
  96. }
  97. /**
  98. *@param string strFormId - the main QForm's identifier
  99. *@param string strControlId - the calling Control's id
  100. *@param string strParameters - ingored, as are the above ..
  101. */
  102. public function InitTotal( $strFormId, $strControlId, $strParameters){
  103. $this->objOrderItem->Quantity = $this->txtQuantity->Text;
  104. $this->fltItemTotal = $this->objProduct->RetailPrice * $this->objOrderItem->Quantity;
  105. $this->lblTotalPrice->Text = money_format('%n', $this->fltItemTotal );
  106. $this->MarkAsModified();
  107. $this->Refresh();
  108. if($this->objControlBlock instanceof CheckOutItemListModule ){
  109. $this->objControlBlock->MarkAsModified();
  110. $this->objControlBlock->RefreshTotalPrice();
  111. }
  112. }
  113. public function __get($strName){
  114. switch ($strName){
  115. case 'Modifiable':
  116. return $this->blnModifiable ;
  117. case 'OrderItem':
  118. return $this->objOrderItem ;
  119. case 'ItemTotal':
  120. return $this->fltItemTotal ;
  121. //if user modified this differs from the quantity in the OrderItem
  122. case 'Quantity':
  123. if($this->blnModifiable)
  124. return $this->txtQuantity->Text ;
  125. else
  126. return $this->lblQuantity->Text;
  127. default:
  128. try {
  129. return parent::__get($strName);
  130. } catch (QCallerException $objExc) {
  131. $objExc->IncrementOffset();
  132. throw $objExc;
  133. }
  134. }
  135. }
  136. }
  137. ?>