1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Eav
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: abstract class Mage_Eav_Model_Convert_Parser_Abstract
29: extends Mage_Dataflow_Model_Convert_Parser_Abstract
30: {
31: protected $_storesById;
32: protected $_attributeSetsById;
33: protected $_attributeSetsByName;
34:
35: public function getStoreIds($stores)
36: {
37: if (empty($stores)) {
38: $storeIds = array(0);
39: } else {
40: $storeIds = array();
41: foreach (explode(',', $stores) as $store) {
42: if (is_numeric($store)) {
43: $storeIds[] = $store;
44: } else {
45: $storeNode = Mage::getConfig()->getNode('stores/'.$store);
46: if (!$storeNode) {
47: return false;
48: }
49: $storeIds[] = (int)$storeNode->system->store->id;
50: }
51: }
52: }
53: return $storeIds;
54: }
55:
56: public function getStoreCode($storeId)
57: {
58: return Mage::app()->getStore($storeId?$storeId:0)->getCode();
59: }
60:
61: public function loadAttributeSets($entityTypeId)
62: {
63: $attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
64: ->setEntityTypeFilter($entityTypeId)
65: ->load();
66: $this->_attributeSetsById = array();
67: $this->_attributeSetsByName = array();
68: foreach ($attributeSetCollection as $id=>$attributeSet) {
69: $name = $attributeSet->getAttributeSetName();
70: $this->_attributeSetsById[$id] = $name;
71: $this->_attributeSetsByName[$name] = $id;
72: }
73: return $this;
74: }
75:
76: public function getAttributeSetName($entityTypeId, $id)
77: {
78: if (!$this->_attributeSetsById) {
79: $this->loadAttributeSets($entityTypeId);
80: }
81: return isset($this->_attributeSetsById[$id]) ? $this->_attributeSetsById[$id] : false;
82: }
83:
84: public function getAttributeSetId($entityTypeId, $name)
85: {
86: if (!$this->_attributeSetsByName) {
87: $this->loadAttributeSets($entityTypeId);
88: }
89: return isset($this->_attributeSetsByName[$name]) ? $this->_attributeSetsByName[$name] : false;
90: }
91:
92: public function getSourceOptionId(Mage_Eav_Model_Entity_Attribute_Source_Interface $source, $value)
93: {
94: foreach ($source->getAllOptions() as $option) {
95: if (strcasecmp($option['label'], $value)==0) {
96: return $option['value'];
97: }
98: }
99: return null;
100: }
101: }
102: