fix bug 2
This commit is contained in:
@@ -65,7 +65,20 @@ class ProductDisplayPriceService
|
||||
|
||||
private function applyAppPrice(Product $product, int $basePrice): void
|
||||
{
|
||||
$storedPrice = (int) ($product->price ?? 0);
|
||||
$useLast = Product::hasUseLastPriceIfZeroColumn()
|
||||
&& ($product->use_last_price_if_zero ?? false);
|
||||
|
||||
if ($basePrice <= 0) {
|
||||
if ($useLast && $storedPrice > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$product->setAttribute('price', 0);
|
||||
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
|
||||
$product->setAttribute('price_profit', 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -75,6 +88,15 @@ class ProductDisplayPriceService
|
||||
|
||||
$computed = ProductPriceService::adjustedTotal($basePrice, 0, $offset);
|
||||
if ($computed <= 0) {
|
||||
if ($useLast && $storedPrice > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$product->setAttribute('price', 0);
|
||||
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
|
||||
$product->setAttribute('price_profit', 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -232,4 +254,23 @@ class ProductDisplayPriceService
|
||||
|
||||
return in_array($group, ['آبشده', 'کاتد مس'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* آیا بعد از enrich قیمت پایه برای نمایش در اپ کاربر وجود دارد؟
|
||||
* کارمزد (cash_fee) بهتنهایی قیمت محسوب نمیشود.
|
||||
*/
|
||||
public function hasCustomerDisplayPrice(Product $product): bool
|
||||
{
|
||||
if ((int) ($product->price ?? 0) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
|
||||
if ((int) ($product->price_profit ?? 0) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,37 @@ class ProductPriceSyncService
|
||||
$synced = true;
|
||||
}
|
||||
|
||||
if ($this->syncAppPriceProducts()) {
|
||||
$synced = true;
|
||||
}
|
||||
|
||||
return $synced;
|
||||
}
|
||||
|
||||
/** محصولات آبشده با مرجع «قیمت اپ» — ذخیره آخرین قیمت در DB برای fallback */
|
||||
private function syncAppPriceProducts(): bool
|
||||
{
|
||||
$display = app(ProductDisplayPriceService::class);
|
||||
$products = Product::query()
|
||||
->where('active', 1)
|
||||
->get()
|
||||
->filter(static fn (Product $product) => $display->usesAppPrice($product));
|
||||
|
||||
if ($products->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$basePrice = $display->resolveAppBasePrice();
|
||||
if ($basePrice <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$synced = false;
|
||||
foreach ($products as $product) {
|
||||
ProductPriceService::syncFromReference($product, $basePrice, 0);
|
||||
$synced = true;
|
||||
}
|
||||
|
||||
return $synced;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user