From fa6adf8bf28e16af87b50d54343e6ddd8117c3cd Mon Sep 17 00:00:00 2001 From: Wyllyan Date: Thu, 15 May 2014 15:21:58 -0300 Subject: [PATCH 1/4] Fixed an issue with configurable attributes verification --- app/code/community/Bubble/Api/Helper/Catalog/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Bubble/Api/Helper/Catalog/Product.php b/app/code/community/Bubble/Api/Helper/Catalog/Product.php index 4f76934..97722fa 100644 --- a/app/code/community/Bubble/Api/Helper/Catalog/Product.php +++ b/app/code/community/Bubble/Api/Helper/Catalog/Product.php @@ -134,7 +134,7 @@ protected function _initConfigurableAttributesData(Mage_Catalog_Model_Product $m } if (!empty($configurableAttributes)){ foreach ($attributesData as $idx => $val) { - if (!in_array($val['attribute_id'], $configurableAttributes)) { + if (!in_array($val['attribute_code'], $configurableAttributes)) { unset($attributesData[$idx]); } } From 9e007f1f02c0d86f686ef7292cdb6f9ddb5e2989 Mon Sep 17 00:00:00 2001 From: Wyllyan Date: Fri, 16 May 2014 18:09:59 -0300 Subject: [PATCH 2/4] Improved verification for new categories with a new method to create it automatically --- .../Bubble/Api/Helper/Catalog/Product.php | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/code/community/Bubble/Api/Helper/Catalog/Product.php b/app/code/community/Bubble/Api/Helper/Catalog/Product.php index 97722fa..58d754a 100644 --- a/app/code/community/Bubble/Api/Helper/Catalog/Product.php +++ b/app/code/community/Bubble/Api/Helper/Catalog/Product.php @@ -59,7 +59,6 @@ public function getCategoryIdsByNames($categoryNames) if (!empty($parentIds)) { $collection->getSelect()->where('parent_id IN (?)', $parentIds); } - $parentIds = array(); if ($collection->count()) { foreach ($collection as $category) { $addCategories[] = (int) $category->getId(); @@ -68,6 +67,15 @@ public function getCategoryIdsByNames($categoryNames) } $parentIds[] = $category->getId(); } + } else { + if ($level > 0) { + $parentId = end($parentIds); + } else { + $parentId = Mage::app()->getWebsite(1)->getDefaultStore()->getRootCategoryId(); + } + $newCategoryId = $this->createCategory($name, $parentId); + $addCategories[] = $newCategoryId; + $parentIds[] = $newCategoryId; } } if (!empty($addCategories)) { @@ -79,6 +87,24 @@ public function getCategoryIdsByNames($categoryNames) return !empty($categories) ? $categories : $categoryNames; } + /** + * @param string $name + * @param int|string $parentId + * @return string + */ + public function createCategory($name, $parentId) + { + $category = Mage::getModel('catalog/category'); + $parentCategory = Mage::getModel('catalog/category')->load($parentId); + + $category->setName($name) + ->setIsActive(1) + ->setPath($parentCategory->getPath()); + $category->save(); + + return $category->getId(); + } + /** * @param string $attributeCode * @param string $label From 42882de5b92ee952c398f970352a52893d8afe37 Mon Sep 17 00:00:00 2001 From: Wyllyan Date: Sun, 18 May 2014 22:01:55 -0300 Subject: [PATCH 3/4] Improved verification for new attribute option with a new method to create it automatically --- .../Bubble/Api/Helper/Catalog/Product.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/code/community/Bubble/Api/Helper/Catalog/Product.php b/app/code/community/Bubble/Api/Helper/Catalog/Product.php index 58d754a..9ca7a6e 100644 --- a/app/code/community/Bubble/Api/Helper/Catalog/Product.php +++ b/app/code/community/Bubble/Api/Helper/Catalog/Product.php @@ -122,9 +122,35 @@ public function getOptionKeyByLabel($attributeCode, $label) } } + if ($newOptionId = $this->createOption($attribute, $label)) { + return $newOptionId; + } + return $label; } + /** + * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @param string $label + * @return string|null + */ + public function createOption(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $label) + { + $option = array( + 'value' => array( + 'option' => array($label) + ) + ); + $attribute->setOption($option); + $attribute->save(); + + $optionId = Mage::getModel('eav/entity_attribute_source_table') + ->setAttribute($attribute) + ->getOptionId($label); + + return $optionId; + } + protected function _getCatagoriesSeparator() { return Mage::getStoreConfig(self::CATEGORIES_SEPARATOR_PATH_XML); From 7960cc8c48198fe4a1e511fff6b9b206bea73b82 Mon Sep 17 00:00:00 2001 From: Wyllyan Date: Thu, 29 May 2014 17:32:09 -0300 Subject: [PATCH 4/4] Merge new and old simple products ids for configurable or grouped products --- app/code/community/Bubble/Api/Helper/Catalog/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Bubble/Api/Helper/Catalog/Product.php b/app/code/community/Bubble/Api/Helper/Catalog/Product.php index 9ca7a6e..d72ab2c 100644 --- a/app/code/community/Bubble/Api/Helper/Catalog/Product.php +++ b/app/code/community/Bubble/Api/Helper/Catalog/Product.php @@ -23,7 +23,7 @@ public function associateProducts(Mage_Catalog_Model_Product $product, $simpleSk ->addFilterByRequiredOptions() ->getAllIds(); - $usedProductIds = array_diff($newProductIds, $oldProductIds); + $usedProductIds = array_unique(array_merge($newProductIds, $oldProductIds)); if (!empty($usedProductIds)) { if ($product->isConfigurable()) {