00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Catalog 00023 * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 /** 00029 * Catalog data helper 00030 * 00031 * @category Mage 00032 * @package Mage_Catalog 00033 * @author Magento Core Team <core@magentocommerce.com> 00034 */ 00035 class Mage_Catalog_Helper_Data extends Mage_Core_Helper_Abstract 00036 { 00037 const PRICE_SCOPE_GLOBAL = 0; 00038 const PRICE_SCOPE_WEBSITE = 1; 00039 const XML_PATH_PRICE_SCOPE = 'catalog/price/scope'; 00040 00041 /** 00042 * Breadcrumb Path cache 00043 * 00044 * @var string 00045 */ 00046 protected $_categoryPath; 00047 00048 /** 00049 * Return current category path or get it from current category 00050 * and creating array of categories|product paths for breadcrumbs 00051 * 00052 * @return string 00053 */ 00054 public function getBreadcrumbPath() 00055 { 00056 if (!$this->_categoryPath) { 00057 00058 $path = array(); 00059 if ($category = $this->getCategory()) { 00060 $pathInStore = $category->getPathInStore(); 00061 $pathIds = array_reverse(explode(',', $pathInStore)); 00062 00063 $categories = $category->getParentCategories(); 00064 00065 // add category path breadcrumb 00066 foreach ($pathIds as $categoryId) { 00067 if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) { 00068 $path['category'.$categoryId] = array( 00069 'label' => $categories[$categoryId]->getName(), 00070 'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : '' 00071 ); 00072 } 00073 } 00074 } 00075 00076 if ($this->getProduct()) { 00077 $path['product'] = array('label'=>$this->getProduct()->getName()); 00078 } 00079 00080 $this->_categoryPath = $path; 00081 } 00082 return $this->_categoryPath; 00083 } 00084 00085 /** 00086 * Check is category link 00087 * 00088 * @param int $categoryId 00089 * @return bool 00090 */ 00091 protected function _isCategoryLink($categoryId) 00092 { 00093 if ($this->getProduct()) { 00094 return true; 00095 } 00096 if ($categoryId != $this->getCategory()->getId()) { 00097 return true; 00098 } 00099 return false; 00100 } 00101 00102 /** 00103 * Return current category object 00104 * 00105 * @return Mage_Catalog_Model_Category|null 00106 */ 00107 public function getCategory() 00108 { 00109 return Mage::registry('current_category'); 00110 } 00111 00112 /** 00113 * Retrieve current Product object 00114 * 00115 * @return Mage_Catalog_Model_Product|null 00116 */ 00117 public function getProduct() 00118 { 00119 return Mage::registry('current_product'); 00120 } 00121 00122 /** 00123 * Retrieve Visitor/Customer Last Viewed URL 00124 * 00125 * @return string 00126 */ 00127 public function getLastViewedUrl() 00128 { 00129 if ($productId = Mage::getSingleton('catalog/session')->getLastViewedProductId()) { 00130 $product = Mage::getModel('catalog/product')->load($productId); 00131 /* @var $product Mage_Catalog_Model_Product */ 00132 if (Mage::helper('catalog/product')->canShow($product, 'catalog')) { 00133 return $product->getProductUrl(); 00134 } 00135 } 00136 if ($categoryId = Mage::getSingleton('catalog/session')->getLastViewedCategoryId()) { 00137 $category = Mage::getModel('catalog/category')->load($categoryId); 00138 /* @var $category Mage_Catalog_Model_Category */ 00139 if (!Mage::helper('catalog/category')->canShow($category)) { 00140 return ''; 00141 } 00142 return $category->getCategoryUrl(); 00143 } 00144 return ''; 00145 } 00146 00147 /** 00148 * Split SKU of an item by dashes and spaces 00149 * Words will not be broken, unless thir length is greater than $length 00150 * 00151 * @param string $sku 00152 * @param int $length 00153 * @return array 00154 */ 00155 public function splitSku($sku, $length = 30) 00156 { 00157 return Mage::helper('core/string')->str_split($sku, $length, true, false, '[\-\s]'); 00158 } 00159 00160 /** 00161 * Retrieve attribute hidden fields 00162 * 00163 * @return array 00164 */ 00165 public function getAttributeHiddenFields() 00166 { 00167 if (Mage::registry('attribute_type_hidden_fields')) { 00168 return Mage::registry('attribute_type_hidden_fields'); 00169 } else { 00170 return array(); 00171 } 00172 } 00173 00174 /** 00175 * Retrieve attribute disabled types 00176 * 00177 * @return array 00178 */ 00179 public function getAttributeDisabledTypes() 00180 { 00181 if (Mage::registry('attribute_type_disabled_types')) { 00182 return Mage::registry('attribute_type_disabled_types'); 00183 } else { 00184 return array(); 00185 } 00186 } 00187 00188 /** 00189 * Retrieve Catalog Price Scope 00190 * 00191 * @return int 00192 */ 00193 public function getPriceScope() 00194 { 00195 return Mage::getStoreConfig(self::XML_PATH_PRICE_SCOPE); 00196 } 00197 00198 /** 00199 * Is Global Price 00200 * 00201 * @return bool 00202 */ 00203 public function isPriceGlobal() 00204 { 00205 return $this->getPriceScope() == self::PRICE_SCOPE_GLOBAL; 00206 } 00207 }