1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34: 35:
36: class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstract
37: {
38: 39: 40: 41: 42:
43: protected $_mapRenderer = 'msrp_item';
44:
45: 46: 47: 48: 49:
50: protected function _prepareLayout()
51: {
52: $this->getLayout()->createBlock('catalog/breadcrumbs');
53: $headBlock = $this->getLayout()->getBlock('head');
54: if ($headBlock) {
55: $product = $this->getProduct();
56: $title = $product->getMetaTitle();
57: if ($title) {
58: $headBlock->setTitle($title);
59: }
60: $keyword = $product->getMetaKeyword();
61: $currentCategory = Mage::registry('current_category');
62: if ($keyword) {
63: $headBlock->setKeywords($keyword);
64: } elseif($currentCategory) {
65: $headBlock->setKeywords($product->getName());
66: }
67: $description = $product->getMetaDescription();
68: if ($description) {
69: $headBlock->setDescription( ($description) );
70: } else {
71: $headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255));
72: }
73: if ($this->helper('catalog/product')->canUseCanonicalTag()) {
74: $params = array('_ignore_category'=>true);
75: $headBlock->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params));
76: }
77: }
78:
79: return parent::_prepareLayout();
80: }
81:
82: 83: 84: 85: 86:
87: public function getProduct()
88: {
89: if (!Mage::registry('product') && $this->getProductId()) {
90: $product = Mage::getModel('catalog/product')->load($this->getProductId());
91: Mage::register('product', $product);
92: }
93: return Mage::registry('product');
94: }
95:
96: 97: 98: 99: 100:
101: public function canEmailToFriend()
102: {
103: $sendToFriendModel = Mage::registry('send_to_friend_model');
104: return $sendToFriendModel && $sendToFriendModel->canEmailToFriend();
105: }
106:
107: 108: 109: 110: 111: 112: 113:
114: public function getAddToCartUrl($product, $additional = array())
115: {
116: if ($this->hasCustomAddToCartUrl()) {
117: return $this->getCustomAddToCartUrl();
118: }
119:
120: if ($this->getRequest()->getParam('wishlist_next')){
121: $additional['wishlist_next'] = 1;
122: }
123:
124: $addUrlKey = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
125: $addUrlValue = Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true));
126: $additional[$addUrlKey] = Mage::helper('core')->urlEncode($addUrlValue);
127:
128: return $this->helper('checkout/cart')->getAddUrl($product, $additional);
129: }
130:
131: 132: 133: 134: 135: 136:
137: public function getJsonConfig()
138: {
139: $config = array();
140: if (!$this->hasOptions()) {
141: return Mage::helper('core')->jsonEncode($config);
142: }
143:
144: $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
145:
146: $product = $this->getProduct();
147: $_request->setProductClassId($product->getTaxClassId());
148: $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request);
149:
150: $_request = Mage::getSingleton('tax/calculation')->getRateRequest();
151: $_request->setProductClassId($product->getTaxClassId());
152: $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request);
153:
154: $_regularPrice = $product->getPrice();
155: $_finalPrice = $product->getFinalPrice();
156: $_priceInclTax = Mage::helper('tax')->getPrice($product, $_finalPrice, true);
157: $_priceExclTax = Mage::helper('tax')->getPrice($product, $_finalPrice);
158: $_tierPrices = array();
159: $_tierPricesInclTax = array();
160: foreach ($product->getTierPrice() as $tierPrice) {
161: $_tierPrices[] = Mage::helper('core')->currency($tierPrice['website_price'], false, false);
162: $_tierPricesInclTax[] = Mage::helper('core')->currency(
163: Mage::helper('tax')->getPrice($product, (int)$tierPrice['website_price'], true),
164: false, false);
165: }
166: $config = array(
167: 'productId' => $product->getId(),
168: 'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(),
169: 'includeTax' => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
170: 'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(),
171: 'showBothPrices' => Mage::helper('tax')->displayBothPrices(),
172: 'productPrice' => Mage::helper('core')->currency($_finalPrice, false, false),
173: 'productOldPrice' => Mage::helper('core')->currency($_regularPrice, false, false),
174: 'priceInclTax' => Mage::helper('core')->currency($_priceInclTax, false, false),
175: 'priceExclTax' => Mage::helper('core')->currency($_priceExclTax, false, false),
176: 177: 178: 179:
180: 'skipCalculate' => ($_priceExclTax != $_priceInclTax ? 0 : 1),
181: 'defaultTax' => $defaultTax,
182: 'currentTax' => $currentTax,
183: 'idSuffix' => '_clone',
184: 'oldPlusDisposition' => 0,
185: 'plusDisposition' => 0,
186: 'plusDispositionTax' => 0,
187: 'oldMinusDisposition' => 0,
188: 'minusDisposition' => 0,
189: 'tierPrices' => $_tierPrices,
190: 'tierPricesInclTax' => $_tierPricesInclTax,
191: );
192:
193: $responseObject = new Varien_Object();
194: Mage::dispatchEvent('catalog_product_view_config', array('response_object'=>$responseObject));
195: if (is_array($responseObject->getAdditionalOptions())) {
196: foreach ($responseObject->getAdditionalOptions() as $option=>$value) {
197: $config[$option] = $value;
198: }
199: }
200:
201: return Mage::helper('core')->jsonEncode($config);
202: }
203:
204: 205: 206: 207: 208:
209: public function hasOptions()
210: {
211: if ($this->getProduct()->getTypeInstance(true)->hasOptions($this->getProduct())) {
212: return true;
213: }
214: return false;
215: }
216:
217: 218: 219: 220: 221:
222: public function hasRequiredOptions()
223: {
224: return $this->getProduct()->getTypeInstance(true)->hasRequiredOptions($this->getProduct());
225: }
226:
227: 228: 229: 230: 231: 232: 233: 234:
235: public function isStartCustomization()
236: {
237: return $this->getProduct()->getConfigureMode() || Mage::app()->getRequest()->getParam('startcustomization');
238: }
239:
240: 241: 242: 243: 244: 245: 246:
247: public function getProductDefaultQty($product = null)
248: {
249: if (!$product) {
250: $product = $this->getProduct();
251: }
252:
253: $qty = $this->getMinimalQty($product);
254: $config = $product->getPreconfiguredValues();
255: $configQty = $config->getQty();
256: if ($configQty > $qty) {
257: $qty = $configQty;
258: }
259:
260: return $qty;
261: }
262: }
263: