|
@@ -21,13 +21,10 @@ use App\Models\Category;
|
|
|
use App\Models\Upload;
|
|
|
use phpDocumentor\Reflection\Types\Compound;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
class ProductController extends Controller
|
|
|
{
|
|
|
public function __construct()
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// *******************************************show page product ************
|
|
@@ -57,23 +54,23 @@ class ProductController extends Controller
|
|
|
public function create(Request $request)
|
|
|
{
|
|
|
$categories = Category::orderBy('parent_id')->where('parent_id', 0)->get();
|
|
|
- if( !$request->has('draft_id') ){
|
|
|
+ if (!$request->has('draft_id')) {
|
|
|
$draft = new Draft();
|
|
|
$draft->object_type = 'Packages\Product';
|
|
|
$draft->save();
|
|
|
- return redirect()->route('products.create',['draft_id' => $draft->id]);
|
|
|
- }
|
|
|
- else{
|
|
|
- $draft = Draft::find( $request->draft_id );
|
|
|
- if( is_null( $draft ) ){
|
|
|
- return redirect()->route( 'products.create');
|
|
|
+ return redirect()->route('products.create', ['draft_id' => $draft->id]);
|
|
|
+ } else {
|
|
|
+ $draft = Draft::find($request->draft_id);
|
|
|
+ if (is_null($draft)) {
|
|
|
+ return redirect()->route('products.create');
|
|
|
}
|
|
|
}
|
|
|
$args = [
|
|
|
- 'draft' => $draft
|
|
|
+ 'draft' => $draft
|
|
|
];
|
|
|
- return view( 'product::product.create',$args, compact('categories')) ;
|
|
|
+ return view('product::product.create', $args, compact('categories'));
|
|
|
}
|
|
|
+
|
|
|
// *********************************************************save products ******************
|
|
|
public function store(ProductRequest $request)
|
|
|
{
|
|
@@ -82,13 +79,13 @@ class ProductController extends Controller
|
|
|
'sale_price' => preg_replace('/[^0-9]+/', '', $request->sale_price),
|
|
|
]);
|
|
|
|
|
|
- if( !$request->has('draft_id') ){
|
|
|
+ if (!$request->has('draft_id')) {
|
|
|
return abort(403, 'دسترسی به این صفحه ممکن نیست ؛ لطفا مجددا تلاش کنید.');
|
|
|
}
|
|
|
- $draft = Draft::findOrFail( $request->draft_id );
|
|
|
+ $draft = Draft::findOrFail($request->draft_id);
|
|
|
$data = [
|
|
|
'title' => $request->title,
|
|
|
- 'slug' => $request->slug,
|
|
|
+ 'slug' => $request->slug,
|
|
|
'sku' => $request->sku,
|
|
|
'ReleaseStatus' => $request->ReleaseStatus,
|
|
|
'price' => $request->price,
|
|
@@ -100,7 +97,7 @@ class ProductController extends Controller
|
|
|
];
|
|
|
// if( $draft->attachments->count() == 0 ){
|
|
|
// return redirect()->back()
|
|
|
-// ->withErrors( ['error_message' => 'نامه باید حداقل یک ضمیمه داشته باشد.'] )
|
|
|
+// ->withErrors( ['error_message' => 'حتما باید یک فایل آپلود شود.'] )
|
|
|
// ->withInput( $request->all() );
|
|
|
// }
|
|
|
// dd($draft->attachments);
|
|
@@ -117,7 +114,6 @@ class ProductController extends Controller
|
|
|
$diskName = 'product';
|
|
|
$this->uploadGallery($file, $diskName, $product, $type);
|
|
|
}
|
|
|
-
|
|
|
if ($request->has('featured_image')) {
|
|
|
$info = $request->only(['featureDescription', 'featureCaption']);
|
|
|
$file = $request->file('featured_image');
|
|
@@ -125,10 +121,10 @@ class ProductController extends Controller
|
|
|
$diskName = 'product';
|
|
|
$this->uploadFeature($file, $diskName, $product, $type, $info);
|
|
|
}
|
|
|
-
|
|
|
$msg = 'ذخیره محصول با موفقیت انجام شد ';
|
|
|
return redirect(route('products.edit', $product->id))->with('success', $msg);
|
|
|
}
|
|
|
+
|
|
|
// ******************************************************edit page product*********************************************
|
|
|
public function edit(Product $product)
|
|
|
{
|
|
@@ -137,15 +133,12 @@ class ProductController extends Controller
|
|
|
}
|
|
|
|
|
|
// *******************************************update page product*****************************************
|
|
|
-
|
|
|
public function update(ProductRequestEdit $request, Product $product)
|
|
|
{
|
|
|
-
|
|
|
$request->merge([
|
|
|
'price' => preg_replace('/[^0-9]+/', '', $request->price),
|
|
|
'sale_price' => preg_replace('/[^0-9]+/', '', $request->sale_price),
|
|
|
]);
|
|
|
-// 'categories' => $request->categories,
|
|
|
$data = [
|
|
|
'title' => $request->title,
|
|
|
'slug' => $request->slug,
|
|
@@ -157,17 +150,14 @@ class ProductController extends Controller
|
|
|
'status' => $request->status,
|
|
|
'discription' => $request->discription,
|
|
|
'creator_id' => auth()->user()->id,
|
|
|
-
|
|
|
];
|
|
|
$product->update($data);
|
|
|
-
|
|
|
$product->categories()->sync($request->categories);
|
|
|
if ($request->has('gallery_image')) {
|
|
|
$file = $request->only('gallery_image', 'captionGallery', 'descriptionGallery');
|
|
|
$type = 'gallery_image';
|
|
|
$diskName = 'product';
|
|
|
$this->updateGallery($file, $diskName, $product, $type);
|
|
|
-
|
|
|
}
|
|
|
if ($request->has('featured_image')) {
|
|
|
$info = $request->only(['featureDescription', 'featureCaption']);
|
|
@@ -175,37 +165,28 @@ class ProductController extends Controller
|
|
|
$type = 'featured_image';
|
|
|
$diskName = 'product';
|
|
|
$this->uploadFeature($file, $diskName, $product, $type, $info);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
$msg = 'ویرایش محصول با موفقیت انجام شد ';
|
|
|
-
|
|
|
return redirect(route('products.index'))->with('success', $msg);
|
|
|
}
|
|
|
|
|
|
//***************************** delete products*****************************************
|
|
|
-
|
|
|
public function destroy(Product $product)
|
|
|
{
|
|
|
-
|
|
|
$product->delete();
|
|
|
{
|
|
|
return back();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//****************upload images in the product************************
|
|
|
- public function uploadFeature($file, $diskName, $product, $type,$info)
|
|
|
+ public function uploadFeature($file, $diskName, $product, $type, $info)
|
|
|
{
|
|
|
-
|
|
|
$fileExtension = $file->getClientOriginalExtension();
|
|
|
-
|
|
|
$fileMimeType = $file->getMimeType();
|
|
|
-
|
|
|
$afterDiskRoot = '/' . jdate()->format('Y') . '/' . jdate()->format('m');
|
|
|
-
|
|
|
$fileName = jdate(time())->format('Ymd') . '_' . $file->getClientOriginalName();
|
|
|
-
|
|
|
$filePath = storage_path('app/public/' . $diskName . $afterDiskRoot . '/' . $fileName);
|
|
|
|
|
|
if (File::exists($filePath)) {
|
|
@@ -213,36 +194,26 @@ class ProductController extends Controller
|
|
|
}
|
|
|
|
|
|
$upload = $file->storeAs($afterDiskRoot, $fileName, $diskName);
|
|
|
-
|
|
|
-
|
|
|
$uploadData = [
|
|
|
'name' => $fileName,
|
|
|
'path' => $upload,
|
|
|
'mime_type' => $fileMimeType,
|
|
|
'extension' => $fileExtension,
|
|
|
- 'type' => $type,
|
|
|
+ 'type' => $type,
|
|
|
'descriptionImg' => $info['featureDescription'],
|
|
|
'caption' => $info['featureCaption'],
|
|
|
-
|
|
|
-
|
|
|
];
|
|
|
|
|
|
-
|
|
|
$uploaded = $product->uploads()->create($uploadData);
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- public function updateFeature($file, $diskName, $product, $type,$info)
|
|
|
+ public function updateFeature($file, $diskName, $product, $type, $info)
|
|
|
{
|
|
|
$fileExtension = $file->getClientOriginalExtension();
|
|
|
-
|
|
|
$fileMimeType = $file->getMimeType();
|
|
|
-
|
|
|
$afterDiskRoot = '/' . jdate()->format('Y') . '/' . jdate()->format('m');
|
|
|
-
|
|
|
$fileName = jdate(time())->format('Ymd') . '_' . $file->getClientOriginalName();
|
|
|
-
|
|
|
$filePath = storage_path('app/public/' . $diskName . $afterDiskRoot . '/' . $fileName);
|
|
|
|
|
|
if (File::exists($filePath)) {
|
|
@@ -262,25 +233,23 @@ class ProductController extends Controller
|
|
|
$uploaded = $product->uploads()->update($uploadData);
|
|
|
}
|
|
|
|
|
|
-//************************delete image in th product**********************
|
|
|
+//************************delete image in the product**********************
|
|
|
public function destroyFile(Upload $upload)
|
|
|
{
|
|
|
$upload->delete();
|
|
|
$msg = 'حذف عکس محصول با موفقیت انجام شد ';
|
|
|
- session()->flash('image_deleted',$msg);
|
|
|
+ session()->flash('image_deleted', $msg);
|
|
|
return redirect()->back();
|
|
|
}
|
|
|
+
|
|
|
+// ****************************uploadGallery********************
|
|
|
public function uploadGallery($files, $diskName, $product, $type)
|
|
|
{
|
|
|
foreach ($files['gallery_image'] as $key => $file) {
|
|
|
$fileExtension = $file->getClientOriginalExtension();
|
|
|
-
|
|
|
$fileMimeType = $file->getMimeType();
|
|
|
-
|
|
|
$afterDiskRoot = '/' . jdate()->format('Y') . '/' . jdate()->format('m');
|
|
|
-
|
|
|
$fileName = jdate(time())->format('Ymd') . '_' . $file->getClientOriginalName();
|
|
|
-
|
|
|
$filePath = storage_path('app/public/' . $diskName . $afterDiskRoot . '/' . $fileName);
|
|
|
|
|
|
if (File::exists($filePath)) {
|
|
@@ -296,13 +265,10 @@ class ProductController extends Controller
|
|
|
'descriptionImg' => $files['descriptionGallery'][$key],
|
|
|
'caption' => $files['captionGallery'][$key],
|
|
|
];
|
|
|
-
|
|
|
$uploaded = $product->uploads()->create($uploadData);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public function updateGallery($files, $diskName, $product, $type)
|
|
|
{
|
|
|
foreach ($files['gallery_image'] as $key => $file) {
|
|
@@ -327,22 +293,4 @@ class ProductController extends Controller
|
|
|
$uploaded = $product->uploads()->update($uploadData);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// public function SaveFormProductByAjax(Request $request)
|
|
|
-// {
|
|
|
-// $title = $this->input->post('title');
|
|
|
-// $price = $this->input->post('price');
|
|
|
-// $slug = $this->input->post('slug');
|
|
|
-// $type= $this->input->post('type');
|
|
|
-// $ReleaseStatus = $this->input->post('ReleaseStatus');
|
|
|
-// $status = $this->input->post('status');
|
|
|
-// $discription = $this->input->post('discription');
|
|
|
-// $categories = $this->input->post('categories');
|
|
|
-// $featured_image = $this->input->post('featured_image');
|
|
|
-//
|
|
|
-// $data=array('title' => $title,"price" => $price,"slug" => $slug,"type" => $type,"status" => $status,"discription" => $discription,"categories" => $categories,"featured_image" => $featured_image,"ReleaseStatus" => $ReleaseStatus);
|
|
|
-// $prouduct = Product::update($data);
|
|
|
-// return $prouduct->with('success', 'اطلاعات با موفقیت ثبت شد .') ;
|
|
|
-//
|
|
|
-// }
|
|
|
}
|