store 2
This commit is contained in:
@@ -155,11 +155,20 @@ class ProductController extends SuperController
|
||||
{
|
||||
if (app(ConfigService::class)->isStore()) {
|
||||
app(ProductPriceSyncService::class)->syncStorePrices(true);
|
||||
$this->auto_close_open();
|
||||
|
||||
return response()->json(
|
||||
Product::with(['file'])->where('active', 1)->get()
|
||||
);
|
||||
if (! str_contains(request()->path(), '/customer/')) {
|
||||
$this->auto_close_open();
|
||||
}
|
||||
|
||||
$products = Product::with(['file'])->where('active', 1)->get();
|
||||
|
||||
if (str_contains(request()->path(), '/customer/')) {
|
||||
$products->each(function (Product $product) {
|
||||
$product->setAttribute('show', $this->storeProductShowForCustomer($product));
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json($products);
|
||||
}
|
||||
|
||||
// آبشده خانگی — ادمین: sync از کش؛ کاربر: enrich بدون UPDATE
|
||||
@@ -324,6 +333,25 @@ class ProductController extends SuperController
|
||||
|
||||
}
|
||||
|
||||
/** فروشگاه — نمایش در اپ کاربر: فعال + قیمت ذخیرهشده یا محصول وزنی */
|
||||
private function storeProductShowForCustomer(Product $product): bool
|
||||
{
|
||||
if (! $product->active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$storedPrice = (int) ($product->price ?? 0) + (int) ($product->price_profit ?? 0);
|
||||
if ($storedPrice > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((int) ($product->direct_price ?? 0) === 0 && (float) ($product->amount ?? 0) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function filterProductData(array $data): array
|
||||
{
|
||||
if (!Product::hasPriceOffsetColumn()) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user