Skip to content

Commit 14b9205

Browse files
author
Cari Spruiell
committed
MAGETWO-64047: WebAPI: It's impossible to empty numeric fields after they're set
- add handling of null values passed as 'special_price' custom attribute
1 parent b20db76 commit 14b9205

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Observer;
7+
8+
use Magento\Framework\Event\ObserverInterface;
9+
10+
/**
11+
* Unset value for Special Price if passed as null
12+
*/
13+
class UnsetSpecialPrice implements ObserverInterface
14+
{
15+
/**
16+
* Unset the Special Price attribute if it is null
17+
*
18+
* @param \Magento\Framework\Event\Observer $observer
19+
* @return $this
20+
*/
21+
public function execute(\Magento\Framework\Event\Observer $observer)
22+
{
23+
/** @var $product \Magento\Catalog\Model\Product */
24+
$product = $observer->getEvent()->getProduct();
25+
if ($product->getSpecialPrice() === null) {
26+
$product->setData('special_price', '');
27+
}
28+
29+
return $this;
30+
}
31+
}

app/code/Magento/Catalog/etc/events.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
</event>
5757
<event name="catalog_product_save_before">
5858
<observer name="set_special_price_start_date" instance="Magento\Catalog\Observer\SetSpecialPriceStartDate" />
59+
<observer name="unset_special_price" instance="Magento\Catalog\Observer\UnsetSpecialPrice" />
5960
</event>
6061
</config>

app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ public function isValueEmpty($value)
661661
*/
662662
public function isAllowedEmptyTextValue($value)
663663
{
664-
return $this->isInEmptyStringTypes() && ($value === self::EMPTY_STRING || $value === null);
664+
return $this->isInEmptyStringTypes() && $value === self::EMPTY_STRING;
665665
}
666666

667667
/**

0 commit comments

Comments
 (0)