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) 2008 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 abstract class Mage_Eav_Model_Convert_Parser_Abstract 00029 extends Mage_Dataflow_Model_Convert_Parser_Abstract 00030 { 00031 protected $_storesById; 00032 protected $_attributeSetsById; 00033 protected $_attributeSetsByName; 00034 00035 public function getStoreIds($stores) 00036 { 00037 if (empty($stores)) { 00038 $storeIds = array(0); 00039 } else { 00040 $storeIds = array(); 00041 foreach (explode(',', $stores) as $store) { 00042 if (is_numeric($store)) { 00043 $storeIds[] = $store; 00044 } else { 00045 $storeNode = Mage::getConfig()->getNode('stores/'.$store); 00046 if (!$storeNode) { 00047 return false; 00048 } 00049 $storeIds[] = (int)$storeNode->system->store->id; 00050 } 00051 } 00052 } 00053 return $storeIds; 00054 } 00055 00056 public function getStoreCode($storeId) 00057 { 00058 return Mage::app()->getStore($storeId?$storeId:0)->getCode(); 00059 } 00060 00061 public function loadAttributeSets($entityTypeId) 00062 { 00063 $attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection') 00064 ->setEntityTypeFilter($entityTypeId) 00065 ->load(); 00066 $this->_attributeSetsById = array(); 00067 $this->_attributeSetsByName = array(); 00068 foreach ($attributeSetCollection as $id=>$attributeSet) { 00069 $name = $attributeSet->getAttributeSetName(); 00070 $this->_attributeSetsById[$id] = $name; 00071 $this->_attributeSetsByName[$name] = $id; 00072 } 00073 return $this; 00074 } 00075 00076 public function getAttributeSetName($entityTypeId, $id) 00077 { 00078 if (!$this->_attributeSetsById) { 00079 $this->loadAttributeSets($entityTypeId); 00080 } 00081 return isset($this->_attributeSetsById[$id]) ? $this->_attributeSetsById[$id] : false; 00082 } 00083 00084 public function getAttributeSetId($entityTypeId, $name) 00085 { 00086 if (!$this->_attributeSetsByName) { 00087 $this->loadAttributeSets($entityTypeId); 00088 } 00089 return isset($this->_attributeSetsByName[$name]) ? $this->_attributeSetsByName[$name] : false; 00090 } 00091 00092 public function getSourceOptionId(Mage_Eav_Model_Entity_Attribute_Source_Interface $source, $value) 00093 { 00094 foreach ($source->getAllOptions() as $option) { 00095 if (strcasecmp($option['label'], $value)==0) { 00096 return $option['value']; 00097 } 00098 } 00099 return null; 00100 } 00101 }