*/ class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstract { /** * Default MAP renderer type * * @var string */ protected $_mapRenderer = 'msrp_item'; /** * Add meta information from product to head block * * @return Mage_Catalog_Block_Product_View */ protected function _prepareLayout() { $this->getLayout()->createBlock('catalog/breadcrumbs'); $headBlock = $this->getLayout()->getBlock('head'); if ($headBlock) { $product = $this->getProduct(); $title = $product->getMetaTitle(); if ($title) { $headBlock->setTitle($title); } $keyword = $product->getMetaKeyword(); $currentCategory = Mage::registry('current_category'); if ($keyword) { $headBlock->setKeywords($keyword); } elseif($currentCategory) { $headBlock->setKeywords($product->getName()); } $description = $product->getMetaDescription(); if ($description) { $headBlock->setDescription( ($description) ); } else { $headBlock->setDescription(Mage::helper('core/string')->substr($product->getName(), 0, 255)); } if ($this->helper('catalog/product')->canUseCanonicalTag()) { $params = array('_ignore_category'=>true); $headBlock->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params)); } } return parent::_prepareLayout(); } /** * Retrieve current product model * * @return Mage_Catalog_Model_Product */ public function getProduct() { if (!Mage::registry('product') && $this->getProductId()) { $product = Mage::getModel('catalog/product')->load($this->getProductId()); Mage::register('product', $product); } return Mage::registry('product'); } /** * Check if product can be emailed to friend * * @return bool */ public function canEmailToFriend() { $sendToFriendModel = Mage::registry('send_to_friend_model'); return $sendToFriendModel && $sendToFriendModel->canEmailToFriend(); } /** * Retrieve url for direct adding product to cart * * @param Mage_Catalog_Model_Product $product * @param array $additional * @return string */ public function getAddToCartUrl($product, $additional = array()) { if ($this->hasCustomAddToCartUrl()) { return $this->getCustomAddToCartUrl(); } if ($this->getRequest()->getParam('wishlist_next')){ $additional['wishlist_next'] = 1; } $addUrlKey = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED; $addUrlValue = Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true)); $additional[$addUrlKey] = Mage::helper('core')->urlEncode($addUrlValue); return $this->helper('checkout/cart')->getAddUrl($product, $additional); } /** * Get JSON encoded configuration array which can be used for JS dynamic * price calculation depending on product options * * @return string */ public function getJsonConfig() { $config = array(); if (!$this->hasOptions()) { return Mage::helper('core')->jsonEncode($config); } $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false); /* @var $product Mage_Catalog_Model_Product */ $product = $this->getProduct(); $_request->setProductClassId($product->getTaxClassId()); $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request); $_request = Mage::getSingleton('tax/calculation')->getRateRequest(); $_request->setProductClassId($product->getTaxClassId()); $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request); $_regularPrice = $product->getPrice(); $_finalPrice = $product->getFinalPrice(); $_priceInclTax = Mage::helper('tax')->getPrice($product, $_finalPrice, true); $_priceExclTax = Mage::helper('tax')->getPrice($product, $_finalPrice); $_tierPrices = array(); $_tierPricesInclTax = array(); foreach ($product->getTierPrice() as $tierPrice) { $_tierPrices[] = Mage::helper('core')->currency($tierPrice['website_price'], false, false); $_tierPricesInclTax[] = Mage::helper('core')->currency( Mage::helper('tax')->getPrice($product, (int)$tierPrice['website_price'], true), false, false); } $config = array( 'productId' => $product->getId(), 'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(), 'includeTax' => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false', 'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(), 'showBothPrices' => Mage::helper('tax')->displayBothPrices(), 'productPrice' => Mage::helper('core')->currency($_finalPrice, false, false), 'productOldPrice' => Mage::helper('core')->currency($_regularPrice, false, false), 'priceInclTax' => Mage::helper('core')->currency($_priceInclTax, false, false), 'priceExclTax' => Mage::helper('core')->currency($_priceExclTax, false, false), /** * @var skipCalculate * @deprecated after 1.5.1.0 */ 'skipCalculate' => ($_priceExclTax != $_priceInclTax ? 0 : 1), 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'idSuffix' => '_clone', 'oldPlusDisposition' => 0, 'plusDisposition' => 0, 'plusDispositionTax' => 0, 'oldMinusDisposition' => 0, 'minusDisposition' => 0, 'tierPrices' => $_tierPrices, 'tierPricesInclTax' => $_tierPricesInclTax, ); $responseObject = new Varien_Object(); Mage::dispatchEvent('catalog_product_view_config', array('response_object'=>$responseObject)); if (is_array($responseObject->getAdditionalOptions())) { foreach ($responseObject->getAdditionalOptions() as $option=>$value) { $config[$option] = $value; } } return Mage::helper('core')->jsonEncode($config); } /** * Return true if product has options * * @return bool */ public function hasOptions() { if ($this->getProduct()->getTypeInstance(true)->hasOptions($this->getProduct())) { return true; } return false; } /** * Check if product has required options * * @return bool */ public function hasRequiredOptions() { return $this->getProduct()->getTypeInstance(true)->hasRequiredOptions($this->getProduct()); } /** * Define if setting of product options must be shown instantly. * Used in case when options are usually hidden and shown only when user * presses some button or link. In editing mode we better show these options * instantly. * * @return bool */ public function isStartCustomization() { return $this->getProduct()->getConfigureMode() || Mage::app()->getRequest()->getParam('startcustomization'); } /** * Get default qty - either as preconfigured, or as 1. * Also restricts it by minimal qty. * * @param null|Mage_Catalog_Model_Product $product * @return int|float */ public function getProductDefaultQty($product = null) { if (!$product) { $product = $this->getProduct(); } $qty = $this->getMinimalQty($product); $config = $product->getPreconfiguredValues(); $configQty = $config->getQty(); if ($configQty > $qty) { $qty = $configQty; } return $qty; } }