| @@ -33,10 +33,17 @@ | ||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function viewDetails(Request $request, $id) |
| 36 | 36 | { |
| 37 | + $coupon = CouponResource::viewDetails($id); | |
| 37 | 38 | |
| 38 | - return ['coupon' => CouponResource::viewDetails($id)]; | |
| 39 | + if (!$coupon) { | |
| 40 | + return CouponResource::makeErrorResponse([ | |
| 41 | + ['code' => 404, 'message' => __('Coupon not found, please reload the page and try again!', 'fluent-cart')] | |
| 42 | + ], 404); | |
| 43 | + } | |
| 44 | + | |
| 45 | + return ['coupon' => $coupon]; | |
| 39 | 46 | } |
| 40 | 47 | |
| 41 | 48 | public function create(CouponRequest $request) |
| 42 | 49 | { |
| @@ -174,12 +181,13 @@ | ||
| 174 | 181 | |
| 175 | 182 | public function reapplyCoupon(Request $request) |
| 176 | 183 | { |
| 177 | 184 | $data = $request->getSafe([ |
| 178 | - 'order_uuid' => 'sanitize_text_field', | |
| 185 | + 'order_uuid' => 'sanitize_text_field', | |
| 179 | 186 | 'applied_coupons.*' => 'intval', |
| 180 | - 'order_items.*' => 'sanitize_text_field', | |
| 187 | + 'customer_email' => 'sanitize_email', | |
| 181 | 188 | ]); |
| 189 | + $data['order_items'] = Arr::except(Arr::get($request->all(), 'order_items', []), ['*']); | |
| 182 | 190 | |
| 183 | 191 | $isApplied = CouponResource::reapplyCoupon($data); |
| 184 | 192 | |
| 185 | 193 | if (is_wp_error($isApplied)) { |
| @@ -198,9 +206,9 @@ | ||
| 198 | 206 | { |
| 199 | 207 | $productId = Arr::get($request->all(), 'productId', null); |
| 200 | 208 | $appliedCoupons = Arr::get($request->all(), 'appliedCoupons', []); |
| 201 | 209 | $origin = Arr::get($request->all(), 'origin', null); |
| 202 | - $checkEligibility = CouponResource::checkProductEligibility($productId, $appliedCoupons, $origin); | |
| 210 | + $checkEligibility = CouponResource::checkProductEligibilityForCodes($productId, $appliedCoupons, $origin); | |
| 203 | 211 | return $checkEligibility; |
| 204 | 212 | } |
| 205 | 213 | |
| 206 | 214 | public function storeCouponSettings(Request $request) |