Magento – Product updates via XML-RPC API not taking effect

apimagento-1.9productxmlrpc

I need to update the value of an attribute in all of my products, so I am trying to script it using the XML-RPC API. Here's the gist of what I'm doing (using a Python API wrapper):

magento.catalog_product.update(
    1234,                         # product id
    {"weight": 3.14}              # "weight" is just an example attribute code
)

I have two different Magento servers for two different stores, both running 1.9.0.1. On the one server, this code works perfectly; the attribute value is updated successfully in the product. On the other server, the update does not take effect. In both cases the method call returns True and does not throw any exceptions. The API users and roles I'm using for both servers are also identical (including the resource access permissions).

Things I have tried:

  • updating the attribute value directly from the admin panel — this works as expected, but is not feasible to do this for ~9000 SKUs
  • deleting and recreating the API user and role, just to be sure
  • setting the store view using catalog_product.currentStore before calling update (per this answer)
  • including the store view ID in the update call as a third paramter
  • checking the system and error logs — saw nothing out of the ordinary
  • using a different API client — I've tried a Ruby wrapper and a NodeJS wrapper to no avail

Any ideas what could be causing this strange behavior? Am I missing something? Like a magic switch somewhere that governs write access for the XML-RPC API? I know for a fact this was working a couple of months ago before we updated to 1.9.

Edit: As @GregC suggested, here are some additional details on my Magento instances:

  • The instances are not copies of each other and there are different product attributes defined in each.
  • The instance that I am having difficulty with has one website/store with two store views. The other instance has one website/store with one store view. I realize that there is a difference here. However, as I said, this was working before I upgraded the problematic instance to 1.9 via the clean install method. The other instance was created recently with 1.9 installed from the beginning.
  • I have tried updating both standard built-in attributes as well as custom attributes. None of them seem to update properly.
  • I have tried updating both textual (such as SKU, description) and numerical fields (such as weight, price) without success.
  • The problematic instance is hosted on SimpleHelix, who also performed the clean install of 1.9. I will try contacting them to see if other customers have had similar issues. The other instance is hosted in the Rackspace Cloud and was installed by myself.

At this point I am leaning toward a problem with one of the following:

  1. A Magento core file that someone edited when installing a module or trying to workaround a problem
  2. A remnant of v1.7 that is lurking around and causing issues, either in the database or on the filesystem
  3. A module that is installed on the problematic instance but not on the other instance. Unfortunately, there are several such modules and I can't just go around uninstalling them to see if it fixes the issue.

I realize that it would be nearly impossible to give me a straight solution to this problem, but any tips for how to track it down would be appreciated. Are there any good ways to debug this type of issue?

Best Answer

Disclaimer: This is not a solution to the XML-RPC issue, but a workaround you could attempt

This solution will use direct SQL which is safe in this instance as there are not any default triggers which would be thrown on updating of the weight attribute.

Find out your weight attribute id & type. You can do this by navigating through CatalogAttributesManage Attributes. Filter by the weight attribute and edit it.

In the URL you will find the attribute_id, like this:

www.yourstore.com/admin/catalog_product_attribute/edit/attribute_id/65/key/...

Once you have the attribute code, you just need to know whether the value is in int, decimal or text format, which will be stored in the _int, _decimal, _varchar EAV tables.

Magento by default creates the weight attribtue in the varchar table.

Your solution script would be:

<?php
$connection_write = Mage::getSingleton('core/resource')->getConnection('core_write');
$attribute_id = 65; //your weight attribute id
$products = array(1,2,3,4); //your product id array
foreach ($products as $product_id){
    $sql = 'UPDATE `catalog_product_entity_varchar` SET `value` = ? WHERE `entity_id` = ? AND `attribute_id` = ?';
    //this is assuming it is stored within the varchar table (other options are _int or _decimal)
    $connection_write->query($sql, array("3.14", $product_id, $attribute_id);
    //should this be in the _int or _decimal table, you'd omit the quotation marks around the value
}
echo "Complete";
?>

Once you run your script, your products will update extremely quickly, likely in a matter of seconds.

Heads up:

  1. To be safe, backup your website & database prior to running the script
  2. Run a full cache & reindex thereafter

Let me know if you have any troubles.

Related Topic