Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the associated sku of a configurable product #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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;
* Specify the website code rather than the id.

## 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):

Expand All @@ -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/).
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.
22 changes: 22 additions & 0 deletions app/code/community/Bubble/Api/Model/Catalog/Product/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
21 changes: 21 additions & 0 deletions app/code/community/Bubble/Api/Model/Catalog/Product/Api/V2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions app/code/community/Bubble/Api/etc/wsdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<element name="configurable_attributes" type="typens:ArrayOfString" minOccurs="0"/>
<element name="price_changes" type="typens:associativeArray" minOccurs="0" />
</all>
</complexType>
<complexType name="catalogProductReturnEntity">
<all>
<element name="associated_skus" type="typens:ArrayOfString" minOccurs="0"/>
</all>
</complexType>
</schema>
</types>
Expand Down
5 changes: 5 additions & 0 deletions app/code/community/Bubble/Api/etc/wsi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<xsd:element name="configurable_attributes" type="typens:ArrayOfString" minOccurs="0" />
<xsd:element name="price_changes" type="typens:complexMultiArray" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="catalogProductReturnEntity">
<xsd:sequence>
<xsd:element name="associated_skus" type="typens:ArrayOfString" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
Expand Down