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

Commit

Permalink
fix update associated products/prices in Magento 1.7.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hadl committed Jan 15, 2015
1 parent 457dacf commit 9f78922
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 25 deletions.
74 changes: 58 additions & 16 deletions app/code/community/Bubble/Api/Helper/Catalog/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function associateProducts(Mage_Catalog_Model_Product $product, $simpleSk
->addFilterByRequiredOptions()
->getAllIds();

$usedProductIds = array_diff($newProductIds, $oldProductIds);
//$usedProductIds = array_diff($newProductIds, $oldProductIds);
$usedProductIds = array_unique( array_merge($oldProductIds, $newProductIds) );

if (!empty($usedProductIds)) {
if ($product->isConfigurable()) {
Expand Down Expand Up @@ -132,15 +133,16 @@ protected function _initConfigurableAttributesData(Mage_Catalog_Model_Product $m
$productType->setUsedProductAttributeIds($attributeIds);
$attributesData = $productType->getConfigurableAttributesAsArray();
}
if (!empty($configurableAttributes)){
if (!empty($configurableAttributes)) {
foreach ($attributesData as $idx => $val) {
if (!in_array($val['attribute_id'], $configurableAttributes)) {
unset($attributesData[$idx]);
}
}
}

$products = Mage::getModel('catalog/product')->getCollection()
$products = Mage::getModel('catalog/product')
->getCollection()
->addIdFilter($simpleProductIds);

if (count($products)) {
Expand All @@ -152,24 +154,64 @@ protected function _initConfigurableAttributesData(Mage_Catalog_Model_Product $m
$optionId = $product->getData($attributeCode);
$isPercent = 0;
$priceChange = 0;
if (!empty($priceChanges) && isset($priceChanges[$attributeCode])) {
$optionText = $product->getResource()
if (!empty($priceChanges) /*&& (isset($priceChanges[$attributeCode]) || $priceChanges['key'] == $attributeCode)*/) {
/*$optionText = $product
->getResource()
->getAttribute($attribute['attribute_code'])
->getSource()
->getOptionText($optionId);
if (isset($priceChanges[$attributeCode][$optionText])) {
if (false !== strpos($priceChanges[$attributeCode][$optionText], '%')) {
$isPercent = 1;
->getOptionText($optionId);*/

/*if (isset($priceChanges[$attributeCode][$optionText])) {
if (false !== strpos($priceChanges[$attributeCode][$optionText], '%')) {
$isPercent = 1;
}
$priceChange = preg_replace('/[^0-9\.,-]/', '', $priceChanges[$attributeCode][$optionText]);
$priceChange = (float) str_replace(',', '.', $priceChange);
}*/

// check if pricechanges has multi-config-attributes and change array structure
$tmp = reset($priceChanges);
$tmp = (array) $tmp;
if(!isset($tmp['key'])){
$priceChanges = $tmp;
}

foreach ($priceChanges as $_priceChange) {
$_priceChange = (array) $_priceChange;
if ($_priceChange['key'] == $attributeCode) {

if (is_array($_priceChange['value'])) {
foreach ($_priceChange['value'] as $_priceChangeValue) {
$_priceChangeValue = (array) $_priceChangeValue;
if ($_priceChangeValue['key'] == $optionId) {
$change = $_priceChangeValue['value'];
if(empty($change)){
continue;
}
if (false !== strpos($change, '%')) {
$isPercent = 1;
}
$priceChange = preg_replace('/[^0-9\.,-]/', '', $change);
$priceChange = (float) str_replace(',', '.', $priceChange);

$attribute['values'][$optionId] = array(
'value_index' => $optionId,
'is_percent' => $isPercent,
'pricing_value' => $priceChange,
);
}
}
}
}
$priceChange = preg_replace('/[^0-9\.,-]/', '', $priceChanges[$attributeCode][$optionText]);
$priceChange = (float) str_replace(',', '.', $priceChange);
}
}
$attribute['values'][$optionId] = array(
'value_index' => $optionId,
'is_percent' => $isPercent,
'pricing_value' => $priceChange,
);
/*if (!isset($attribute['values'][$optionId])) {
$attribute['values'][$optionId] = array(
'value_index' => $optionId,
'is_percent' => $isPercent,
'pricing_value' => $priceChange,
);
}*/
}
}
$mainProduct->setConfigurableAttributesData($attributesData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ protected function _prepareDataForSave($product, $productData)
$simpleSkus = (array) $productData->associated_skus;
$priceChanges = array();
if (property_exists($productData, 'price_changes')) {
if (key($productData->price_changes) === 0) {
/*if (key($productData->price_changes) === 0) {
$priceChanges = $productData->price_changes[0];
} else {
$priceChanges = $productData->price_changes;
}
}*/
$priceChanges = $productData->price_changes;
}
$configurableAttributes = array();
if (property_exists($productData, 'configurable_attributes')) {
Expand Down
35 changes: 28 additions & 7 deletions app/code/community/Bubble/Api/etc/wsdl.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<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" />
<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" /> -->
<element name="price_changes" type="typens:complexMultiArray" minOccurs="0" />
</all>
</complexType>
<complexType name="catalogProductReturnEntity">
<all>
<element name="associated_skus" type="typens:ArrayOfString" minOccurs="0" />
</all>
</complexType>
<complexType name="complexMultiArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="typens:complexMultiFilter[]"/>
</restriction>
</complexContent>
<!--<all>
<element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray" type="typens:complexMultiFilter" />
</all> -->
</complexType>
<complexType name="complexMultiFilter">
<all>
<element name="key" type="string" />
<element name="value" type="typens:associativeArray" />
</all>
</complexType>
</schema>
Expand Down

0 comments on commit 9f78922

Please sign in to comment.