Reputation: 51
I have searched SO, Google and the Magento Forums. None of the solutions have helped.
I am trying to update a product's custom attribute via a Joomla! component using Magento's SOAP API V1. I get no errors back, in fact, the result I get back suggests the update succeeded.
When checking the Magento back-end, nothing has changed for this particular product that was apparently updated via my script.
I send the values via an Ajax request. The values are 100% (triple checked). The product DOES exist in Magento.
I am trying to do this using the product's SKU (numerical and not), but even the ID gives me the same result.
My code as it is now (I have tried many variations of this):
$data = trim($_REQUEST['badgedata']);
$sku = trim($_REQUEST['skudata']);
$update_data = array(
'additional_attributes' => array(
'single_data' => array(
array(
'badge' => $data
)
)
)
);
$mage_url = 'http://localhost/magentosite/index.php/api/soap?wsdl';
$mage_user = 'magentousername';
$mage_api_key = 'magentoapikey';
$soap = new SoapClient( $mage_url );
$session_id = $soap->login( $mage_user, $mage_api_key );
$update = $soap->call($session_id, 'catalog_product.update', array($sku, $update_data));
Hope this is enough information. Am I missing something?
Any help would be greatly appreciated! Thanks :)
Upvotes: 2
Views: 2030
Reputation: 51
Okay so,
I fixed this with the help of this post here. Patching "app/code/core/Mage/Catalog/Model/Product/Api/V2.php"
Somewhere around line 263, within:
if (property_exists($productData, 'additional_attributes')) {...}
Place this 3rd IF statement:
if (gettype($productData->additional_attributes) == 'array') {
foreach ($productData->additional_attributes as $k => $v) {
$_attrCode = $k;
$productData->$_attrCode = $v;
}
}
Now using V2 of the SOAP API ( which I should have done in the first place *-.- )
New working code:
$data = trim($_REQUEST['badgedata']);
$sku = trim($_REQUEST['skudata']);
$update_data = array (
'additional_attributes' => array (
'single_data' => array (
array ('key' => 'badge', 'value' => $data)
)
)
);
$mage_url = 'http://localhost/magentosite/index.php/api/v2_soap?wsdl';
$mage_user = 'magentousername';
$mage_api_key = 'magentoapikey';
$soap = new SoapClient( $mage_url );
$session_id = $soap->login( $mage_user, $mage_api_key );
$update = $soap->catalogProductUpdate($session_id, $sku, $update_data);
Thanks to stroisi!
Upvotes: 3