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 abstract class Mage_Catalog_Block_Product_Abstract extends Mage_Core_Block_Template
00036 {
00037 private $_priceBlock = array();
00038 private $_priceBlockDefaultTemplate = 'catalog/product/price.phtml';
00039 private $_tierPriceDefaultTemplate = 'catalog/product/view/tierprices.phtml';
00040 private $_priceBlockTypes = array();
00041
00042 private $_reviewsHelperBlock;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 public function getAddToCartUrl($product, $additional = array())
00053 {
00054 if ($product->getTypeInstance(true)->hasRequiredOptions($product)) {
00055 $url = $product->getProductUrl();
00056 $link = (strpos($url, '?') !== false) ? '&' : '?';
00057 return $url . $link . 'options=cart';
00058 }
00059 return $this->helper('checkout/cart')->getAddUrl($product, $additional);
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 public function getAddToWishlistUrl($product)
00069 {
00070 return $this->getUrl('wishlist/index/add',array('product'=>$product->getId()));
00071 }
00072
00073
00074
00075
00076
00077
00078
00079 public function getAddToCompareUrl($product)
00080 {
00081 return $this->helper('catalog/product_compare')->getAddUrl($product);
00082 }
00083
00084 public function getMinimalQty($product)
00085 {
00086 if ($stockItem = $product->getStockItem()) {
00087 return $stockItem->getMinSaleQty()>1 ? $stockItem->getMinSaleQty()*1 : null;
00088 }
00089 return null;
00090 }
00091
00092 protected function _getPriceBlock($productTypeId)
00093 {
00094 if (!isset($this->_priceBlock[$productTypeId])) {
00095 $block = 'catalog/product_price';
00096 if (isset($this->_priceBlockTypes[$productTypeId])) {
00097 if ($this->_priceBlockTypes[$productTypeId]['block'] != '') {
00098 $block = $this->_priceBlockTypes[$productTypeId]['block'];
00099 }
00100 }
00101 $this->_priceBlock[$productTypeId] = $this->getLayout()->createBlock($block);
00102 }
00103 return $this->_priceBlock[$productTypeId];
00104 }
00105
00106 protected function _getPriceBlockTemplate($productTypeId)
00107 {
00108 if (isset($this->_priceBlockTypes[$productTypeId])) {
00109 if ($this->_priceBlockTypes[$productTypeId]['template'] != '') {
00110 return $this->_priceBlockTypes[$productTypeId]['template'];
00111 }
00112 }
00113 return $this->_priceBlockDefaultTemplate;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122 public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix='')
00123 {
00124 return $this->_getPriceBlock($product->getTypeId())
00125 ->setTemplate($this->_getPriceBlockTemplate($product->getTypeId()))
00126 ->setProduct($product)
00127 ->setDisplayMinimalPrice($displayMinimalPrice)
00128 ->setIdSuffix($idSuffix)
00129 ->toHtml();
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139 public function addPriceBlockType($type, $block = '', $template = '')
00140 {
00141 if ($type) {
00142 $this->_priceBlockTypes[$type] = array(
00143 'block' => $block,
00144 'template' => $template
00145 );
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 public function getReviewsSummaryHtml(Mage_Catalog_Model_Product $product, $templateType = false, $displayIfNoReviews = false)
00158 {
00159 $this->_initReviewsHelperBlock();
00160 return $this->_reviewsHelperBlock->getSummaryHtml($product, $templateType, $displayIfNoReviews);
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 public function addReviewSummaryTemplate($type, $template)
00170 {
00171 $this->_initReviewsHelperBlock();
00172 $this->_reviewsHelperBlock->addTemplate($type, $template);
00173 }
00174
00175
00176
00177
00178
00179 protected function _initReviewsHelperBlock()
00180 {
00181 if (!$this->_reviewsHelperBlock) {
00182 $this->_reviewsHelperBlock = $this->getLayout()->createBlock('review/helper');
00183 }
00184 }
00185
00186
00187
00188
00189
00190
00191 public function getProduct()
00192 {
00193 if (!$this->hasData('product')) {
00194 $this->setData('product', Mage::registry('product'));
00195 }
00196 return $this->getData('product');
00197 }
00198
00199 public function getTierPriceTemplate()
00200 {
00201 if (!$this->hasData('tier_price_template')) {
00202 return $this->_tierPriceDefaultTemplate;
00203 }
00204
00205 return $this->getData('tier_price_template');
00206 }
00207
00208
00209
00210
00211
00212 public function getTierPriceHtml($product = null)
00213 {
00214 if (is_null($product)) {
00215 $product = $this->getProduct();
00216 }
00217 return $this->_getPriceBlock($product->getTypeId())
00218 ->setTemplate($this->getTierPriceTemplate())
00219 ->setProduct($product)
00220 ->setInGrouped($this->getProduct()->isGrouped())
00221 ->toHtml();
00222 }
00223
00224
00225
00226
00227
00228
00229
00230 public function getTierPrices($product = null)
00231 {
00232 if (is_null($product)) {
00233 $product = $this->getProduct();
00234 }
00235 $prices = $product->getFormatedTierPrice();
00236
00237 $res = array();
00238 if (is_array($prices)) {
00239 foreach ($prices as $price) {
00240 $price['price_qty'] = $price['price_qty']*1;
00241 if ($product->getPrice() != $product->getFinalPrice()) {
00242 if ($price['price']<$product->getFinalPrice()) {
00243 $price['savePercent'] = ceil(100 - (( 100/$product->getFinalPrice() ) * $price['price'] ));
00244 $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])));
00245 $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)));
00246 $res[] = $price;
00247 }
00248 }
00249 else {
00250 if ($price['price']<$product->getPrice()) {
00251 $price['savePercent'] = ceil(100 - (( 100/$product->getPrice() ) * $price['price'] ));
00252 $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])));
00253 $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)));
00254 $res[] = $price;
00255 }
00256 }
00257 }
00258 }
00259
00260 return $res;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 protected function _addProductAttributesAndPrices(Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection)
00272 {
00273 return $collection
00274 ->addMinimalPrice()
00275 ->addFinalPrice()
00276 ->addTaxPercents()
00277 ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 public function getImageLabel($product=null, $mediaAttributeCode='image')
00289 {
00290 if (is_null($product)) {
00291 $product = $this->getProduct();
00292 }
00293
00294 $label = $product->getData($mediaAttributeCode.'_label');
00295 if (empty($label)) {
00296 $label = $product->getName();
00297 }
00298
00299 return $label;
00300 }
00301
00302 }