PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/Catalog/Block/Product/Compare/List.php

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