Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request jreinke#3 from goodscloud/master
Browse files Browse the repository at this point in the history
allow specifying the set of attributes that should be used to configure the configurable product
  • Loading branch information
jreinke committed Jun 3, 2013
2 parents d38e5ba + 947719b commit 457dacf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
25 changes: 20 additions & 5 deletions app/code/community/Bubble/Api/Helper/Catalog/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ class Bubble_Api_Helper_Catalog_Product extends Mage_Core_Helper_Abstract
* @param array $priceChanges
* @return Bubble_Api_Helper_Catalog_Product
*/
public function associateProducts(Mage_Catalog_Model_Product $product, $simpleSkus, $priceChanges = array())
public function associateProducts(Mage_Catalog_Model_Product $product, $simpleSkus, $priceChanges = array(), $configurableAttributes = array())
{
if (!empty($simpleSkus)) {
$usedProductIds = Mage::getModel('catalog/product')->getCollection()
$newProductIds = Mage::getModel('catalog/product')->getCollection()
->addFieldToFilter('sku', array('in' => (array) $simpleSkus))
->addFieldToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
->getAllIds();

$oldProductIds = Mage::getModel('catalog/product_type_configurable')->setProduct($product)->getUsedProductCollection()
->addAttributeToSelect('*')
->addFilterByRequiredOptions()
->getAllIds();

$usedProductIds = array_diff($newProductIds, $oldProductIds);

if (!empty($usedProductIds)) {
if ($product->isConfigurable()) {
$this->_initConfigurableAttributesData($product, $usedProductIds, $priceChanges);
$this->_initConfigurableAttributesData($product, $usedProductIds, $priceChanges, $configurableAttributes);
} elseif ($product->isGrouped()) {
$relations = array_fill_keys($usedProductIds, array('qty' => 0, 'position' => 0));
$product->setGroupedLinkData($relations);
Expand Down Expand Up @@ -102,7 +110,7 @@ protected function _getCatagoriesSeparator()
* @param array $priceChanges
* @return Bubble_Api_Helper_Catalog_Product
*/
protected function _initConfigurableAttributesData(Mage_Catalog_Model_Product $mainProduct, $simpleProductIds, $priceChanges = array())
protected function _initConfigurableAttributesData(Mage_Catalog_Model_Product $mainProduct, $simpleProductIds, $priceChanges = array(), $configurableAttributes = array())
{
if (!$mainProduct->isConfigurable() || empty($simpleProductIds)) {
return $this;
Expand All @@ -124,6 +132,13 @@ protected function _initConfigurableAttributesData(Mage_Catalog_Model_Product $m
$productType->setUsedProductAttributeIds($attributeIds);
$attributesData = $productType->getConfigurableAttributesAsArray();
}
if (!empty($configurableAttributes)){
foreach ($attributesData as $idx => $val) {
if (!in_array($val['attribute_id'], $configurableAttributes)) {
unset($attributesData[$idx]);
}
}
}

$products = Mage::getModel('catalog/product')->getCollection()
->addIdFilter($simpleProductIds);
Expand Down Expand Up @@ -162,4 +177,4 @@ protected function _initConfigurableAttributesData(Mage_Catalog_Model_Product $m

return $this;
}
}
}
3 changes: 2 additions & 1 deletion app/code/community/Bubble/Api/Model/Catalog/Product/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ protected function _prepareDataForSave($product, $productData)
if (isset($productData['associated_skus'])) {
$simpleSkus = $productData['associated_skus'];
$priceChanges = isset($productData['price_changes']) ? $productData['price_changes'] : array();
Mage::helper('bubble_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges);
$configurableAttributes = isset($productData['configurable_attributes']) ? $productData['configurable_attributes'] : array();
Mage::helper('bubble_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges, $configurableAttributes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ protected function _prepareDataForSave($product, $productData)
$priceChanges = $productData->price_changes;
}
}
Mage::helper('bubble_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges);
$configurableAttributes = array();
if (property_exists($productData, 'configurable_attributes')) {
$configurableAttributes = $productData->configurable_attributes;
}
Mage::helper('bubble_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges, $configurableAttributes);
}
}
}
1 change: 1 addition & 0 deletions app/code/community/Bubble/Api/etc/wsdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<complexType name="catalogProductCreateEntity">
<all>
<element name="associated_skus" type="typens:ArrayOfString" minOccurs="0"/>
<element name="configurable_attributes" type="typens:ArrayOfString" minOccurs="0"/>
<element name="price_changes" type="typens:associativeArray" minOccurs="0" />
</all>
</complexType>
Expand Down
1 change: 1 addition & 0 deletions app/code/community/Bubble/Api/etc/wsi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<xsd:complexType name="catalogProductCreateEntity">
<xsd:sequence>
<xsd:element name="associated_skus" type="typens:ArrayOfString" minOccurs="0" />
<xsd:element name="configurable_attributes" type="typens:ArrayOfString" minOccurs="0" />
<xsd:element name="price_changes" type="typens:complexMultiArray" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
Expand Down

0 comments on commit 457dacf

Please sign in to comment.