Exemplo n.º 1
0
 /**
  * @param string $code
  * @return Coupon
  * @throws RestException
  */
 private function getCoupon($code)
 {
     try {
         return Coupon::where('code', 'ilike', $code)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         throw new RestException(HTTP_NOT_FOUND, 'Coupon not found', ['coupon' => $code]);
     }
 }
Exemplo n.º 2
0
 public function setCouponIdAttribute($id)
 {
     if ($id == $this->coupon_id) {
         //nothing to do here, let's skip all the queries!
         return;
     }
     $discount = $id ? Coupon::findOrFail($id)->discount : 0;
     foreach ($this->items as $item) {
         $item->setDiscount($discount);
         $item->save();
     }
     $this->attributes['coupon_id'] = $id;
 }