PageRenderTime 33ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Catalog/Block/Product/View.php

https://bitbucket.org/dnejedly/eaparts
PHP | 262 lines | 145 code | 22 blank | 95 comment | 18 complexity | 3a142c79b93a45847f7ac1856292cc4a MD5 | raw file
  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. * Product View block
  28. *
  29. * @category Mage
  30. * @package Mage_Catalog
  31. * @module Catalog
  32. * @author Magento Core Team <core@magentocommerce.com>
  33. */
  34. class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstract
  35. {
  36. /**
  37. * Default MAP renderer type
  38. *
  39. * @var string
  40. */
  41. protected $_mapRenderer = 'msrp_item';
  42. /**
  43. * Add meta information from product to head block
  44. *
  45. * @return Mage_Catalog_Block_Product_View
  46. */
  47. protected function _prepareLayout()
  48. {
  49. $this->getLayout()->createBlock('catalog/breadcrumbs');
  50. $headBlock = $this->getLayout()->getBlock('head');
  51. if ($headBlock) {
  52. $product = $this->getProduct();
  53. $title = $product->getMetaTitle();
  54. if ($title) {
  55. $headBlock->setTitle($title);
  56. }
  57. $keyword = $product->getMetaKeyword();
  58. $currentCategory = Mage::registry('current_category');
  59. if ($keyword) {
  60. $headBlock->setKeywords($keyword);
  61. } elseif($currentCategory) {
  62. $headBlock->setKeywords($product->getName());
  63. }
  64. $description = $product->getMetaDescription();
  65. if ($description) {
  66. $headBlock->setDescription( ($description) );
  67. } else {
  68. $headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255));
  69. }
  70. if ($this->helper('catalog/product')->canUseCanonicalTag()) {
  71. $params = array('_ignore_category'=>true);
  72. $headBlock->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params));
  73. }
  74. }
  75. return parent::_prepareLayout();
  76. }
  77. /**
  78. * Retrieve current product model
  79. *
  80. * @return Mage_Catalog_Model_Product
  81. */
  82. public function getProduct()
  83. {
  84. if (!Mage::registry('product') && $this->getProductId()) {
  85. $product = Mage::getModel('catalog/product')->load($this->getProductId());
  86. Mage::register('product', $product);
  87. }
  88. return Mage::registry('product');
  89. }
  90. /**
  91. * Check if product can be emailed to friend
  92. *
  93. * @return bool
  94. */
  95. public function canEmailToFriend()
  96. {
  97. $sendToFriendModel = Mage::registry('send_to_friend_model');
  98. return $sendToFriendModel && $sendToFriendModel->canEmailToFriend();
  99. }
  100. /**
  101. * Retrieve url for direct adding product to cart
  102. *
  103. * @param Mage_Catalog_Model_Product $product
  104. * @param array $additional
  105. * @return string
  106. */
  107. public function getAddToCartUrl($product, $additional = array())
  108. {
  109. if ($this->hasCustomAddToCartUrl()) {
  110. return $this->getCustomAddToCartUrl();
  111. }
  112. if ($this->getRequest()->getParam('wishlist_next')){
  113. $additional['wishlist_next'] = 1;
  114. }
  115. $addUrlKey = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
  116. $addUrlValue = Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true));
  117. $additional[$addUrlKey] = Mage::helper('core')->urlEncode($addUrlValue);
  118. return $this->helper('checkout/cart')->getAddUrl($product, $additional);
  119. }
  120. /**
  121. * Get JSON encoded configuration array which can be used for JS dynamic
  122. * price calculation depending on product options
  123. *
  124. * @return string
  125. */
  126. public function getJsonConfig()
  127. {
  128. $config = array();
  129. if (!$this->hasOptions()) {
  130. return Mage::helper('core')->jsonEncode($config);
  131. }
  132. $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
  133. /* @var $product Mage_Catalog_Model_Product */
  134. $product = $this->getProduct();
  135. $_request->setProductClassId($product->getTaxClassId());
  136. $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request);
  137. $_request = Mage::getSingleton('tax/calculation')->getRateRequest();
  138. $_request->setProductClassId($product->getTaxClassId());
  139. $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request);
  140. $_regularPrice = $product->getPrice();
  141. $_finalPrice = $product->getFinalPrice();
  142. $_priceInclTax = Mage::helper('tax')->getPrice($product, $_finalPrice, true);
  143. $_priceExclTax = Mage::helper('tax')->getPrice($product, $_finalPrice);
  144. $_tierPrices = array();
  145. $_tierPricesInclTax = array();
  146. foreach ($product->getTierPrice() as $tierPrice) {
  147. $_tierPrices[] = Mage::helper('core')->currency($tierPrice['website_price'], false, false);
  148. $_tierPricesInclTax[] = Mage::helper('core')->currency(
  149. Mage::helper('tax')->getPrice($product, (int)$tierPrice['website_price'], true),
  150. false, false);
  151. }
  152. $config = array(
  153. 'productId' => $product->getId(),
  154. 'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(),
  155. 'includeTax' => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
  156. 'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(),
  157. 'showBothPrices' => Mage::helper('tax')->displayBothPrices(),
  158. 'productPrice' => Mage::helper('core')->currency($_finalPrice, false, false),
  159. 'productOldPrice' => Mage::helper('core')->currency($_regularPrice, false, false),
  160. 'priceInclTax' => Mage::helper('core')->currency($_priceInclTax, false, false),
  161. 'priceExclTax' => Mage::helper('core')->currency($_priceExclTax, false, false),
  162. /**
  163. * @var skipCalculate
  164. * @deprecated after 1.5.1.0
  165. */
  166. 'skipCalculate' => ($_priceExclTax != $_priceInclTax ? 0 : 1),
  167. 'defaultTax' => $defaultTax,
  168. 'currentTax' => $currentTax,
  169. 'idSuffix' => '_clone',
  170. 'oldPlusDisposition' => 0,
  171. 'plusDisposition' => 0,
  172. 'plusDispositionTax' => 0,
  173. 'oldMinusDisposition' => 0,
  174. 'minusDisposition' => 0,
  175. 'tierPrices' => $_tierPrices,
  176. 'tierPricesInclTax' => $_tierPricesInclTax,
  177. );
  178. $responseObject = new Varien_Object();
  179. Mage::dispatchEvent('catalog_product_view_config', array('response_object'=>$responseObject));
  180. if (is_array($responseObject->getAdditionalOptions())) {
  181. foreach ($responseObject->getAdditionalOptions() as $option=>$value) {
  182. $config[$option] = $value;
  183. }
  184. }
  185. return Mage::helper('core')->jsonEncode($config);
  186. }
  187. /**
  188. * Return true if product has options
  189. *
  190. * @return bool
  191. */
  192. public function hasOptions()
  193. {
  194. if ($this->getProduct()->getTypeInstance(true)->hasOptions($this->getProduct())) {
  195. return true;
  196. }
  197. return false;
  198. }
  199. /**
  200. * Check if product has required options
  201. *
  202. * @return bool
  203. */
  204. public function hasRequiredOptions()
  205. {
  206. return $this->getProduct()->getTypeInstance(true)->hasRequiredOptions($this->getProduct());
  207. }
  208. /**
  209. * Define if setting of product options must be shown instantly.
  210. * Used in case when options are usually hidden and shown only when user
  211. * presses some button or link. In editing mode we better show these options
  212. * instantly.
  213. *
  214. * @return bool
  215. */
  216. public function isStartCustomization()
  217. {
  218. return $this->getProduct()->getConfigureMode() || Mage::app()->getRequest()->getParam('startcustomization');
  219. }
  220. /**
  221. * Get default qty - either as preconfigured, or as 1.
  222. * Also restricts it by minimal qty.
  223. *
  224. * @param null|Mage_Catalog_Model_Product $product
  225. * @return int|float
  226. */
  227. public function getProductDefaultQty($product = null)
  228. {
  229. if (!$product) {
  230. $product = $this->getProduct();
  231. }
  232. $qty = $this->getMinimalQty($product);
  233. $config = $product->getPreconfiguredValues();
  234. $configQty = $config->getQty();
  235. if ($configQty > $qty) {
  236. $qty = $configQty;
  237. }
  238. return $qty;
  239. }
  240. }