Skip to content

Commit a116a96

Browse files
committed
MAGETWO-69714: Cannot delete product tier-prices
1 parent 1aaa2fc commit a116a96

File tree

2 files changed

+21
-3
lines changed
  • app/code/Magento/Catalog

2 files changed

+21
-3
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
179179
} else {
180180
$productOptions = [];
181181
}
182-
182+
$productData['tier_price'] = isset($productData['tier_price']) ? $productData['tier_price'] : [];
183183
$product->addData($productData);
184184

185185
if ($wasLockedMedia) {

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,15 @@ protected function updateValues(array $valuesToUpdate, array $oldValues)
180180
{
181181
$isChanged = false;
182182
foreach ($valuesToUpdate as $key => $value) {
183-
if ($oldValues[$key]['price'] != $value['value']
184-
|| $this->getPercentage($oldValues[$key]) != $this->getPercentage($value)
183+
$oldPrice = $this->prepareFloatValue($oldValues[$key]['price']);
184+
$newPrice = $this->prepareFloatValue($value['value']);
185+
$oldQty = $this->prepareFloatValue($oldValues[$key]['price_qty']);
186+
$newQty = $this->prepareFloatValue($value['qty']);
187+
$oldPercentageValue = $this->prepareFloatValue($this->getPercentage($oldValues[$key]));
188+
$newPercentageValue = $this->prepareFloatValue($this->getPercentage($value));
189+
if (($oldPrice !== $newPrice)
190+
|| ($oldQty !== $newQty)
191+
|| ($oldPercentageValue !== $newPercentageValue)
185192
) {
186193
$price = new \Magento\Framework\DataObject(
187194
[
@@ -198,6 +205,17 @@ protected function updateValues(array $valuesToUpdate, array $oldValues)
198205
return $isChanged;
199206
}
200207

208+
/**
209+
* Prepare float value for comparison
210+
*
211+
* @param string|float|int $value
212+
* @return float
213+
*/
214+
private function prepareFloatValue($value)
215+
{
216+
return floatval(str_replace(',', '.', (string)$value));
217+
}
218+
201219
/**
202220
* Check whether price has percentage value.
203221
*

0 commit comments

Comments
 (0)