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_Catalog
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: * Catalog products compare block
30: *
31: * @category Mage
32: * @package Mage_Catalog
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Catalog_Block_Product_Compare_List extends Mage_Catalog_Block_Product_Compare_Abstract
36: {
37: /**
38: * Product Compare items collection
39: *
40: * @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection
41: */
42: protected $_items;
43:
44: /**
45: * Compare Products comparable attributes cache
46: *
47: * @var array
48: */
49: protected $_attributes;
50:
51: /**
52: * Flag which allow/disallow to use link for as low as price
53: *
54: * @var bool
55: */
56: protected $_useLinkForAsLowAs = false;
57:
58: /**
59: * Customer id
60: *
61: * @var null|int
62: */
63: protected $_customerId = null;
64:
65: /**
66: * Retrieve url for adding product to wishlist with params
67: *
68: * @param Mage_Catalog_Model_Product $product
69: * @return string
70: */
71: public function getAddToWishlistUrl($product)
72: {
73: $continueUrl = Mage::helper('core')->urlEncode($this->getUrl('customer/account'));
74: $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
75:
76: $params = array(
77: $urlParamName => $continueUrl
78: );
79:
80: return $this->helper('wishlist')->getAddUrlWithParams($product, $params);
81: }
82:
83: /**
84: * Preparing layout
85: *
86: * @return Mage_Catalog_Block_Product_Compare_List
87: */
88: protected function _prepareLayout()
89: {
90: $headBlock = $this->getLayout()->getBlock('head');
91: if ($headBlock) {
92: $headBlock->setTitle(Mage::helper('catalog')->__('Products Comparison List') . ' - ' . $headBlock->getDefaultTitle());
93: }
94: return parent::_prepareLayout();
95: }
96:
97: /**
98: * Retrieve Product Compare items collection
99: *
100: * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection
101: */
102: public function getItems()
103: {
104: if (is_null($this->_items)) {
105: Mage::helper('catalog/product_compare')->setAllowUsedFlat(false);
106:
107: $this->_items = Mage::getResourceModel('catalog/product_compare_item_collection')
108: ->useProductItem(true)
109: ->setStoreId(Mage::app()->getStore()->getId());
110:
111: if (Mage::getSingleton('customer/session')->isLoggedIn()) {
112: $this->_items->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
113: } elseif ($this->_customerId) {
114: $this->_items->setCustomerId($this->_customerId);
115: } else {
116: $this->_items->setVisitorId(Mage::getSingleton('log/visitor')->getId());
117: }
118:
119: $this->_items
120: ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
121: ->loadComparableAttributes()
122: ->addMinimalPrice()
123: ->addTaxPercents();
124:
125: Mage::getSingleton('catalog/product_visibility')
126: ->addVisibleInSiteFilterToCollection($this->_items);
127: }
128:
129: return $this->_items;
130: }
131:
132: /**
133: * Retrieve Product Compare Attributes
134: *
135: * @return array
136: */
137: public function getAttributes()
138: {
139: if (is_null($this->_attributes)) {
140: $this->_attributes = $this->getItems()->getComparableAttributes();
141: }
142:
143: return $this->_attributes;
144: }
145:
146: /**
147: * Retrieve Product Attribute Value
148: *
149: * @param Mage_Catalog_Model_Product $product
150: * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
151: * @return string
152: */
153: public function getProductAttributeValue($product, $attribute)
154: {
155: if (!$product->hasData($attribute->getAttributeCode())) {
156: return Mage::helper('catalog')->__('N/A');
157: }
158:
159: if ($attribute->getSourceModel()
160: || in_array($attribute->getFrontendInput(), array('select','boolean','multiselect'))
161: ) {
162: //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
163: $value = $attribute->getFrontend()->getValue($product);
164: } else {
165: $value = $product->getData($attribute->getAttributeCode());
166: }
167: return ((string)$value == '') ? Mage::helper('catalog')->__('No') : $value;
168: }
169:
170: /**
171: * Retrieve Print URL
172: *
173: * @return string
174: */
175: public function getPrintUrl()
176: {
177: return $this->getUrl('*/*/*', array('_current'=>true, 'print'=>1));
178: }
179:
180: /**
181: * Setter for customer id
182: *
183: * @param int $id
184: * @return Mage_Catalog_Block_Product_Compare_List
185: */
186: public function setCustomerId($id)
187: {
188: $this->_customerId = $id;
189: return $this;
190: }
191: }
192: