I don't think this is only an issue with special price, since it can be a problem in every numeric type.
I resolved the issue myself (temporary) via a plugin for "Magento\Framework\Webapi\ServiceInputProcessor" on the "convertValue" method. Here I check if the type is Simple via the typeProcessor and if the value is an empty string, if it is I don't cast it to another type. This solved my issue with the special price.
I have some problem.
@bartlubbersen, Could you give your plugin for temporarily resolve this bug? Thanks!
Thanks for reporting this issue. Internal ticket number is MAGETWO-64047.
You guys are right in that it seems to affect other numeric fields as well, but special price is especially bad due to financial loss implications. This is for the engineering team will investigate.
Hi guys
This problem is more general because seems NOT EMPTYING values,
see my question:
https://github.com/magento/magento2/issues/8862
Where can I find info on MAGETWO-64047 ?
I found cause of this but NO clean SOLUTION.
Api don't remove empty values from corresponding tables, ex:
catalog_product_entity_datetime ( handle: special_from_date, special_to_date)
catalog_product_entity_decimal ( handle: special_price)
This two tables handles corresponding values and set to defaults if is EMPTY, but NOT REMOVE.
I'm not expert of MAGENTO 2 coding, so I don't know where must be patched to force remove table records.
any word this, it's driving me crazy.
thank's
This is a problem for us in production. We need a fix here...
I solved this problem for my API with the following plugin:
<type name="Magento\Framework\Webapi\ServiceInputProcessor">
<plugin name="dontConvertEmptyString" type="Vendor\Modulename\Plugin\Framework\Webapi\ServiceInputProcessorPlugin" />
</type>
and class
<?php
namespace Vendor\Modulename\Plugin\Framework\Webapi;
use Magento\Framework\Webapi\ServiceInputProcessor;
use Magento\Framework\Reflection\TypeProcessor;
class ServiceInputProcessorPlugin
{
/**
* @var Request
*/
protected $typeProcessor;
public function __construct(
TypeProcessor $typeProcessor
) {
$this->typeProcessor = $typeProcessor;
}
/**
* Don't convert value if it is empty, because that way you are not able to empty values like prices.
*
* @param ServiceInputProcessor $subject
* @param \Closure $proceed
* @param $data
* @param $type
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundConvertValue(
ServiceInputProcessor $subject,
\Closure $proceed,
$data,
$type
) {
if ($this->typeProcessor->isTypeSimple($type)) {
if ($data === ""){
return $data;
}
}
return $proceed($data, $type);
}
}
Hope this helps.
Can this be treated together with https://github.com/magento/magento2/issues/7468
bartlubbersen,
I've tryed to create plugin suggested, spend time (follows official guides ecc) but my insufficent experience i'm not able to make it work (probably wrong file structure),
app/code/Albertix/WebApiMod/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Albertix_WebApiMod',
__DIR__
);
app/code/Albertix/WebApiMod/etc/di.xml
app/code/Albertix/WebApiMod/Plugin/Framework/Webapi/ServiceInputProcessorPlugin/ServiceInputProcessorPlugin.php
What is wrong of structure ?
Thanks in advance
@bartlubbersen, thank you for your report.
The issue is already fixed in 2.2.0
@bartlubbersen I tried your plugin and it did not fix the issue for me. I verified that the plugin is set up correctly and is being called, but the special price is still being set to "0.0000".
What I've resorted to doing is setting the dates to past values in order to disable the 0.00 special price.
When is this going to be fixed in the release?