fixed show true when price is 0 3
This commit is contained in:
@@ -289,8 +289,7 @@ class ProductDisplayPriceService
|
||||
return;
|
||||
}
|
||||
|
||||
$normalized = $zaarbox->normalizeFeedRow($row);
|
||||
$providerRaw = (int) round((float) ($normalized['price'] ?? 0) + (float) ($normalized['profit'] ?? 0));
|
||||
$providerRaw = $zaarbox->resolveReferenceProviderTotal($row);
|
||||
$providerActive = $useLast || $providerRaw > 0;
|
||||
$product->setAttribute('reference_provider_active', $providerActive);
|
||||
|
||||
@@ -435,7 +434,7 @@ class ProductDisplayPriceService
|
||||
|
||||
$row = app(ZaarboxPriceService::class)->normalizeFeedRow($row);
|
||||
|
||||
return (int) round((float) ($row['price'] ?? 0) + (float) ($row['profit'] ?? 0));
|
||||
return app(ZaarboxPriceService::class)->resolveReferenceProviderTotal($row);
|
||||
}
|
||||
|
||||
private function isMeltedTradeProduct(Product $product): bool
|
||||
|
||||
@@ -221,9 +221,7 @@ class ZaarboxPriceService
|
||||
return $empty;
|
||||
}
|
||||
|
||||
$base = (float) ($row['price'] ?? 0);
|
||||
$profit = (float) ($row['profit'] ?? 0);
|
||||
$orderPrice = (int) round($base + $profit);
|
||||
$orderPrice = $this->resolveReferenceProviderTotal($row);
|
||||
|
||||
return ['price' => $orderPrice, 'order_price' => $orderPrice, 'raw' => $row];
|
||||
} catch (\Throwable $e) {
|
||||
@@ -339,7 +337,7 @@ class ZaarboxPriceService
|
||||
return $empty;
|
||||
}
|
||||
|
||||
$orderPrice = (int) round((float) ($row['price'] ?? 0) + (float) ($row['profit'] ?? 0));
|
||||
$orderPrice = $this->resolveReferenceProviderTotal($row);
|
||||
|
||||
return ['order_price' => $orderPrice, 'raw' => $row];
|
||||
} catch (\Throwable $e) {
|
||||
@@ -386,23 +384,24 @@ class ZaarboxPriceService
|
||||
}
|
||||
|
||||
$row = $this->normalizeFeedRow($RPrice);
|
||||
$parts = $this->resolveReferenceBaseProfit($row);
|
||||
|
||||
if (($row['name'] ?? '') === 'TGJU فلز مس') {
|
||||
$copper = ($row['price'] ?? 0) + ($row['profit'] ?? 0);
|
||||
$copper = $parts['price'] + $parts['profit'];
|
||||
}
|
||||
if (($row['name'] ?? '') === 'TGJU دلار') {
|
||||
$dollar = ($row['price'] ?? 0) + ($row['profit'] ?? 0);
|
||||
$dollar = $parts['price'] + $parts['profit'];
|
||||
}
|
||||
|
||||
ProductPriceService::syncFromReference(
|
||||
$product,
|
||||
(int) $row['price'],
|
||||
(int) ($row['profit'] ?? 0)
|
||||
$parts['price'],
|
||||
$parts['profit']
|
||||
);
|
||||
|
||||
$productPrice = (float) ProductPriceService::adjustedTotal(
|
||||
(int) $row['price'],
|
||||
(int) ($row['profit'] ?? 0),
|
||||
$parts['price'],
|
||||
$parts['profit'],
|
||||
ProductPriceService::offsetPercent($product)
|
||||
);
|
||||
|
||||
@@ -477,22 +476,6 @@ class ZaarboxPriceService
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* قیمت نمایشی محصول از یک ردیف فید + offset درصد — بدون نوشتن DB
|
||||
*
|
||||
* @param array<string, mixed> $row
|
||||
*/
|
||||
public function computeAdjustedProductPrice(Product $product, array $row): int
|
||||
{
|
||||
$normalized = $this->normalizeFeedRow($row);
|
||||
|
||||
return ProductPriceService::adjustedTotal(
|
||||
(int) ($normalized['price'] ?? 0),
|
||||
(int) ($normalized['profit'] ?? 0),
|
||||
ProductPriceService::offsetPercent($product)
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
public function normalizeFeedRow(array $row): array
|
||||
{
|
||||
@@ -503,6 +486,55 @@ class ZaarboxPriceService
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* base/profit مرجع zaarbox — وقتی price صفر است provider قیمت نداده (profit مقدار قدیمی است).
|
||||
*
|
||||
* @param array<string, mixed> $row
|
||||
* @return array{price: int, profit: int}
|
||||
*/
|
||||
public function resolveReferenceBaseProfit(array $row): array
|
||||
{
|
||||
$normalized = $this->normalizeFeedRow($row);
|
||||
$price = (int) round((float) ($normalized['price'] ?? 0));
|
||||
if ($price <= 0) {
|
||||
return ['price' => 0, 'profit' => 0];
|
||||
}
|
||||
|
||||
return [
|
||||
'price' => $price,
|
||||
'profit' => (int) round((float) ($normalized['profit'] ?? 0)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $row
|
||||
*/
|
||||
public function resolveReferenceProviderTotal(array $row): int
|
||||
{
|
||||
$parts = $this->resolveReferenceBaseProfit($row);
|
||||
|
||||
return $parts['price'] + $parts['profit'];
|
||||
}
|
||||
|
||||
/**
|
||||
* قیمت نمایشی محصول از یک ردیف فید + offset درصد — بدون نوشتن DB
|
||||
*
|
||||
* @param array<string, mixed> $row
|
||||
*/
|
||||
public function computeAdjustedProductPrice(Product $product, array $row): int
|
||||
{
|
||||
$parts = $this->resolveReferenceBaseProfit($row);
|
||||
if ($parts['price'] <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ProductPriceService::adjustedTotal(
|
||||
$parts['price'],
|
||||
$parts['profit'],
|
||||
ProductPriceService::offsetPercent($product)
|
||||
);
|
||||
}
|
||||
|
||||
public function syncProductFromApi(Product $product): bool
|
||||
{
|
||||
if (!Product::hasStoredPriceColumns()) {
|
||||
@@ -524,11 +556,12 @@ class ZaarboxPriceService
|
||||
}
|
||||
|
||||
$row = $this->normalizeFeedRow($RPrice);
|
||||
$parts = $this->resolveReferenceBaseProfit($row);
|
||||
|
||||
ProductPriceService::syncFromReference(
|
||||
$product,
|
||||
(int) $row['price'],
|
||||
(int) ($row['profit'] ?? 0)
|
||||
$parts['price'],
|
||||
$parts['profit']
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user