diff --git a/src/Services/WCPriceUpdate.php b/src/Services/WCPriceUpdate.php index 5471735..04691d6 100644 --- a/src/Services/WCPriceUpdate.php +++ b/src/Services/WCPriceUpdate.php @@ -32,7 +32,7 @@ class WCPriceUpdate { ]; // Если цена товара равна базовой и акционная цена отсутствует, его нет смысла обновлять, т.к. данные везде совпадают - if ($price["regular"] === $price["new"] && $price["sale"] === 0) { + if ($price["regular"] === $price["new"] && $price["sale"] === "") { $result[] = array_merge($item->toArray(), $price, [ "message" => "Товар не обновлён. Цены совпадают.", "isError" => true ]); continue; } @@ -45,15 +45,16 @@ class WCPriceUpdate { if ($price["regular"] <= $price["new"]) { $product->set_regular_price($price["new"]); - - if ($price["sale"] > 0) { - $product->set_sale_price(0); - } + // Полностью очищаем акционную цену + $product = self::clearSalePrice($product); } else { - $product->set_sale_price($price["new"]); + if ($price["new"] == 0) { + $product = self::clearSalePrice($product); + } else { + $product->set_sale_price($price["new"]); + } } - $product->save(); $result[] = [ @@ -73,4 +74,12 @@ class WCPriceUpdate { return $result; } + + private static function clearSalePrice($product) { + $product->set_sale_price(""); + $product->set_date_on_sale_from(""); + $product->set_date_on_sale_to(""); + + return $product; + } } \ No newline at end of file