Magento Product Create API: use_config_min_sale_qty (and max) attributes
In a site I maintain I have a separate web application for adding products. The reason for this is that products need to be added to both a backend warehousing system as well as magento.
I’m posting this because the documentation on the magento site isn’t clear about how one goes about setting these attributes:
min_sale_qty use_config_min_sale_qty use_config_max_sale_qty use_config_manage_stock
Although these attributes are exported to a csv file via Admin->Profiles, they are not so simply assigned via the API. Here’s the snippet given as an example on magento’s site:
1 2 3 4 5 6 7 8 9 10 11 | $newProductData = array( 'name' => 'name of product', 'websites' => array(1), // array(1,2,3,...) 'short_description' => 'short description', 'description' => 'description', 'price' => 12.05 ); // Create new product $proxy->call($sessionId, 'product.create', array('simple', $set['set_id'], 'sku_of_product', $newProductData)); |
What I cannot do is set min_sale_qty, use_config_min_sale_qty etc in the $newProductData array – that is, this will not work:
1 2 3 4 5 6 7 8 9 10 11 | $newProductData = array( 'name' => 'name of product', 'websites' => array(1), // array(1,2,3,...) 'short_description' => 'short description', 'description' => 'description', 'price' => 12.05, 'min_sale_qty' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1, 'use_config_manage_stock' => 1 ); |
Rather, these attributes must be set within a double secret probation array called stock_data! I divined this from this page on magento’s forum. I wrote my code like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $stock_data = array ( 'min_sale_qty' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1, 'use_config_manage_stock' => 1 ); $newProductData = array( 'name' => 'name of product', 'websites' => array(1), // array(1,2,3,...) 'short_description' => 'short description', 'description' => 'description', 'price' => 12.05, 'stock_data' => $stock_data ); $proxy->call($sessionId, 'product.create', array('simple', $set['set_id'], 'sku_of_product', $newProductData)); |
For the record, I chose to separately declare $stock_data to make the code easier to read and understand. I’m not a big fan of array with array within array etc. Gets too clunky.
Leave a Reply