I finally found the reason for the problem and the solution:
The problem: SOAPv2 with WS-I does not use the single_data
and multi_data
attributes. Therefore the check in /app/code/core/Mage/Catalog/Model/Product/Api/V2.php
in _prepareDataForSave
fails.
The method _prepareDataForSave
checks for single_data
and multi_data
which are both not part of the SOAP-Call, according to the WSDL for SOAPv2 with WS-I.
SOAPv2 (WSDL) - catalogProductCreateEntity:
<element name="additional_attributes" type="typens:catalogProductAdditionalAttributesEntity" minOccurs="0"/>
SOAPv2 with WS-I (WSDL) - catalogProductCreateEntity:
<xsd:element name="additional_attributes" type="typens:associativeArray" minOccurs="0">
</xsd:element>
associativeArray is of type associativeEntity which includes key/value pairs. In SOAPv2 withous WS-I, the catalogProductAdditionalAttributesEntity
is used (which consists of single_data and/or multi_data values which again include key/value pairs).
This is the SOAPv2 WS-I part of the WSDL which describes the format of additional_attributes:
<xsd:complexType name="associativeEntity">
<xsd:sequence>
<xsd:element name="key" type="xsd:string"/>
<xsd:element name="value" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="associativeArray">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray" type="typens:associativeEntity"/>
</xsd:sequence>
</xsd:complexType>
The check for additional_attributes /app/code/core/Mage/Catalog/Model/Product/Api/V2.php
worded fine, but the check for single_data or multi_data always returned false.
The solution:
I found another SOAP Problem here where the last answer was the solution to my problem: https://stackoverflow.com/a/9502311/865443).
So I put this block in my code in _prepareDataForSave
which solved the problem of setting the additional_attributes values:
if (gettype($productData->additional_attributes) == 'array') {
foreach ($productData->additional_attributes as $k => $v) {
$_attrCode = $k;
$productData->$_attrCode = $v;
}
}
I hope this helps someone else encountering the same problem. I would also appreciate an explanation for this differencde between SOAPv2 and SOAPv2 WS-I and/or other ways which solved this problem.
it took me a while to figure this out. Should work for you, if you customy it for your needs.
To list products affected by a price rule, you must make your way over the rule-model.
Here is the code:
<?php
// we need the date to filter for the special price
$dateToday = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
$dateTomorrow = date('m/d/y', $tomorrow);
// this gets the product collection and filters for special price;
// grabs products with special_from_date at least today, and special_to_date at least tomorrow
$_productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $dateToday))
->addAttributeToFilter('special_to_date', array('date' => true, 'from' => $dateTomorrow))
->load();
// this loads the standard magento catalog proce rule model
$rules = Mage::getResourceModel('catalogrule/rule_collection')->load();
// read: if there are active rules
if($rules->getData()) {
$rule_ids = array(); // i used this down below to style the products according to which rule affected
$productIds[] = array(); // this will hold the ids of the products
foreach($rules as $rule) {
$rule_ids[] = $rule->getId();
$productIds = $rule->getMatchingProductIds(); // affected products come in here
}
// merge the collections: $arr is an array and keeps all product IDs we fetched before with the special-price-stuff
$arr = $_productCollection->getAllIds();
if($productIds) {
// if there are products affected by catalog price rules, $arr now also keeps their IDs
$arr = array_merge($arr,$productIds);
}
// we initialize a new collection and filter solely by the product IDs we got before, read: select all products with their entity_id in $arr
$_productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('entity_id',array('in'=>$arr))
->load();
}
== UPDATE ==
I added some comments to the code and renamed $skus
to $productIds
(which fits better).
If you are still getting errors, please let me know what's exactly happening. This code is tested for Magento v1.7.0.2.
Cheers
Simon
Best Answer
Copy extension's design files in your custom theme's design package.