From c034fecef27c6c2138eabf08347499a39ee684f0 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Tue, 6 Aug 2019 15:46:59 +0200 Subject: [PATCH] fixed import of unicode attribute options --- .../Model/Import/Entity/Category.php | 39 +++++++++++++++++++ .../Model/Import/Entity/Customer.php | 39 +++++++++++++++++++ .../Model/Import/Entity/Product.php | 39 +++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Category.php b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Category.php index 489a9917..1f0164e1 100644 --- a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Category.php +++ b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Category.php @@ -1480,4 +1480,43 @@ public function getOldCategory() { return $this->getCategoriesWithRoots(); } + + /** + * Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased. + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param array $indexValAttrs OPTIONAL Additional attributes' codes with index values. + * @return array + */ + public function getAttributeOptions(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $indexValAttrs = array()) + { + $options = array(); + + if ($attribute->usesSource()) { + // merge global entity index value attributes + $indexValAttrs = array_merge($indexValAttrs, $this->_indexValueAttributes); + + // should attribute has index (option value) instead of a label? + $index = in_array($attribute->getAttributeCode(), $indexValAttrs) ? 'value' : 'label'; + + // only default (admin) store values used + $attribute->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + try { + /** @var AvS_FastSimpleImport_Helper_Data $helper */ + $helper = Mage::helper('fastsimpleimport'); + foreach ($attribute->getSource()->getAllOptions(false) as $option) { + $value = is_array($option['value']) ? $option['value'] : array($option); + foreach ($value as $innerOption) { + if (strlen($innerOption['value'])) { // skip ' -- Please Select -- ' option + $options[$helper->strtolower($innerOption[$index])] = $innerOption['value']; + } + } + } + } catch (Exception $e) { + // ignore exceptions connected with source models + } + } + return $options; + } } diff --git a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Customer.php b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Customer.php index ba364d47..b1b95a61 100644 --- a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Customer.php +++ b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Customer.php @@ -703,4 +703,43 @@ public function getOldCustomers() { return $this->_oldCustomers; } + + /** + * Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased. + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param array $indexValAttrs OPTIONAL Additional attributes' codes with index values. + * @return array + */ + public function getAttributeOptions(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $indexValAttrs = array()) + { + $options = array(); + + if ($attribute->usesSource()) { + // merge global entity index value attributes + $indexValAttrs = array_merge($indexValAttrs, $this->_indexValueAttributes); + + // should attribute has index (option value) instead of a label? + $index = in_array($attribute->getAttributeCode(), $indexValAttrs) ? 'value' : 'label'; + + // only default (admin) store values used + $attribute->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + try { + /** @var AvS_FastSimpleImport_Helper_Data $helper */ + $helper = Mage::helper('fastsimpleimport'); + foreach ($attribute->getSource()->getAllOptions(false) as $option) { + $value = is_array($option['value']) ? $option['value'] : array($option); + foreach ($value as $innerOption) { + if (strlen($innerOption['value'])) { // skip ' -- Please Select -- ' option + $options[$helper->strtolower($innerOption[$index])] = $innerOption['value']; + } + } + } + } catch (Exception $e) { + // ignore exceptions connected with source models + } + } + return $options; + } } diff --git a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product.php b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product.php index 20fec9d9..9b49d5d7 100644 --- a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product.php +++ b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product.php @@ -2210,4 +2210,43 @@ public function getEntityBySku($sku) } return false; } + + /** + * Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased. + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param array $indexValAttrs OPTIONAL Additional attributes' codes with index values. + * @return array + */ + public function getAttributeOptions(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $indexValAttrs = array()) + { + $options = array(); + + if ($attribute->usesSource()) { + // merge global entity index value attributes + $indexValAttrs = array_merge($indexValAttrs, $this->_indexValueAttributes); + + // should attribute has index (option value) instead of a label? + $index = in_array($attribute->getAttributeCode(), $indexValAttrs) ? 'value' : 'label'; + + // only default (admin) store values used + $attribute->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + try { + /** @var AvS_FastSimpleImport_Helper_Data $helper */ + $helper = Mage::helper('fastsimpleimport'); + foreach ($attribute->getSource()->getAllOptions(false) as $option) { + $value = is_array($option['value']) ? $option['value'] : array($option); + foreach ($value as $innerOption) { + if (strlen($innerOption['value'])) { // skip ' -- Please Select -- ' option + $options[$helper->strtolower($innerOption[$index])] = $innerOption['value']; + } + } + } + } catch (Exception $e) { + // ignore exceptions connected with source models + } + } + return $options; + } }