/app/code/local/MageWorx/SeoSuite/Model/Catalog/Product/Template/Category.php

https://bitbucket.org/kdms/sh-magento · PHP · 148 lines · 109 code · 10 blank · 29 comment · 32 complexity · 5e532c92ca15a1d8ec08b13edb413a25 MD5 · raw file

  1. <?php
  2. /**
  3. * MageWorx
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the MageWorx EULA that is bundled with
  8. * this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.mageworx.com/LICENSE-1.0.html
  11. *
  12. * DISCLAIMER
  13. *
  14. * Do not edit or add to this file if you wish to upgrade the extension
  15. * to newer versions in the future. If you wish to customize the extension
  16. * for your needs please refer to http://www.mageworx.com/ for more information
  17. *
  18. * @category MageWorx
  19. * @package MageWorx_SeoSuite
  20. * @copyright Copyright (c) 2012 MageWorx (http://www.mageworx.com/)
  21. * @license http://www.mageworx.com/LICENSE-1.0.html
  22. */
  23. /**
  24. * SEO Suite extension
  25. *
  26. * @category MageWorx
  27. * @package MageWorx_SeoSuite
  28. * @author MageWorx Dev Team
  29. */
  30. class MageWorx_SeoSuite_Model_Catalog_Product_Template_Title extends MageWorx_SeoSuite_Model_Catalog_Product_Template_Abstract
  31. {
  32. protected $_useDefault = array();
  33. protected $_defaultProduct = null;
  34. public function process() {
  35. if (!$this->_product instanceof Mage_Catalog_Model_Product){
  36. return;
  37. }
  38. try {
  39. $string = $this->__compile($this->getTemplate());
  40. } catch (Exception $e){}
  41. return $string;
  42. }
  43. protected function __compile($template) {
  44. $vars = $this->__parse($template);
  45. foreach ($vars as $key => $params) {
  46. foreach ($params['attributes'] as $n => $attribute) {
  47. $value = '';
  48. switch ($attribute) {
  49. case 'category':
  50. $category = $this->_product->getCategory();
  51. if ($category) {
  52. $value = $this->_product->getCategory()->getName();
  53. } else {
  54. $categoryItems = $this->_product->getCategoryCollection()->load()->getIterator();
  55. $category = current($categoryItems);
  56. if ($category) {
  57. $category = Mage::getModel('catalog/category')->load($category->getId());
  58. $value = $category->getName();
  59. }
  60. }
  61. break;
  62. case 'categories':
  63. $separator = (string)Mage::getStoreConfig('catalog/seo/title_separator');
  64. $separator = ' ' . $separator . ' ';
  65. $title = array();
  66. $path = Mage::helper('catalog')->getBreadcrumbPath();
  67. foreach ($path as $name => $breadcrumb) {
  68. $title[] = $breadcrumb['label'];
  69. }
  70. array_pop($title);
  71. $value = join($separator, array_reverse($title));
  72. break;
  73. case 'store_view_name':
  74. $value = Mage::app()->getStore($this->_product->getStoreId())->getName();
  75. break;
  76. case 'store_name':
  77. $value = Mage::app()->getStore($this->_product->getStoreId())->getGroup()->getName();
  78. break;
  79. case 'website_name':
  80. $value = Mage::app()->getStore($this->_product->getStoreId())->getWebsite()->getName();
  81. break;
  82. case 'price':
  83. $taxHelper = Mage::helper('tax');
  84. if ($taxHelper->displayPriceIncludingTax()) $includingTax = true; else $includingTax = null;
  85. if ($this->_product->getTypeId()=='bundle') {
  86. list($_minimalPriceTax, $_maximalPriceTax) = $this->_product->getPriceModel()->getPrices($this->_product);
  87. if ($this->_product->getPriceType() == 1) {
  88. $_weeeTaxAmount = Mage::helper('weee')->getAmount($this->_product);
  89. if ($_weeeTaxAmount && Mage::helper('weee')->typeOfDisplay($this->_product, array(0, 1, 4))) {
  90. $_minimalPriceTax += $_weeeTaxAmount;
  91. }
  92. if ($_weeeTaxAmount && Mage::helper('weee')->typeOfDisplay($this->_product, array(0, 1, 4))) {
  93. $_maximalPriceTax += $_weeeTaxAmount;
  94. }
  95. }
  96. if ($_minimalPriceTax <> $_maximalPriceTax) $value = Mage::helper('seosuite')->__('form %s to %s', Mage::app()->getStore()->convertPrice($_minimalPriceTax, true, false), Mage::app()->getStore()->convertPrice($_maximalPriceTax, true, false)); else $value = Mage::app()->getStore()->convertPrice($_maximalPriceTax, true, false);
  97. } elseif ($this->_product->getTypeId()=='grouped') {
  98. $price = $taxHelper->getPrice($this->_product, $this->_product->getMinimalPrice(), $includingTax);
  99. if ($price>0) $value = Mage::helper('seosuite')->__('form %s', Mage::app()->getStore()->convertPrice($price, true, false)); else $value = '';
  100. } elseif ($this->_product->getPrice()>0) {
  101. $price = $taxHelper->getPrice($this->_product, $this->_product->getPrice(), $includingTax);
  102. if ($price>0) $value = Mage::app()->getStore()->convertPrice($price, true, false); else $value = '';
  103. } else {
  104. $value = '';
  105. }
  106. break;
  107. case 'special_price':
  108. $taxHelper = Mage::helper('tax');
  109. if ($taxHelper->displayPriceIncludingTax()) $includingTax = true; else $includingTax = null;
  110. if ($this->_product->getData('special_price')>0 && Mage::app()->getLocale()->isStoreDateInInterval(Mage::app()->getStore(), $this->_product->getSpecialFromDate(), $this->_product->getSpecialToDate())) {
  111. $price = Mage::helper('tax')->getPrice($this->_product, $this->_product->getData('special_price'), $includingTax);
  112. if ($price>0) $value = Mage::app()->getStore()->convertPrice($price, true, false); else $value = '';
  113. //$value = Mage::app()->getStore()->formatPrice($this->_product->getData('special_price'), false);
  114. } else {
  115. $value = '';
  116. }
  117. break;
  118. default:
  119. if ($_attr = $this->_product->getResource()->getAttribute($attribute)) {
  120. $value = $_attr->getSource()->getOptionText($this->_product->getData($attribute));
  121. }
  122. if (!$value) {
  123. $value = $this->_product->getData($attribute);
  124. }
  125. if (is_array($value)) {
  126. $value = implode(', ', $value);
  127. }
  128. }
  129. if ($value) {
  130. $value = $params['prefix'] . $value . $params['suffix'];
  131. break;
  132. }
  133. }
  134. $template = str_replace($key, $value, $template);
  135. }
  136. return $template;
  137. }
  138. }