1.
PUT http://myhost/rest/V1/products/p000018_1-10%2C15-210 http/1.1
{"product":{"id":935,"sku":"p000018_1-10,15-210","name":"18_Donna Chuck Taylor All Star Fresh [38,5,Rosa]","attribute_set_id":9,"price":135,"status":2,"visibility":1,"type_id":"simple","created_at":"2017-02-01 13:05:47","updated_at":"2017-02-01 13:05:47","weight":1,"extension_attributes":{"stock_item":{"item_id":897.0,"product_id":935.0,"stock_id":1.0,"qty":0.0,"is_in_stock":false,"is_qty_decimal":false,"show_default_notification_message":false,"use_config_min_qty":true,"min_qty":0.0,"use_config_min_sale_qty":1.0,"min_sale_qty":1.0,"use_config_max_sale_qty":true,"max_sale_qty":10000.0,"use_config_backorders":true,"backorders":0.0,"use_config_notify_stock_qty":true,"notify_stock_qty":1.0,"use_config_qty_increments":true,"qty_increments":0.0,"use_config_enable_qty_inc":true,"enable_qty_increments":false,"use_config_manage_stock":false,"manage_stock":true,"low_stock_date":"2017-03-10 10:42:41","is_decimal_divided":false,"stock_status_changed_auto":1.0}},"product_links":[],"options":[],"media_gallery_entries":[],"tier_prices":[],"custom_attributes":[{"attribute_code":"special_price","value":" "},{"attribute_code":"special_from_date","value":" "},{"attribute_code":"special_to_date","value":" "},{"attribute_code":"news_from_date","value":"2017-03-01 15:30:42"},{"attribute_code":"custom_design_from","value":"2017-03-01 15:30:42"},{"attribute_code":"category_ids","value":[]},{"attribute_code":"options_container","value":"container2"},{"attribute_code":"required_options","value":"0"},{"attribute_code":"has_options","value":"0"},{"attribute_code":"url_key","value":"donna-chuck-taylor-all-star-fresh-38-5-rosa"},{"attribute_code":"tax_class_id","value":"2"},{"attribute_code":"taglie_scarpe_donna","value":"14"},{"attribute_code":"colore","value":"215"}]}}
NOTE : particular: special_price, special_from_date, special_to_date - all is empty (before was valued)
RESPONSE
{"id":935,"sku":"p000018_1-10,15-210","name":"18_Donna Chuck Taylor All Star Fresh [38,5,Rosa]","attribute_set_id":9,"price":135,"status":2,"visibility":1,"type_id":"simple","created_at":"2017-02-01 13:05:47","updated_at":"2017-02-01 13:05:47","weight":1,"extension_attributes":{"stock_item":{"item_id":897,"product_id":935,"stock_id":1,"qty":0,"is_in_stock":false,"is_qty_decimal":false,"show_default_notification_message":false,"use_config_min_qty":true,"min_qty":0,"use_config_min_sale_qty":1,"min_sale_qty":1,"use_config_max_sale_qty":true,"max_sale_qty":10000,"use_config_backorders":true,"backorders":0,"use_config_notify_stock_qty":true,"notify_stock_qty":1,"use_config_qty_increments":true,"qty_increments":0,"use_config_enable_qty_inc":true,"enable_qty_increments":false,"use_config_manage_stock":false,"manage_stock":true,"low_stock_date":"2017-03-13 09:20:00","is_decimal_divided":false,"stock_status_changed_auto":1}},"product_links":[],"options":[],"media_gallery_entries":[],"tier_prices":[],"custom_attributes":[{"attribute_code":"special_price","value":"0.0000"},{"attribute_code":"special_from_date","value":"2017-03-13 09:20:00"},{"attribute_code":"special_to_date","value":"2017-03-13 09:20:00"},{"attribute_code":"news_from_date","value":"2017-03-01 15:30:42"},{"attribute_code":"custom_design_from","value":"2017-03-01 15:30:42"},{"attribute_code":"category_ids","value":[]},{"attribute_code":"options_container","value":"container2"},{"attribute_code":"required_options","value":"0"},{"attribute_code":"has_options","value":"0"},{"attribute_code":"url_key","value":"donna-chuck-taylor-all-star-fresh-38-5-rosa"},{"attribute_code":"tax_class_id","value":"2"},{"attribute_code":"taglie_scarpe_donna","value":"14"},{"attribute_code":"colore","value":"215"}]}
NOTE: response
special_from_date, special_to_date, special_price : all VALUED !!!! WHY ???
I have not method to resolve : EMPTYING VALUES. Is possible to do it in magento 2 ????
I've also struggled with this. I resorted to hacky tricks like setting the value to a single space or a direct database update. For special pricing, I set the price equal to the "normal" price and Magento ignores it.
This definitely needs to be resolved. The developers never at all considered that maybe a user would want to set an attribute value to an empty string.
Airman, are You right.
My further suggestions.
I've examinated database structure and in my case
in table: "catalog_product_entity_datetime" i found correspond record (attribute_id: 80, entity_id
Correct behaviour is to DELETE empty values.
Is no possible to empty completly attribute because this tables handle also empty values (like date, double eccc)
Confirmed. Values can't be "unset" using the WebAPI.
This especially is fun with the special_price.
Setting it to
{
"attribute_code": "special_price",
"value": ""
}
sets it to 0.0000, which makes the product very cheap indeed. Our current hacky workaround is to to set the special_price to the same value as price, so it doesn't render as a special price on the frontend.
Still, this workaround might not be possible for all attributes, and it's far from ideal.
I think the ideal behavior would be to set a value to NULL if the JSON value is an empty string.
Alternatively, omitting the attribute from the payload could mean "unset", too.
I also discovered the trick of setting special_price and price to be equal so that Magento doesn't do any special price rendering. It's the best I can do for now.
I wouldn't recommend omitting the attribute as equivalent to a removal request. I really like only having to set price for example, and not have to iterate over every single attribute and set its value. I think a null value would work just fine.
@albertixcom Please try to add to your API call value "all" , like (domain)/rest/all/v1/products/(sku) and in body instead of empy value " " for special price attributes put there value null like:
{
"product":{ "custom_attributes":[
{
"attribute_code": "special_price",
"value": null
},
{
"attribute_code": "special_from_date",
"value": null
},
{
"attribute_code": "special_to_date",
"value": null
}
]
}}
I confirm the problem stil exist in Magento 2.1.8
@smoskaluk Your solution will not work. I have tried both null and "".
@albertixcom, thank you for your report.
We've created internal ticket(s) MAGETWO-78406 to track progress on the issue.
@albertixcom We are closing this issue report now, as the fix is already implemented in the 2.2-develop branch and will be released with the next functional patch for 2.2.x
this problem still exists in 2.3.3
Most helpful comment
Confirmed. Values can't be "unset" using the WebAPI.
This especially is fun with the
special_price.Setting it to
sets it to
0.0000, which makes the product very cheap indeed. Our current hacky workaround is to to set thespecial_priceto the same value asprice, so it doesn't render as a special price on the frontend.Still, this workaround might not be possible for all attributes, and it's far from ideal.
I think the ideal behavior would be to set a value to
NULLif the JSON value is an empty string.Alternatively, omitting the attribute from the payload could mean "unset", too.