public function postVendorRegister(Request $request) { try { $validator = $this->validator($request->all()); if ($validator->fails()) { $this->throwValidationException($request, $validator); } DB::beginTransaction(); // Create User first $user = $this->create($request->all(), config('app.role_vendor')); // Now validate / create vendor profile $data = $request->all(); $vendorValidator = $this->vendorValidator($data); if ($vendorValidator->fails()) { $this->throwValidationException($request, $vendorValidator); } // Attempt to upload the images $uploader = new UploadHandler(); if ($request->hasFile('logo_image_path') && $request->file('logo_image_path')->isValid() && $uploader->isImage($request->file('logo_image_path'))) { $newFilename = $uploader->uploadVendorAsset($request->file('logo_image_path')); $data['logo_image_path'] = $newFilename; } if ($request->hasFile('background_image_path') && $request->file('background_image_path')->isValid() && $uploader->isImage($request->file('background_image_path'))) { $newFilename = $uploader->uploadVendorAsset($request->file('background_image_path')); $data['background_image_path'] = $newFilename; } $vendor = $this->createVendor($user->id, $data); DB::commit(); \Auth::login($user); } catch (\Exception $ex) { DB::rollBack(); throw $ex; } // Send an email to us to notify of new vendor registration try { $mailData = ['to' => config('app.vendor_registration_notify_email'), 'from' => $user->email, 'subject' => 'Vendor ' . $user->email . ' has registered', 'body' => 'Vendor sign up: Email:' . $user->email . ', Company Name: ' . $vendor->company_name, 'sendRaw' => true]; $this->dispatch(new SendEmail($mailData)); } catch (\Exception $ex) { // If email fails do not stop registration from happening } return redirect($this->redirectPath()); }
public function editProduct(Request $request) { $productId = $request->input('id'); $vendorId = \Session::get(config('app.session_key_vendor')); $action = $request->input('action'); if (isset($vendorId)) { $uploader = new UploadHandler(); if ($action === 'DELETE') { $product = $this->dataAccess->getProductByIdVendor($productId, $vendorId, ['product_image']); if (isset($product)) { $uploader->removeProductAsset($product->product_image); $rowsAffected = $this->dataAccess->deleteProduct($productId, $vendorId); return redirect('/product/vendor'); } } else { // Now validate user product $productValidator = $this->productValidator($request->all()); if ($productValidator->fails()) { $this->throwValidationException($request, $productValidator); } $data = $request->all(); if (is_null($request->input('allergens'))) { $data['allergens'] = array(); } try { // Upload product file if present if ($request->hasFile('product_image') && $request->file('product_image')->isValid() && $uploader->isImage($request->file('product_image'))) { $newFilename = $uploader->uploadProductAsset($request->file('product_image')); $data['product_image'] = $newFilename; } $product = $this->dataAccess->upsertProduct($productId, $vendorId, $data); // Update categories // Update cache entry $this->updateProductCache($product, 'UPDATE'); return redirect('product/detail/' . $product->id)->with('successMessage', trans('messages.product_update_success')); } catch (\Exception $ex) { // Clean up uploaded image if needed if (isset($data['product_image'])) { $uploader->removeProductAsset($newFilename); } } } } return redirect('/'); }