Add formula-based product pricing (P/W/MG) for Parsian-style unit prices.

Port FormulaPriceService from colleague app so admins can compute a single unit price from reference mid, weight, and wage instead of offset coefficients.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-10 16:47:29 +03:30
co-authored by Cursor
parent 71a48c9c08
commit f421fcb83f
9 changed files with 515 additions and 9 deletions
+39
View File
@@ -78,6 +78,45 @@ class ProductPriceService
return null;
}
if (FormulaPriceService::isEnabled($product)) {
$computed = FormulaPriceService::calculateForProduct($product, [
'price' => $basePrice,
'active' => true,
]);
if ($computed === null || $computed <= 0) {
if (
Product::hasUseLastPriceIfZeroColumn()
&& ($product->use_last_price_if_zero ?? false)
) {
return null;
}
$computed = 0;
}
$oldPrice = (int) ($product->price ?? 0);
$data = ['price' => $computed];
if (\Illuminate\Support\Facades\Schema::hasColumn($product->getTable(), 'price_profit')) {
$data['price_profit'] = 0;
}
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' => 0.0,
'old_price' => $oldPrice,
'new_price' => $computed,
'changed' => $oldPrice !== $computed,
'price_formula' => true,
];
}
$offsetPercent = self::offsetPercent($product);
$adjustedPrice = self::adjustedTotal($basePrice, $baseProfit, $offsetPercent);
$oldPrice = (int) ($product->price ?? 0);