zarbox added 2

This commit is contained in:
2026-06-04 14:42:22 +03:30
parent 92d01f96da
commit f5d53b2747
4 changed files with 86 additions and 9 deletions
+12 -6
View File
@@ -28,18 +28,24 @@ class ProductPriceService
public static function syncFromReference(Product $product, int $basePrice, int $baseProfit = 0): void
{
$offsetPercent = self::offsetPercent($product);
if (!Product::hasStoredPriceColumns()) {
return;
}
Product::where('id', $product->id)->update([
'price' => self::adjustedTotal($basePrice, $baseProfit, $offsetPercent),
'price_profit' => 0,
]);
$offsetPercent = self::offsetPercent($product);
$data = ['price' => self::adjustedTotal($basePrice, $baseProfit, $offsetPercent)];
if (\Illuminate\Support\Facades\Schema::hasColumn($product->getTable(), 'price_profit')) {
$data['price_profit'] = 0;
}
Product::where('id', $product->id)->update($data);
}
/** وقتی فقط درصد در ادمین عوض می‌شود (بدون sync جدید) */
public static function reapplyOffsetPercent(Product $product, float $newOffsetPercent, ?float $oldOffsetPercent = null): void
{
if (!Product::hasPriceOffsetColumn()) {
if (!Product::hasPriceOffsetColumn() || !Product::hasStoredPriceColumns()) {
return;
}