PageRenderTime 20ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php

https://gitlab.com/blingbang2016/shop
PHP | 186 lines | 89 code | 11 blank | 86 comment | 6 complexity | 8ef6eeee9f331eae1b37290159b00704 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Wishlist
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Wishlist block customer items
  28. *
  29. * @category Mage
  30. * @package Mage_Wishlist
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Wishlist_Block_Customer_Wishlist extends Mage_Wishlist_Block_Abstract
  34. {
  35. /*
  36. * List of product options rendering configurations by product type
  37. */
  38. protected $_optionsCfg = array();
  39. /**
  40. * Add wishlist conditions to collection
  41. *
  42. * @param Mage_Wishlist_Model_Mysql4_Item_Collection $collection
  43. * @return Mage_Wishlist_Block_Customer_Wishlist
  44. */
  45. protected function _prepareCollection($collection)
  46. {
  47. $collection->setInStockFilter(true)->setOrder('added_at', 'ASC');
  48. return $this;
  49. }
  50. /**
  51. * Preparing global layout
  52. *
  53. * @return Mage_Wishlist_Block_Customer_Wishlist
  54. */
  55. protected function _prepareLayout()
  56. {
  57. parent::_prepareLayout();
  58. $headBlock = $this->getLayout()->getBlock('head');
  59. if ($headBlock) {
  60. $headBlock->setTitle($this->__('My Wishlist'));
  61. }
  62. }
  63. /**
  64. * Retrieve Back URL
  65. *
  66. * @return string
  67. */
  68. public function getBackUrl()
  69. {
  70. return $this->getUrl('customer/account/');
  71. }
  72. /**
  73. * Sets all options render configurations
  74. *
  75. * @deprecated after 1.6.2.0
  76. * @param null|array $optionCfg
  77. * @return Mage_Wishlist_Block_Customer_Wishlist
  78. */
  79. public function setOptionsRenderCfgs($optionCfg)
  80. {
  81. $this->_optionsCfg = $optionCfg;
  82. return $this;
  83. }
  84. /**
  85. * Returns all options render configurations
  86. *
  87. * @deprecated after 1.6.2.0
  88. * @return array
  89. */
  90. public function getOptionsRenderCfgs()
  91. {
  92. return $this->_optionsCfg;
  93. }
  94. /*
  95. * Adds config for rendering product type options
  96. *
  97. * @deprecated after 1.6.2.0
  98. * @param string $productType
  99. * @param string $helperName
  100. * @param null|string $template
  101. * @return Mage_Wishlist_Block_Customer_Wishlist
  102. */
  103. public function addOptionsRenderCfg($productType, $helperName, $template = null)
  104. {
  105. $this->_optionsCfg[$productType] = array('helper' => $helperName, 'template' => $template);
  106. return $this;
  107. }
  108. /**
  109. * Returns html for showing item options
  110. *
  111. * @deprecated after 1.6.2.0
  112. * @param string $productType
  113. * @return array|null
  114. */
  115. public function getOptionsRenderCfg($productType)
  116. {
  117. if (isset($this->_optionsCfg[$productType])) {
  118. return $this->_optionsCfg[$productType];
  119. } elseif (isset($this->_optionsCfg['default'])) {
  120. return $this->_optionsCfg['default'];
  121. } else {
  122. return null;
  123. }
  124. }
  125. /**
  126. * Returns html for showing item options
  127. *
  128. * @deprecated after 1.6.2.0
  129. * @param Mage_Wishlist_Model_Item $item
  130. * @return string
  131. */
  132. public function getDetailsHtml(Mage_Wishlist_Model_Item $item)
  133. {
  134. $cfg = $this->getOptionsRenderCfg($item->getProduct()->getTypeId());
  135. if (!$cfg) {
  136. return '';
  137. }
  138. $helper = Mage::helper($cfg['helper']);
  139. if (!($helper instanceof Mage_Catalog_Helper_Product_Configuration_Interface)) {
  140. Mage::throwException($this->__("Helper for wishlist options rendering doesn't implement required interface."));
  141. }
  142. $block = $this->getChild('item_options');
  143. if (!$block) {
  144. return '';
  145. }
  146. if ($cfg['template']) {
  147. $template = $cfg['template'];
  148. } else {
  149. $cfgDefault = $this->getOptionsRenderCfg('default');
  150. if (!$cfgDefault) {
  151. return '';
  152. }
  153. $template = $cfgDefault['template'];
  154. }
  155. return $block->setTemplate($template)
  156. ->setOptionList($helper->getOptions($item))
  157. ->toHtml();
  158. }
  159. /**
  160. * Returns qty to show visually to user
  161. *
  162. * @deprecated after 1.6.2.0
  163. * @param Mage_Wishlist_Model_Item $item
  164. * @return float
  165. */
  166. public function getAddToCartQty(Mage_Wishlist_Model_Item $item)
  167. {
  168. $qty = $this->getQty($item);
  169. return $qty ? $qty : 1;
  170. }
  171. }