Beispiel #1
0
 public function addToCart($deal_id)
 {
     $amount = 1;
     if ($amount <= 0) {
         throw new BadRequestHttpException('QUALITY_MUST_GREATER_THAN_0');
     }
     $deal = Deal::find($deal_id);
     if ($deal == null) {
         throw new NotFoundException('NOT_FOUND');
     }
     if ($deal->stock < $amount) {
         throw new BadRequestHttpException('OUT_OF_STOCK');
     }
     if ($deal->time_expired < Carbon::now()) {
         throw new BadRequestHttpException('EXPIRED');
     }
     // --- Check if deal is existed in cart
     $deal_cart = \Cart::get($deal_id);
     if ($deal_cart == null) {
         \Cart::add(['id' => $deal->id, 'name' => $deal->name, 'quantity' => $amount, 'price' => $deal->deal_price, 'attributes' => ['list_price' => $deal->list_price, 'time_expired' => $deal->time_expired, 'thumb' => $deal->getThumb()]]);
     } else {
         \Cart::update($deal_id, ['quantity' => $amount]);
     }
     return redirect('/gio-hang');
 }