Поправки удаления акционной цены.

Co-authored-by: „Andrei <you@example.com>
Reviewed-on: #2
Co-authored-by: Dmitriy <Quali123@list.ru>
Co-committed-by: Dmitriy <Quali123@list.ru>
This commit was merged in pull request #2.
This commit is contained in:
web_103and„Andrei authored and WEB № 103 - Дмитрий | Vue, NestJS, WP committed 2026-01-26 14:04:27 +03:00
1 parent 3c33c265b2
commit e634a2106e
1 file changed
+15 -6
+15 -6
View File
@@ -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 ]); $result[] = array_merge($item->toArray(), $price, [ "message" => "Товар не обновлён. Цены совпадают.", "isError" => true ]);
continue; continue;
} }
@@ -45,14 +45,15 @@ class WCPriceUpdate {
if ($price["regular"] <= $price["new"]) { if ($price["regular"] <= $price["new"]) {
$product->set_regular_price($price["new"]); $product->set_regular_price($price["new"]);
// Полностью очищаем акционную цену
if ($price["sale"] > 0) { $product = self::clearSalePrice($product);
$product->set_sale_price(0); } else {
} if ($price["new"] == 0) {
$product = self::clearSalePrice($product);
} else { } else {
$product->set_sale_price($price["new"]); $product->set_sale_price($price["new"]);
} }
}
$product->save(); $product->save();
@@ -73,4 +74,12 @@ class WCPriceUpdate {
return $result; 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;
}
} }