session(), $store); } /** * Every store page gets the same basics: the design, the fonts, the product list and the cart. * * @param array $view Which page to show. */ private function renderStorefront(Request $request, Storefront $storefront, array $view): Response { $store = $storefront->store; $cart = $this->cart($request, $store); return Inertia::render('stores/preview', [ 'storeName' => $store->name, 'language' => $store->language->value, 'plan' => $storefront->plan, 'fonts' => PlanSchema::FONTS, // Links inside the store are built on top of this address. It is empty for a live store. 'baseUrl' => $storefront->baseUrl, 'preview' => $storefront->preview, 'view' => $view, 'products' => $store->products() ->active() ->with(Product::STOREFRONT_RELATIONS) ->latest('id') ->limit(60) ->get() ->map(fn (Product $product) => $product->toStorefront()), // Products that "featured product" sections point to, by web-address name. // Fetched separately so a featured product always shows, however many products the store has. 'featuredProducts' => (object) $store->products() ->active() ->with(Product::STOREFRONT_RELATIONS) ->whereIn('slug', FeaturedProducts::slugs($storefront->plan)) ->get() ->mapWithKeys(fn (Product $product) => [$product->slug => $product->toStorefront()]) ->all(), // Photos for hero sections: the ones the design points to, and product photos to use otherwise. 'heroImages' => HeroImages::forStorefront($store, $storefront->plan), 'cart' => $cart->toStorefront(), 'shop' => [ // Digits only, such as 60123456789, or null when the merchant has not set one. 'whatsapp' => $store->whatsapp_number, // In ringgit, or null when shipping is never free. 'free_shipping_over' => $store->free_shipping_over !== null ? $store->free_shipping_over / 100 : null, // Lines for the slim bar above the header. Empty when the merchant switched it off. 'announcements' => Announcements::for($store, $cart->liveOffers()), // The cheapest shipping fee in ringgit, for the trust row. 'shipping_from' => min($store->shipping_west, $store->shipping_east) / 100, // Automatic discounts running now, so product pages can mention them. 'offers' => $cart->liveOffers()->map(fn (AutomaticDiscount $offer) => [ 'name' => $offer->name, 'text' => $offer->describe($store->language->value), 'product_ids' => $offer->product_ids, ])->values()->all(), ], ]); } }