store 6
This commit is contained in:
@@ -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 جدید) */
|
||||
|
||||
Reference in New Issue
Block a user