Exemplo n.º 1
0
 public function deleteOffer($id)
 {
     $offer = Offers::where('id', $id)->first();
     $offer->delete();
     return redirect('admin/offers/all');
 }
Exemplo n.º 2
0
 public function editOffer(request $request)
 {
     $input = $request->only('store_id', 'offer_id');
     if (!$this->checkUserHasStore($input['store_id'], true)) {
         return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403);
     }
     $matchThese = ['id' => $input['offer_id'], 'store_id' => $input['store_id']];
     $offer = Offers::where($matchThese)->first();
     if (empty($offer)) {
         return response()->json(['response_code' => 'RES_OU', 'messages' => 'Offer Updated']);
     }
     foreach ($request->except('offer_id', 'store_id', 'api_key') as $key => $value) {
         $offer->{$key} = $value;
     }
     $offer->save();
     return response()->json(['response_code' => 'RES_OU', 'messages' => 'Offer Updated']);
 }
Exemplo n.º 3
0
 public function editOffer(request $request)
 {
     $rules = array('offer_id' => 'required', 'title' => 'required', 'fineprint' => 'required', 'startDate' => 'required', 'endDate' => 'required');
     $Validator = $this->customValidator($request->all(), $rules, array());
     if ($Validator->fails()) {
         return response()->json(['response_code' => 'ERR_RULES', 'messages' => $Validator->errors()->all()], 400);
     }
     $matchThese = ['id' => $request->input('offer_id'), 'is_child' => false];
     $offer = Offers::where($matchThese)->first();
     if (empty($offer)) {
         return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403);
     }
     if (!$this->checkUserHasStorePermission($offer->store_id)) {
         // checking if offer can be editable by logged in store
         return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403);
     }
     foreach ($request->only('title', 'fineprint', 'startDate', 'endDate') as $key => $value) {
         $offer->{$key} = $value;
     }
     $offer->save();
     if ($offer->is_parent && $this->checkIfStoreIsParent($offer->store_id)) {
         //edit all child offer if above conditions are satisfied
         $matchThese = ['is_child' => true, 'parent_id' => $offer->id];
         Offers::where($matchThese)->update($request->only('title', 'fineprint', 'startDate', 'endDate'));
         //updating all offers
     }
     return response()->json(['response_code' => 'RES_OU', 'messages' => 'Offer Updated']);
 }
Exemplo n.º 4
0
 public function editOffer(request $request)
 {
     $validator = Validator::make($request->all(), ['offer_id' => 'required', 'title' => 'required', 'startDate' => 'required', 'endDate' => 'required', 'fineprint' => 'required']);
     if ($validator->fails()) {
         return response()->json(['status' => 'fail', 'message' => $validator->errors()->all()]);
     }
     $matchThese = ['id' => $request->input('offer_id'), 'is_child' => false];
     // child offers are not editable by child merchants
     $offer = Offers::where($matchThese)->first();
     if (empty($offer)) {
         return response()->json(['status' => 'fail', 'message' => 'Not Authorized']);
     }
     if (!$this->checkUserHasStorePermission($offer->store_id)) {
         // checking if offer can be editable by logged in store
         return response()->json(['status' => 'fail', 'message' => 'Not Authorized']);
     }
     $fineprintArr = explode("\n", $request->input('fineprint'));
     $fineprint = '';
     foreach ($fineprintArr as $value) {
         if ($value != '' || !empty($value)) {
             $fineprint .= '<li>' . $value . '</li>';
         }
     }
     $updateValues = $request->only('title', 'startDate', 'endDate');
     $updateValues['fineprint'] = $fineprint;
     foreach ($updateValues as $key => $value) {
         $offer->{$key} = $value;
     }
     $offer->save();
     // if offer is parent and store editing this also parent update all child offers
     if ($offer->is_parent && $this->checkIfStoreIsParent($offer->store_id)) {
         $matchThese = ['is_child' => true, 'parent_id' => $offer->id];
         Offers::where($matchThese)->update($updateValues);
     }
     return response()->json(['status' => 'success', 'data' => $offer]);
 }