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
@@ -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()) {