added kashkool 5
This commit is contained in:
@@ -162,9 +162,7 @@ class ProductController extends SuperController
|
||||
$displayPriceService = app(ProductDisplayPriceService::class);
|
||||
$displayPriceService->enrichForApi($products);
|
||||
$products->each(function (Product $product) use ($displayPriceService) {
|
||||
if (! $displayPriceService->hasCustomerDisplayPrice($product)) {
|
||||
$product->setAttribute('show', false);
|
||||
}
|
||||
$product->setAttribute('show', $displayPriceService->resolveCustomerShow($product));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -57,10 +57,76 @@ class ProductDisplayPriceService
|
||||
|
||||
if ($product->reading_method && is_array($zaarboxFeed)) {
|
||||
$this->applyReferenceFeedPrice($product, $zaarboxFeed, $zaarbox);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->isWeightBasedStoreProduct($product)) {
|
||||
$this->enrichWeightBasedPrice($product);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** شمش / سکه و … — قیمت واحد (هر گرم) از مظنه زنده یا آخرین قیمت */
|
||||
private function isWeightBasedStoreProduct(Product $product): bool
|
||||
{
|
||||
if ($this->usesAppPrice($product) || $product->reading_method) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((int) ($product->direct_price ?? 0) === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (float) ($product->amount ?? 0) > 0;
|
||||
}
|
||||
|
||||
private function enrichWeightBasedPrice(Product $product): void
|
||||
{
|
||||
$useLast = $this->productUsesLastPriceIfZero($product);
|
||||
$unitBuy = $useLast
|
||||
? $this->resolveLiveBuyPriceWithFallback()
|
||||
: $this->resolveStrictLiveBuyPrice();
|
||||
|
||||
if ($unitBuy <= 0 && ! $useLast && app(ConfigService::class)->getBool('show_last_price', false)) {
|
||||
$unitBuy = $this->resolveHistoricalBasePrice();
|
||||
}
|
||||
|
||||
$this->applyPriceOrFallback($product, $unitBuy, $useLast);
|
||||
}
|
||||
|
||||
private function resolveStrictLiveBuyPrice(): int
|
||||
{
|
||||
$cached = Cache::get(self::LIVE_PRICE_CACHE_KEY);
|
||||
if (! is_array($cached)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$buy = (int) ($cached['buy'] ?? 0);
|
||||
if ($buy > 0) {
|
||||
return $buy;
|
||||
}
|
||||
|
||||
$priceLast = (int) ($cached['price_last'] ?? 0);
|
||||
if ($priceLast > 0) {
|
||||
return $priceLast;
|
||||
}
|
||||
|
||||
return $this->extractBaseFromPayload($cached);
|
||||
}
|
||||
|
||||
private function resolveLiveBuyPriceWithFallback(): int
|
||||
{
|
||||
$strict = $this->resolveStrictLiveBuyPrice();
|
||||
if ($strict > 0) {
|
||||
return $strict;
|
||||
}
|
||||
|
||||
$payload = $this->resolveFallbackPayload();
|
||||
|
||||
return (int) ($payload['buy'] ?? 0) ?: (int) ($payload['price_last'] ?? 0);
|
||||
}
|
||||
|
||||
private function applyAppPrice(Product $product, int $basePrice): void
|
||||
{
|
||||
$useLast = $this->productUsesLastPriceIfZero($product);
|
||||
@@ -347,4 +413,29 @@ class ProductDisplayPriceService
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* نمایش در اپ کاربر:
|
||||
* • خاموش (show=false در DB) → false
|
||||
* • قیمت نمایشی بعد از enrich → true
|
||||
* • قیمت صفر و show_last_price خاموش → false
|
||||
* • قیمت صفر و show_last_price روشن و fallback موجود → true
|
||||
*/
|
||||
public function resolveCustomerShow(Product $product): bool
|
||||
{
|
||||
if (! (bool) ($product->show ?? true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->hasCustomerDisplayPrice($product)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! app(ConfigService::class)->getBool('show_last_price', false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->resolveLastPriceFallback($product) > 0
|
||||
|| $this->resolveHistoricalBasePrice() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user