zarbox added
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -142,4 +143,34 @@ class EtehadiePriceService
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** بهروز قیمت یک محصول از API با reading_method */
|
||||
public function syncProductFromApi(Product $product): bool
|
||||
{
|
||||
if (!$product->reading_method) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$prices = $this->fetchPriceList();
|
||||
if ($prices === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$RPrice = collect($prices)->firstWhere('key', $product->reading_method);
|
||||
if (empty($RPrice)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($RPrice['name'] ?? '') === 'گلد دات ای از آبشده - رسمی - نقد فردا') {
|
||||
$RPrice['price'] = ($RPrice['price'] ?? 0) / 4.3318;
|
||||
}
|
||||
|
||||
ProductPriceService::syncFromReference(
|
||||
$product,
|
||||
(int) $RPrice['price'],
|
||||
(int) ($RPrice['profit'] ?? 0)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user