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_View extends Mage_Catalog_Block_Product_Abstract
00036 {
00037 protected function _prepareLayout()
00038 {
00039 $this->getLayout()->createBlock('catalog/breadcrumbs');
00040 if ($headBlock = $this->getLayout()->getBlock('head')) {
00041 if ($title = $this->getProduct()->getMetaTitle()) {
00042 $headBlock->setTitle($title);
00043 }
00044
00045 if ($keyword = $this->getProduct()->getMetaKeyword()) {
00046 $headBlock->setKeywords($keyword);
00047 } elseif( $currentCategory = Mage::registry('current_category') ) {
00048 $headBlock->setKeywords($this->getProduct()->getName());
00049 }
00050
00051 if ($description = $this->getProduct()->getMetaDescription()) {
00052 $headBlock->setDescription( ($description) );
00053 } else {
00054 $headBlock->setDescription( $this->getProduct()->getDescription() );
00055 }
00056 }
00057
00058 return parent::_prepareLayout();
00059 }
00060
00061
00062
00063
00064
00065
00066 public function getProduct()
00067 {
00068 if (!Mage::registry('product') && $this->getProductId()) {
00069 $product = Mage::getModel('catalog/product')->load($this->getProductId());
00070 Mage::register('product', $product);
00071 }
00072 return Mage::registry('product');
00073 }
00074
00075 public function canEmailToFriend()
00076 {
00077 $sendToFriendModel = Mage::registry('send_to_friend_model');
00078 return $sendToFriendModel && $sendToFriendModel->canEmailToFriend();
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088 public function getAddToCartUrl($product, $additional = array())
00089 {
00090 $additional = array();
00091
00092 if ($this->getRequest()->getParam('wishlist_next')){
00093 $additional['wishlist_next'] = 1;
00094 }
00095
00096 return $this->helper('checkout/cart')->getAddUrl($product, $additional);
00097 }
00098
00099 public function getJsonConfig()
00100 {
00101 $config = array();
00102
00103 $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
00104 $_request->setProductClassId($this->getProduct()->getTaxClassId());
00105 $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request);
00106
00107 $_request = Mage::getSingleton('tax/calculation')->getRateRequest();
00108 $_request->setProductClassId($this->getProduct()->getTaxClassId());
00109 $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request);
00110
00111 $_regularPrice = $this->getProduct()->getPrice();
00112 $_finalPrice = $this->getProduct()->getFinalPrice();
00113 $_priceInclTax = Mage::helper('tax')->getPrice($this->getProduct(), $_finalPrice, true);
00114 $_priceExclTax = Mage::helper('tax')->getPrice($this->getProduct(), $_finalPrice);
00115
00116 $idSuffix = '__none__';
00117 if ($this->hasOptions()) {
00118 $idSuffix = '_clone';
00119 }
00120
00121 $config = array(
00122 'productId' => $this->getProduct()->getId(),
00123 'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(),
00124 'includeTax' => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
00125 'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(),
00126 'showBothPrices' => Mage::helper('tax')->displayBothPrices(),
00127 'productPrice' => Mage::helper('core')->currency($_finalPrice, false, false),
00128 'productOldPrice' => Mage::helper('core')->currency($_regularPrice, false, false),
00129 'skipCalculate' => ($_priceExclTax != $_priceInclTax ? 0 : 1),
00130 'defaultTax' => $defaultTax,
00131 'currentTax' => $currentTax,
00132 'idSuffix' => $idSuffix,
00133 'oldPlusDisposition' => 0,
00134 'plusDisposition' => 0,
00135 'oldMinusDisposition' => 0,
00136 'minusDisposition' => 0,
00137 );
00138
00139 $responseObject = new Varien_Object();
00140 Mage::dispatchEvent('catalog_product_view_config', array('response_object'=>$responseObject));
00141 if (is_array($responseObject->getAdditionalOptions())) {
00142 foreach ($responseObject->getAdditionalOptions() as $option=>$value) {
00143 $config[$option] = $value;
00144 }
00145 }
00146
00147 return Zend_Json::encode($config);
00148 }
00149
00150
00151
00152
00153
00154
00155 public function hasOptions()
00156 {
00157 if ($this->getProduct()->getTypeInstance(true)->hasOptions($this->getProduct())) {
00158 return true;
00159 }
00160 return false;
00161 }
00162
00163
00164
00165
00166
00167
00168 public function hasRequiredOptions()
00169 {
00170 return $this->getProduct()->getTypeInstance(true)->hasRequiredOptions($this->getProduct());
00171 }
00172 }