I asked a similar question on Stack Overflow as well, and was directed to an article explaining the various available filter options available to the products REST endpoint.
What I was looking for is mostly covered by using the filter
parameter, like so:
http://magentohost/api/rest/products?filter[1][attribute]=description&filter[1][in]=%shirt%
Each filter
parameter appears to take an identifying number as well as the field to filter against, followed by another filter parameter referencing the desired identifying number, with the actual value to filter against following.
Placing the term to search for inside %
applies limited loose matching, allowing for returning records that has a field containing a query term, rather than exactly matching it. The full article on the subject is here, and the Stack Overflow question is here.
Cheers!
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 Catalog
→ Attributes
→ Manage 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:
- To be safe, backup your website & database prior to running the script
- Run a full cache & reindex thereafter
Let me know if you have any troubles.
Best Answer
POST /V1/products
should be used for product creation, whilePUT /V1/products/:sku
for product update. They both rely on the same service method\Magento\Catalog\Model\ProductRepository::save
, but that may be your problem.