This commit is contained in:
2026-06-12 20:10:14 +03:30
parent 98e1fe969c
commit 62dc555196
3 changed files with 243 additions and 23 deletions
+21 -19
View File
@@ -24,13 +24,15 @@ class ProductPriceSyncService
}
/**
* فروشگاه (قطره / کشکول) — همان getPrice قدیمی ghatreh:
* فید legacy + تطبیق reading_method با name + ذخیره خام price/profit (بدون offset).
* فروشگاه (قطره / کشکول) — فید legacy + تطبیق reading_method با name
* + اعمال price_offset_percent روی قیمت ذخیره‌شده.
*/
public function syncStorePrices(bool $forceRefresh = true): bool
{
$RPrices = $this->cachedLegacyPriceList($forceRefresh);
if ($RPrices === null) {
$feed = $this->zaarboxPriceService->cachedPriceList($forceRefresh)
?? $this->cachedLegacyPriceList($forceRefresh);
if ($feed === null) {
return false;
}
@@ -43,23 +45,23 @@ class ProductPriceSyncService
$synced = false;
foreach ($products as $product) {
foreach ($RPrices as $RPrice) {
if ($product->reading_method != ($RPrice['name'] ?? null)) {
continue;
}
$row = $this->zaarboxPriceService->findFeedRow($feed, (string) $product->reading_method);
if ($row === null) {
continue;
}
Product::where('id', $product->id)->update([
'price' => (int) ($RPrice['price'] ?? 0),
'price_profit' => (int) ($RPrice['profit'] ?? 0),
]);
$synced = true;
$row = $this->zaarboxPriceService->normalizeFeedRow($row);
$basePrice = (int) ($row['price'] ?? 0);
$baseProfit = (int) ($row['profit'] ?? 0);
if ((int) ($product->bubble ?? 0) === 1 && $liquidGoldPrice > 0) {
$p = Product::find($product->id);
if ($p) {
$p->amount = (float) ($RPrice['price'] ?? 0) / $liquidGoldPrice;
$p->save();
}
ProductPriceService::syncFromReference($product, $basePrice, $baseProfit);
$synced = true;
if ((int) ($product->bubble ?? 0) === 1 && $liquidGoldPrice > 0 && $basePrice > 0) {
$p = Product::find($product->id);
if ($p) {
$p->amount = $basePrice / $liquidGoldPrice;
$p->save();
}
}
}