00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Catalog_Block_Product_Compare_List extends Mage_Catalog_Block_Product_Abstract
00036 {
00037
00038
00039
00040
00041
00042 protected $_items;
00043
00044
00045
00046
00047
00048
00049 protected $_attributes;
00050
00051
00052
00053
00054
00055
00056 protected function _prepareLayout()
00057 {
00058 if ($headBlock = $this->getLayout()->getBlock('head')) {
00059 $headBlock->setTitle(Mage::helper('catalog')->__('Compare Products List') . ' - ' . $headBlock->getDefaultTitle());
00060 }
00061 return parent::_prepareLayout();
00062 }
00063
00064
00065
00066
00067
00068
00069 public function getItems()
00070 {
00071 if (is_null($this->_items)) {
00072 Mage::helper('catalog/product_compare')->setAllowUsedFlat(false);
00073 $this->_items = Mage::getResourceModel('catalog/product_compare_item_collection')
00074 ->useProductItem(true)
00075 ->setStoreId(Mage::app()->getStore()->getId());
00076
00077 if (Mage::getSingleton('customer/session')->isLoggedIn()) {
00078 $this->_items
00079 ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
00080 }
00081 else {
00082 $this->_items
00083 ->setVisitorId(Mage::getSingleton('log/visitor')->getId());
00084 }
00085
00086 $this->_items
00087 ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
00088 ->loadComparableAttributes()
00089 ->addMinimalPrice()
00090 ->addTaxPercents();
00091
00092 Mage::getSingleton('catalog/product_visibility')
00093 ->addVisibleInSiteFilterToCollection($this->_items);
00094 }
00095
00096 return $this->_items;
00097 }
00098
00099
00100
00101
00102
00103
00104 public function getAttributes()
00105 {
00106 if (is_null($this->_attributes)) {
00107 $this->_attributes = $this->getItems()->getComparableAttributes();
00108 }
00109
00110 return $this->_attributes;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120 public function getProductAttributeValue($product, $attribute)
00121 {
00122 if (!$product->hasData($attribute->getAttributeCode())) {
00123 return ' ';
00124 }
00125
00126 if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select','boolean','multiselect'))) {
00127
00128 $value = $attribute->getFrontend()->getValue($product);
00129 }
00130 else {
00131 $value = $product->getData($attribute->getAttributeCode());
00132 }
00133 return $value ? $value : ' ';
00134 }
00135
00136
00137
00138
00139
00140
00141 public function getPrintUrl()
00142 {
00143 return $this->getUrl('*/*/*', array('_current'=>true, 'print'=>1));
00144 }
00145 }