Esempio n. 1
0
 /**
  * @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');
 }
Esempio n. 2
0
 /**
  * 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'));
 }
Esempio n. 3
0
 /**
  * @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();
 }
Esempio n. 4
0
 /**
  * @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";
 }
Esempio n. 5
0
 /**
  * @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'));
 }