From e634a2106ee660b72d38340b6dc5731884b80d94 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Mon, 26 Jan 2026 14:04:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B0=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D0=BE=D0=B9=20=D1=86?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: „Andrei Reviewed-on: https://git.good-production.xyz/Good-Production/cosmopet-price-updates/pulls/2 Co-authored-by: Dmitriy Co-committed-by: Dmitriy --- src/Services/WCPriceUpdate.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) 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