diff --git a/README.md b/README.md index 27b594e..aedc0f3 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ This extension improves default features of Magento API. It allows you to: * Associate simple products to configurable or grouped product; +* Retrieve simple products from configurable products; +* Retrieve configurable attributes used in configurable products; * Specify category names rather than the ids; * Specify the name of the attribute set rather than the id; * Specify options labels rather than the ids; @@ -12,7 +14,7 @@ It allows you to: ## Installation -### Magento CE 1.6.x, 1.7.x +### Magento CE 1.6.x, 1.7.x (retrieval of simple products and configurable attributes worked on 1.5.x) Install with [modgit](https://github.com/jreinke/modgit): @@ -28,4 +30,10 @@ or download package manually: ## How to associate simple products to configurable/grouped product -Please refer to [this article](http://www.bubblecode.net/en/2012/04/20/magento-api-associate-simple-products-to-configurable-or-grouped-product/). \ No newline at end of file +Please refer to [this article](http://www.bubblecode.net/en/2012/04/20/magento-api-associate-simple-products-to-configurable-or-grouped-product/). + +## How to retrieve simple products and used configurable attributes from configurable products + +Consume the "catalogProductInfo" method from the SOAP API on neither V1 and V2 versions. + +The simple products list will be on the "associated_skus" attribute and the configurable attributes list will be on the "configurable_attributes" attribute. diff --git a/app/code/community/Bubble/Api/Model/Catalog/Product/Api.php b/app/code/community/Bubble/Api/Model/Catalog/Product/Api.php index 1066dac..0df99d7 100644 --- a/app/code/community/Bubble/Api/Model/Catalog/Product/Api.php +++ b/app/code/community/Bubble/Api/Model/Catalog/Product/Api.php @@ -52,4 +52,26 @@ protected function _prepareDataForSave($product, $productData) Mage::helper('bubble_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges, $configurableAttributes); } } + + // Not tested + public function info($productId, $store = null, $attributes = null, $identifierType = null) + { + $result = parent::info($productId, $store, $attributes, $identifierType); + if ($result['type'] == 'configurable') { + $associated_skus = array(); + $product = Mage::getModel('catalog/product')->load($productId); + $used_products = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product); + foreach ($used_products as $used_product) { + $associated_skus[] = $used_product->getSku(); + } + $result += ['associated_skus' => $associated_skus]; + $configurable_attributes = array(); + $_configurable_attributes = Mage::getModel('catalog/product_type_configurable')->getUsedProductAttributeIds($product); + foreach ($_configurable_attributes as $configurable_attribute) { + $configurable_attributes[] = Mage::getModel('eav/entity_attribute')->load($configurable_attribute)->getAttributeCode(); + } + $result += ['configurable_attributes' => $configurable_attributes]; + } + return $result; + } } \ No newline at end of file diff --git a/app/code/community/Bubble/Api/Model/Catalog/Product/Api/V2.php b/app/code/community/Bubble/Api/Model/Catalog/Product/Api/V2.php index 0e52829..c0c86b4 100644 --- a/app/code/community/Bubble/Api/Model/Catalog/Product/Api/V2.php +++ b/app/code/community/Bubble/Api/Model/Catalog/Product/Api/V2.php @@ -84,4 +84,25 @@ protected function _prepareDataForSave($product, $productData) Mage::helper('bubble_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges, $configurableAttributes); } } + + public function info($productId, $store = null, $attributes = null, $identifierType = null) + { + $result = parent::info($productId, $store, $attributes, $identifierType); + if ($result['type'] == 'configurable') { + $associated_skus = array(); + $product = Mage::getModel('catalog/product')->load($productId); + $used_products = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product); + foreach ($used_products as $used_product) { + $associated_skus[] = $used_product->getSku(); + } + $result += ['associated_skus' => $associated_skus]; + $configurable_attributes = array(); + $_configurable_attributes = Mage::getModel('catalog/product_type_configurable')->getUsedProductAttributeIds($product); + foreach ($_configurable_attributes as $configurable_attribute) { + $configurable_attributes[] = Mage::getModel('eav/entity_attribute')->load($configurable_attribute)->getAttributeCode(); + } + $result += ['configurable_attributes' => $configurable_attributes]; + } + return $result; + } } diff --git a/app/code/community/Bubble/Api/etc/wsdl.xml b/app/code/community/Bubble/Api/etc/wsdl.xml index 3029e01..395ae9e 100644 --- a/app/code/community/Bubble/Api/etc/wsdl.xml +++ b/app/code/community/Bubble/Api/etc/wsdl.xml @@ -12,6 +12,11 @@ + + + + + diff --git a/app/code/community/Bubble/Api/etc/wsi.xml b/app/code/community/Bubble/Api/etc/wsi.xml index d1e2cf5..6dcf7de 100644 --- a/app/code/community/Bubble/Api/etc/wsi.xml +++ b/app/code/community/Bubble/Api/etc/wsi.xml @@ -25,6 +25,11 @@ + + + + +