This commit is contained in:
2026-06-13 12:42:42 +03:30
parent f8c96a420f
commit e70fcef962
8 changed files with 264 additions and 7 deletions
+18 -3
View File
@@ -26,21 +26,23 @@ class ProductPriceService
: 0.0;
}
public static function syncFromReference(Product $product, int $basePrice, int $baseProfit = 0): void
/** @return array<string, mixed>|null */
public static function syncFromReference(Product $product, int $basePrice, int $baseProfit = 0, ?string $sourceName = null): ?array
{
if (!Product::hasStoredPriceColumns()) {
return;
return null;
}
$offsetPercent = self::offsetPercent($product);
$adjustedPrice = self::adjustedTotal($basePrice, $baseProfit, $offsetPercent);
$oldPrice = (int) ($product->price ?? 0);
if (
$adjustedPrice <= 0
&& Product::hasUseLastPriceIfZeroColumn()
&& ($product->use_last_price_if_zero ?? false)
) {
return;
return null;
}
$data = ['price' => $adjustedPrice];
@@ -50,6 +52,19 @@ class ProductPriceService
}
Product::where('id', $product->id)->update($data);
return [
'product_id' => $product->id,
'product_title' => $product->title,
'reading_method' => $product->reading_method,
'source_name' => $sourceName ?? $product->reading_method,
'base_price' => $basePrice,
'base_profit' => $baseProfit,
'offset_percent' => $offsetPercent,
'old_price' => $oldPrice,
'new_price' => $adjustedPrice,
'changed' => $oldPrice !== $adjustedPrice,
];
}
/** وقتی فقط درصد در ادمین عوض می‌شود (بدون sync جدید) */