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@magentocommerce.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.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Wishlist
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Wishlist block customer items
30: *
31: * @category Mage
32: * @package Mage_Wishlist
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Wishlist_Block_Customer_Wishlist extends Mage_Wishlist_Block_Abstract
36: {
37: /*
38: * List of product options rendering configurations by product type
39: */
40: protected $_optionsCfg = array();
41:
42: /**
43: * Add wishlist conditions to collection
44: *
45: * @param Mage_Wishlist_Model_Mysql4_Item_Collection $collection
46: * @return Mage_Wishlist_Block_Customer_Wishlist
47: */
48: protected function _prepareCollection($collection)
49: {
50: $collection->setInStockFilter(true)->setOrder('added_at', 'ASC');
51: return $this;
52: }
53:
54: /**
55: * Preparing global layout
56: *
57: * @return Mage_Wishlist_Block_Customer_Wishlist
58: */
59: protected function _prepareLayout()
60: {
61: parent::_prepareLayout();
62: $headBlock = $this->getLayout()->getBlock('head');
63: if ($headBlock) {
64: $headBlock->setTitle($this->__('My Wishlist'));
65: }
66: }
67:
68: /**
69: * Retrieve Back URL
70: *
71: * @return string
72: */
73: public function getBackUrl()
74: {
75: return $this->getUrl('customer/account/');
76: }
77:
78: /**
79: * Sets all options render configurations
80: *
81: * @deprecated after 1.6.2.0
82: * @param null|array $optionCfg
83: * @return Mage_Wishlist_Block_Customer_Wishlist
84: */
85: public function setOptionsRenderCfgs($optionCfg)
86: {
87: $this->_optionsCfg = $optionCfg;
88: return $this;
89: }
90:
91: /**
92: * Returns all options render configurations
93: *
94: * @deprecated after 1.6.2.0
95: * @return array
96: */
97: public function getOptionsRenderCfgs()
98: {
99: return $this->_optionsCfg;
100: }
101:
102: /*
103: * Adds config for rendering product type options
104: *
105: * @deprecated after 1.6.2.0
106: * @param string $productType
107: * @param string $helperName
108: * @param null|string $template
109: * @return Mage_Wishlist_Block_Customer_Wishlist
110: */
111: public function addOptionsRenderCfg($productType, $helperName, $template = null)
112: {
113: $this->_optionsCfg[$productType] = array('helper' => $helperName, 'template' => $template);
114: return $this;
115: }
116:
117: /**
118: * Returns html for showing item options
119: *
120: * @deprecated after 1.6.2.0
121: * @param string $productType
122: * @return array|null
123: */
124: public function getOptionsRenderCfg($productType)
125: {
126: if (isset($this->_optionsCfg[$productType])) {
127: return $this->_optionsCfg[$productType];
128: } elseif (isset($this->_optionsCfg['default'])) {
129: return $this->_optionsCfg['default'];
130: } else {
131: return null;
132: }
133: }
134:
135: /**
136: * Returns html for showing item options
137: *
138: * @deprecated after 1.6.2.0
139: * @param Mage_Wishlist_Model_Item $item
140: * @return string
141: */
142: public function getDetailsHtml(Mage_Wishlist_Model_Item $item)
143: {
144: $cfg = $this->getOptionsRenderCfg($item->getProduct()->getTypeId());
145: if (!$cfg) {
146: return '';
147: }
148:
149: $helper = Mage::helper($cfg['helper']);
150: if (!($helper instanceof Mage_Catalog_Helper_Product_Configuration_Interface)) {
151: Mage::throwException($this->__("Helper for wishlist options rendering doesn't implement required interface."));
152: }
153:
154: $block = $this->getChild('item_options');
155: if (!$block) {
156: return '';
157: }
158:
159: if ($cfg['template']) {
160: $template = $cfg['template'];
161: } else {
162: $cfgDefault = $this->getOptionsRenderCfg('default');
163: if (!$cfgDefault) {
164: return '';
165: }
166: $template = $cfgDefault['template'];
167: }
168:
169: return $block->setTemplate($template)
170: ->setOptionList($helper->getOptions($item))
171: ->toHtml();
172: }
173:
174: /**
175: * Returns qty to show visually to user
176: *
177: * @deprecated after 1.6.2.0
178: * @param Mage_Wishlist_Model_Item $item
179: * @return float
180: */
181: public function getAddToCartQty(Mage_Wishlist_Model_Item $item)
182: {
183: $qty = $this->getQty($item);
184: return $qty ? $qty : 1;
185: }
186: }
187: