/** * @param Request $request * @param int $id * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return \Illuminate\Http\RedirectResponse */ public function putProducts(Request $request, int $id) { /** @var Offer $offer */ $offer = $this->offer->findOrFail($id); $offer->products()->sync((array) $request->get('product-ids')); $this->webUi->successMessage("Set products for offer `{$offer->name}`."); return $this->webUi->redirect('offers.index'); }
/** * Display the specified resource. * * @param string $sku * * @throws NotFoundHttpException * * @return \Illuminate\Http\Response */ public function show(string $sku) { $product = $this->mustLoadProductBySku($sku); $tags = $this->catalogueRepository->loadAllTags(); $colours = $this->catalogueRepository->loadAllColours(); $categories = $this->catalogueRepository->loadAllCategories(); $offers = Offer::all(); return $this->buildView('show', compact('product', 'tags', 'colours', 'categories', 'offers')); }
/** * @throws \InvalidArgumentException * * @return Money */ private function priceFromRelative() : Money { if ($this->offer->isPriced()) { // Relative price offer (i.e. a set discount). return $this->offer->price->negative(); } // Relative percentage offer (i.e. a percentage discount). return $this->originalPrice()->multiply($this->offer->percentage / 100)->negative(); }
/** * @return string */ private function byPercentage() : string { $saving = $this->offer->percentage; if ($this->offer->isAbsolute()) { $saving = 100 - $this->offer->percentage; } if ($this->offer->quantity > 1) { return "{$saving}% off when you buy {$this->offer->quantity}"; } return "{$saving}% off"; }
/** * @param int $offerId * @param string $slug * * @throws ModelNotFoundException * * @return View|RedirectResponse */ public function view(int $offerId, string $slug) { /** @var Offer $offer */ $offer = Offer::findOrFail($offerId); if ($offer->slug() !== $slug) { return $this->webUi->redirect('offer.show', [$offerId, $offer->slug()]); } $products = Product::whereHas('offers', function ($query) use($offer) { /* @var Builder $query */ $query->where('id', '=', $offer->id); })->with(Product::standardRelations())->paginate(); return $this->webUi->view('sales::offer.view', compact('offer', 'products')); }