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.

156 lines
6.4 KiB

13 years ago
  1. <?php
  2. /**
  3. * ShopingCartItemView - provides a panel for the display of a single item in the cart
  4. *
  5. * This class displays the shopping cart item with a field for adjusting the quantity
  6. *
  7. *@author Erik Winn <erikwinnmail@yahoo.com>
  8. *
  9. *
  10. * $Id: ShoppingCartItemView.class.php 286 2008-10-10 23:33:36Z erikwinn $
  11. *@version 0.1
  12. *
  13. *@copyright (C) 2008 by Erik Winn
  14. *@license GPL v.2
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2 of the License, or
  18. (at your option) any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  26. *
  27. * @package Quasi
  28. * @subpackage Classes
  29. */
  30. class ShoppingCartItemView extends QPanel
  31. {
  32. protected $objControlBlock;
  33. // Local instance of the ShoppingCartItem
  34. protected $objShoppingCartItem;
  35. protected $objProduct;
  36. protected $fltItemTotal;
  37. public $ctlProductImage;
  38. public $lblProductName;
  39. public $lblDimensions;
  40. public $lblItemPrice;
  41. public $lblTotalPrice;
  42. public $btnRemove;
  43. public $txtQuantity;
  44. public function __construct($objControlBlock, ShoppingCartItem $objShoppingCartItem)
  45. {
  46. $this->objControlBlock = $objControlBlock;
  47. $this->objShoppingCartItem = $objShoppingCartItem;
  48. try {
  49. parent::__construct($objControlBlock);
  50. } catch (QCallerException $objExc) {
  51. $objExc->IncrementOffset();
  52. throw $objExc;
  53. }
  54. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/ShoppingCartItemView.tpl.php';
  55. $this->objProduct = Product::Load($this->objShoppingCartItem->ProductId);
  56. $this->lblProductName = new QLabel($this);
  57. $this->lblProductName->HtmlEntities = false;
  58. $this->lblProductName->Text = '<a href="'. __QUASI_SUBDIRECTORY__ . '/index.php/Products/'
  59. . $this->objProduct->Id . '">' . $this->objProduct->Model . '</a>';
  60. $this->ctlProductImage = new ProductImageLabel($this, $this->objProduct->Id, ImageSizeType::Thumb, 48, 48);
  61. $strHeight = number_format( $this->objProduct->Height , 2 );
  62. $strWidth = number_format( $this->objProduct->Width , 2 );
  63. $this->lblDimensions = new QLabel($this);
  64. $this->lblDimensions->Text = $strHeight . ' x ' . $strWidth;
  65. $this->btnRemove = new QImageButton($this);
  66. $this->btnRemove->ImageUrl = __QUASI_CORE_IMAGES__ . '/square_button_small_grey.gif';
  67. $this->btnRemove->ActionParameter = $this->objProduct->Id;
  68. $strWarning = Quasi::Translate('Are you SURE you want to remove this item') . ' ?';
  69. $this->btnRemove->AddAction(new QClickEvent(), new QConfirmAction($strWarning));
  70. if(IndexPage::$blnAjaxOk)
  71. $this->btnRemove->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnRemoveItem_Click'));
  72. else
  73. $this->btnRemove->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnRemoveItem_Click'));
  74. $this->lblItemPrice = new QLabel($this);
  75. $this->lblItemPrice->CssClass = 'ItemPrice';
  76. $this->lblItemPrice->Text = money_format('%n',$this->objProduct->RetailPrice);
  77. $this->txtQuantity = new QIntegerTextBox($this);
  78. $this->txtQuantity->CssClass = 'ProductQtyBox';
  79. $this->txtQuantity->Text = $this->objShoppingCartItem->Quantity;
  80. $this->txtQuantity->Minimum = 0;
  81. $this->txtQuantity->Maximum = MAX_PRODUCT_QUANTITY;
  82. $this->txtQuantity->CausesValidation = $this->txtQuantity;
  83. if(IndexPage::$blnAjaxOk)
  84. $this->txtQuantity->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'InitTotal') );
  85. else
  86. $this->txtQuantity->AddAction(new QChangeEvent(), new QServerControlAction($this, 'InitTotal') );
  87. $this->fltItemTotal = $this->objProduct->RetailPrice * $this->objShoppingCartItem->Quantity;
  88. $this->lblTotalPrice = new QLabel($this);
  89. $this->lblTotalPrice->CssClass = 'ItemTotal';
  90. $this->lblTotalPrice->Text = money_format('%n', $this->fltItemTotal );
  91. }
  92. /**
  93. *@param string strFormId - the main QForm's identifier
  94. *@param string strControlId - the calling Control's id
  95. *@param string strParameters - ingored, as are the above ..
  96. */
  97. public function InitTotal( $strFormId, $strControlId, $strParameters)
  98. {
  99. $this->objShoppingCartItem->Quantity = $this->txtQuantity->Text;
  100. $this->fltItemTotal = $this->objProduct->RetailPrice * $this->objShoppingCartItem->Quantity;
  101. $this->lblTotalPrice->Text = money_format('%n', $this->fltItemTotal );
  102. $this->objControlBlock->RefreshTotals();
  103. }
  104. /**
  105. * This removes the item when the user clicks the remove button - Note that the
  106. * ShoppingCart function also refreshes the page (a quick fix to redraw the items ..)
  107. */
  108. public function btnRemoveItem_Click($strFormId, $strControlId, $intProductId)
  109. {
  110. IndexPage::$objShoppingCart->RemoveItem($intProductId);
  111. }
  112. public function __get($strName)
  113. {
  114. switch ($strName)
  115. {
  116. case 'ShoppingCartItem':
  117. return $this->objShoppingCartItem ;
  118. case 'Quantity':
  119. return $this->txtQuantity->Text ;
  120. case 'ItemTotal':
  121. return $this->fltItemTotal ;
  122. default:
  123. try {
  124. return parent::__get($strName);
  125. } catch (QCallerException $objExc) {
  126. $objExc->IncrementOffset();
  127. throw $objExc;
  128. }
  129. }
  130. }
  131. }
  132. ?>