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