Parcourir la source

Check out the feature appearance form

Azam Rezayi il y a 4 ans
Parent
commit
7d4f7c979f

+ 13 - 127
packages/product/src/Http/Controllers/ProductController.php

@@ -52,7 +52,7 @@ class ProductController extends Controller
 //**************************************************** page create products *****************
     public function create(Request $request)
     {
-        return view('product::product.create');
+        return view('product::product.create',compact('attributes'));
     }
 // *********************************************************save products ******************
     public function store(ProductRequest $request)
@@ -205,72 +205,6 @@ class ProductController extends Controller
             return back();
         }
     }
-//****************upload images in the product************************
-    public function uploadFeature(Request $request)
-    {
-        if ($request->has('featured_image')) {
-            $info = $request->only(['featureDescription', 'featureCaption']);
-            $file = $request->file('featured_image');
-            $type = 'featured_image';
-            $diskName = 'product';
-            $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)) {
-                $fileName = time() . '_' . $fileName;
-            }
-            $draft = Draft::orderBy('id', 'Desc')->get()->first();
-            $upload = $file->storeAs($afterDiskRoot, $fileName, $diskName);
-
-            $uploadData = [
-                'name' => $fileName,
-                'path' => $upload,
-                'mime_type' => $fileMimeType,
-                'extension' => $fileExtension,
-                'parent_type' => 'packages\product',
-                'uploadable_type' => 'Packages\Product\Models\Product',
-                'uploadable_id' => $draft->id,
-                'type' => $type,
-                'descriptionImg' => $info['featureDescription'],
-                'caption' => $info['featureCaption'],
-            ];
-            $uploads = Upload::where('type', $type)->where('uploadable_id', $draft->id)->first();
-            if (empty($uploads)) {
-                $uploaded = Upload::create($uploadData);
-            } else {
-                $uploaded = $uploads->update($uploadData);
-            }
-        }
-    }
-
-
-    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)) {
-            $fileName = time() . '_' . $fileName;
-        }
-
-        $upload = $file->storeAs($afterDiskRoot, $fileName, $diskName);
-        $uploadData = [
-            'name' => $fileName,
-            'path' => $upload,
-            'mime_type' => $fileMimeType,
-            'extension' => $fileExtension,
-            'type' => $type,
-            'descriptionImg' => $info['featureDescription'],
-            'caption' => $info['featureCaption'],
-        ];
-        $uploaded = $product->uploads()->update($uploadData);
-    }
 
 //************************delete image in the product**********************
     public function destroyFile(Upload $upload)
@@ -282,70 +216,22 @@ class ProductController extends Controller
     }
 
 //    ****************************uploadGallery********************
-    public function uploadGallery(Request $request)
-    {
 
-        if ($request->has('gallery_image')) {
-            $files = $request->only('gallery_image', 'captionGallery', 'descriptionGallery');
-            $type = 'gallery_image';
-            $diskName = 'product';
-//           dd($files);
-      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);
+    public function uploadValAttribute(Request $request)
+    {
+        $attributes = Attribute::orderBy('id')->where('use_in_veriation', 1)->get();
+        $product = Product::where('id')->get();
+//dd($request);
 
-            if (File::exists($filePath)) {
-                $fileName = time() . '_' . $fileName;
-            }
-          $draft = Draft::orderBy('id', 'Desc')->get()->first();
-            $upload = $file->storeAs($afterDiskRoot, $fileName, $diskName);
+            $data = [
+                'val_attribute' => $request->val_attribute,
+                'attribute_id' => $attributes->id,
+                'attributable_id' => $product->id,
+                'attributable_type' => 'products',
 
-            $uploadData = [
-                'name' => $fileName,
-                'path' => $upload,
-                'mime_type' => $fileMimeType,
-                'extension' => $fileExtension,
-                'parent_type' => 'packages\product',
-                'uploadable_type' => 'Packages\Product\Models\Product',
-                'uploadable_id' => $draft->id,
-                'type' => $type,
-                'descriptionImg' => $files['descriptionGallery'][$key],
-                'caption' => $files['captionGallery'][$key],
             ];
-//         dd($uploadData);
-//          $uploaded = Upload::where('uploadable_id', $draft->id)->update($uploadData);
-           $uploaded = Upload::create($uploadData);
-          dd($uploaded);
-
+            $uploaded = $product->attributes()->save($data);
+            return redirect(route('productStepVariable'));
         }
-      }
-    }
 
-    public function updateGallery($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)) {
-                $fileName = time() . '_' . $fileName;
-            }
-            $upload = $file->storeAs($afterDiskRoot, $fileName, $diskName);
-            $uploadData = [
-                'name' => $fileName,
-                'path' => $upload,
-                'mime_type' => $fileMimeType,
-                'extension' => $fileExtension,
-                'type' => $type,
-                'descriptionImg' => $files['descriptionGallery'][$key],
-                'caption' => $files['captionGallery'][$key],
-            ];
-            $uploaded = $product->uploads()->update($uploadData);
-        }
-    }
 }

+ 3 - 1
packages/product/src/database/migrations/2020_08_12_070412_create_attributable_table.php

@@ -14,11 +14,13 @@ class CreateAttributableTable extends Migration
     public function up()
     {
         Schema::create('attributable', function (Blueprint $table) {
-            $table->id();
+
             $table->integer('attribute_id');
             $table->integer('attributable_id');
             $table->string('attributable_type');
+            $table->string('val_attribute');
             $table->timestamps();
+            $table->softDeletes();
         });
     }
 

+ 53 - 15
packages/product/src/js/product.js

@@ -1,24 +1,62 @@
 // Add Attribute
 $(document).on('click', '.attribute_creator', function () {
-    let new_select = $('<div>').append( $(".added_attribute:first").append('label.label').clone() );
-    new_select.find('span').remove();
-    new_select.find('select').removeClass();
-    $('div.added_attribute:last').after( new_select.html() );
-    $('div.added_attribute:last').show();
-    $(".added_attribute select").select2({
-        tags: true
-    });
-});
-//add value Attribute
-
-
-
+    var attr = document.getElementById("Show_attributeValue").value;
+    if(attr == $('#Show_selectValue').html()){
+        create = false;
+        swal({
+            title: "مقدار تکراری",
+            text: "این ویژگی از قبل ثبت شده است !!" +
+                "مقدار دیگری را انتخاب کنید.",
+            icon: "warning",
+            // buttons: true,
+            dangerMode: true,
+        })
+    }else {
+        create = true;
+    }
+    document.getElementById("Show_selectValue").innerHTML = attr;
+    if (create == true){
+        let new_select = $('<div>').append( $(".added_attribute:first")
+            .clone());
+        new_select.find('span').remove();
+        new_select.find('select').removeClass();
+        $('div.added_attribute:last').after( new_select.html() );
+        $('div.added_attribute:last').show();
+        $(".added_attribute select").select2({
+            tags: true
+        });
+    }
 
+});
+//*********save attribute by ajax
+$(document).ready(function(){
+    $(".attachment_value_attribute").on('change',function(){
+        var loc = window.location;
+        var base_url = loc.protocol + "//" + loc.hostname + (loc.port? ":"+loc.port : "");
+        for( let i=0; i<$(this).prop('files').length; i++ ){
+            var uploader = $('.attachment_value_attribute[name="val_attribute[]"]');
+            var data = new FormData();
+            uploader.each(function(){
+                data.append('val_attribute[]', $('#val_attribute').val());
+            })
+            data.append('_token', $('[name="csrf-token"]').attr('content'));
+            $.ajax({
+                url:  base_url + "/panel/product_uploads/uploadValAttribute",
+                method: 'POST',
+                data: data,
+                processData: false,
+                contentType: false,
+                success: function(data) {
 
+                }
+            });
+        };
+    });
+});
+//******add product variable
 $(document).on('click', '.variable_creator', function () {
     $(".added_variable:last").after($(".added_variable:last").clone());
-    $("div.added_variable").addClass("added_variable_show");
-
+    $("div.added_variable:last").addClass("added_variable_show");
 });
 
 

+ 1 - 0
packages/product/src/routes/web.php

@@ -23,6 +23,7 @@ Route::group([
     'prefix' => 'panel'
 ], function () {
     Route::resource('attributes', 'AttributeController');
+    Route::post('attributes_uploads/val_attribute', 'ProductController@uploadValAttribute')->name('uploadValAttribute');
 
 });
 

+ 32 - 10
packages/product/src/sass/product.scss

@@ -87,6 +87,17 @@
 .label-tags i {
     cursor: pointer;
 }
+.attr{
+    font-size: large;
+    margin-right: 20px;
+    color: #e80566;
+}
+.font-color{
+    color: #e80566;
+}
+.Attr_item{
+    text-align: center;
+}
 /*    *****************************/
 output span {
     padding: 6px;
@@ -148,19 +159,16 @@ output span {
 }
 .added_attribute {
     display: none;
-    border: 1px solid #752360;
+    border: 2px solid #752360;
     padding: 20px;
     border-radius: 5px;
-    margin: 10px 20px;
+    margin: 10px 0px;
 }  .added_variable{
      display: none;
-    border: 4px solid #752360;
-    padding: 10px;
+    border: 2px solid #752360;
    border-radius: 5px;
- }
-   .c{
        margin: 10px;
-   }
+ }
 .added_attribute_show {
     display: inline !important;
 }
@@ -170,6 +178,20 @@ output span {
 .btn{
     height: 3em ;
 }
-//.AddPad {
-//    padding-top: 8px;
-//}
+.AddPad {
+    padding-top: 8px;
+}
+.swal-footer {
+    text-align: center;
+}
+.attribute {
+    font-size: large;
+    margin-right: 20px;
+    color: #e80566;
+    margin-top: 20px;
+}
+.attribute_style {
+    font-size: large;
+    margin: 30px 20px;
+
+}

+ 0 - 2
packages/product/src/views/attributes/create.blade.php

@@ -44,8 +44,6 @@
                                                 <div class="alert alert-danger">{{$message}}</div>
                                             @enderror
                                         </div>
-
-
                                         <div class="form-group col-lg-6">
                                             <label for="use_in_veriation">{{ __('attribute.use_in_veriation') }}</label>
                                             <select id="use_in_veriation" type="text" class="form-control @error('use_in_veriation') is-invalid @enderror" name="use_in_veriation" value="{{ old('use_in_veriation') }}" autocomplete="use_in_veriation">

+ 19 - 15
packages/product/src/views/product/include/variableAttribute.blade.php → packages/product/src/views/product/include/createAttribute.blade.php

@@ -4,44 +4,48 @@
             <strong>{{ __('انتخاب ویژگی ها') }}</strong>
         </div>
         <div class="card-body mx-lg-6 px-lg-4">
+            <form method="POST" action="{{ route('uploadValAttribute') }}" enctype="multipart/form-data" >
             @csrf
             <div class="form-row ">
-
                 <div class="form-group col-lg-4">
                     <label for="status">{{ __('attribute.titleProduct') }}</label><i class="required">&nbsp; *</i>
-                    <select id="attributes" type="text"
+                    <select id="Show_attributeValue" type="text"
                             class="form-control attributes @error('attributes') is-invalid @enderror"
                             name="attributes" value="{{ old('attributes') }}" autocomplete="attributes">
-
                         @foreach($attributes as $attr_id)
-
-                            <option value="{{$attr_id->id}}">{{$attr_id->title}}</option>
-
+                            <option value="{{$attr_id->title}}">{{$attr_id->title}}</option>
                         @endforeach
                     </select>
                     @error('ReleaseStatus')
-                    <span class="invalid-feedback" role="alert">
-                           <strong>{{ $message }}</strong>
-                    </span>
+                        <span class="invalid-feedback" role="alert">
+                               <strong>{{ $message }}</strong>
+                        </span>
                     @enderror
                 </div>
                 <span class="btn btn-primary btn_create attribute_creator">
-                       <i class="fa fa-plus"></i> {{ __('افزودن ') }}
+                       <i class="fa fa-plus" ></i> {{ __('افزودن ') }}
                 </span>
             </div>
             <div class="form-row">
-                <div class="col-lg-5 added_attribute "  >
-                    <div class="col-lg-6">
-                        <label for="" class="label"></label>
+                <div class=" col-lg-12 added_attribute">
+                    <div class="col-lg-12 ">
+                        <label id="Show_selectValue" class="attr"></label><per class="font-color">:</per>
                     </div>
-                    <select name="" id="" class="js-example-tokenizer" multiple="multiple">
+                    <div class="form-group Attr_item">
+                    <select name="val_attribute[]" id="" class="attr js-example-tokenizer attachment_value_attribute" multiple="multiple">
                         <option value=""></option>
                     </select>
-                    <a href="" class="deleteGallery btn btn-danger pull-left">
+                    <a href="" class="deleteGallery btn btn-danger ">
                         <i class="icon fa fa-close AddPad"></i>
                     </a>
+                    <button type="submit" class="btn btn-success ">
+                        اعمال
+                    </button>
+                    </div>
                 </div>
             </div>
+            </form>
         </div>
+
     </div>
 </div>

+ 1 - 1
packages/product/src/views/product/include/simpleProduct.blade.php

@@ -1,6 +1,6 @@
 <div class="card">
     <div class="card-header">
-        <strong>{{ __('ثبت اطلاعات محصول ساده') }}</strong>&nbsp;<i class="required">{{$product->id}}</i>
+        <strong>{{ __('ثبت اطلاعات محصول ') }}</strong>&nbsp;<i class="required">({{$product->title}})</i>
     </div>
     <div class="card-body mx-lg-6 px-lg-4">
     <div class="form-row ">

+ 0 - 54
packages/product/src/views/product/include/variableAttribute.php

@@ -1,54 +0,0 @@
-<div class="col-lg-12 col-md-12 mx-auto">
-    <div class="card">
-        <div class="card-header">
-            <strong>{{ __('انتخاب ویژگی ها') }}</strong>
-        </div>
-        <div class="card-body mx-lg-6 px-lg-4">
-            @csrf
-            <div class="form-row ">
-                <div class="form-group col-lg-4">
-                    <label for="status">{{ __('attribute.titleProduct') }}</label><i class="required">&nbsp; *</i>
-                    <select id="attributes[]" type="text"
-                            class="form-control select2-simple @error('attributes') is-invalid @enderror"
-                            name="attributes" value="{{ old('attributes') }}" autocomplete="attributes"
-                            multiple="multiple">
-                        <option value="">انتخاب کنید...</option>
-                        @foreach($attributes as $attr_id)
-                            <option value="{{$attr_id->id}}">{{$attr_id->title}}</option>
-                        @endforeach
-                    </select>
-                    @error('ReleaseStatus')
-                    <span class="invalid-feedback" role="alert">
-                           <strong>{{ $message }}</strong>
-                    </span>
-                    @enderror
-                </div>
-                <span class="btn btn-primary btn_create attribute_creator">
-                       <i class="fa fa-plus"></i> {{ __('افزودن ') }}
-                </span>
-            </div>
-            <div class="form-row ">
-                <div class="col-lg-6 added_attribute" id="added_attribute">
-                    <label for="">{{$attr_id->title}}</label>
-                    <select name="states[]" id="" class="js-example-tokenizer" multiple>
-                        <option value="">uyt</option>
-                    </select>
-                    <a href="" class="deleteGallery btn btn-danger pull-left">
-                        <i class="icon fa fa-close AddPad"></i>
-                    </a>
-                </div>
-            </div>
-        </div>
-    </div>
-</div>
-<script>
-    $(document).on('click', '.attribute_creator', function () {
-        $(".added_attribute:last").after($(".added_attribute:last").clone());
-        $("div#added_attribute").addClass("added_attribute_show");
-        selecte2.init(selecte2);
-    });
-</script>
-
-
-
-

+ 89 - 41
packages/product/src/views/product/variableProduct.blade.php

@@ -10,58 +10,106 @@
     @endslot
     @slot('content')
         <div class="auth-background h-auto">
-            @include('product::product.include.variableAttribute')
-        <div class="col-lg-12 col-md-12 mx-auto">
-            <div class="card">
-                <div class="card-header">
-                    <strong>{{ __('ثبت محصول متغییر') }}</strong>&nbsp;<i class="required">{{$product->id}}</i>
-                </div>
-                @component('product::components.message')
-                @endcomponent
-                <div class="card-body mx-lg-6 px-lg-4">
-                    <form method="POST" action="{{ route('products.store',$product->id) }}"
-                          enctype="multipart/form-data">
-                        @csrf
-                        <div class="form-row ">
-                            <div class="col-lg-2">
+            @include('product::product.include.createAttribute')
+            <div class="col-lg-12 col-md-12 mx-auto">
+                <div class="card">
+                    <div class="card-header">
+                        <strong>{{ __('ثبت محصول متغیر') }}</strong>&nbsp;<i class="required">{{$product->title}}</i>
+                    </div>
+                    @component('product::components.message')
+                    @endcomponent
+                    <div class="card-body mx-lg-6 px-lg-4">
+                        <form method="POST" action="{{ route('products.store',$product->id) }}"
+                              enctype="multipart/form-data">
+                            @csrf
+                            <div class="form-row ">
+                                <div class="col-lg-2">
                                 <span class="btn btn-primary btn_create variable_creator">
                                     <i class="fa fa-plus"></i> {{ __('افزودن ') }}
                                 </span>
+                                </div>
                             </div>
-                        </div>
-
-                        <div class="form-row container">
-                            <div class="col-lg-12 added_variable">
-                                <label for="" class="col-lg-12">tyui</label>
-                                <select type="text" class="col-lg-2 c">
-                                    <option value="">{{$product->id}}</option>
-                                </select>
-                                <select type="text" class="col-lg-2 c">
-                                    <option value="">{{$product->id}}</option>
-                                </select>
-                                <select type="text" class="col-lg-2 c">
-                                    <option value="">{{$product->id}}</option>
-                                </select>
-                                <select type="text" class="col-lg-2 c">
-                                    <option value="">{{$product->id}}</option>
-                                </select>
-                                @include('product::product.include.simpleProduct')
+                            <div class="form-row ">
+                                <div class="col-lg-12 added_variable">
+                                    <div><label for="" class="label attribute">ویژگی ها</label></div>
+                                    <div class="form-row attribute_style">
+                                        <div class="form-group col-lg-3">
+                                            <label for="slug">  {{ __('product.slug') }}</label>
+                                            <input id="slug" type="text" class="form-control @error('slug') is-invalid @enderror" name="slug"  value="{{$product->slug}}" autocomplete="slug" autofocus>
+                                            @error('slug')
+                                                <span class="invalid-feedback" role="alert">
+                                                        <strong>{{ $message }}</strong>
+                                                </span>
+                                            @enderror
+                                        </div>
+                                        <div class="form-group col-lg-3">
+                                            <label for="slug">  {{ __('product.slug') }}</label>
+                                            <input id="slug" type="text" class="form-control @error('slug') is-invalid @enderror" name="slug"  value="{{$product->slug}}" autocomplete="slug" autofocus>
+                                            @error('slug')
+                                                <span class="invalid-feedback" role="alert">
+                                                        <strong>{{ $message }}</strong>
+                                                </span>
+                                            @enderror
+                                        </div>
+                                        <div class="form-group col-lg-3">
+                                            <label for="slug">  {{ __('product.slug') }}</label>
+                                            <input id="slug" type="text" class="form-control @error('slug') is-invalid @enderror" name="slug"  value="{{$product->slug}}" autocomplete="slug" autofocus>
+                                            @error('slug')
+                                                <span class="invalid-feedback" role="alert">
+                                                    <strong>{{ $message }}</strong>
+                                                </span>
+                                            @enderror
+                                        </div>
+                                        <div class="form-group col-lg-3">
+                                            <label for="ReleaseStatus">{{ __('product.Country') }}</label><i
+                                                class="required"> *</i>
+                                            <select id="ReleaseStatus" type="text"
+                                                    class="form-control @error('ReleaseStatus') is-invalid @enderror"
+                                                    name="ReleaseStatus" autocomplete="ReleaseStatus">
+                                                <option value="draft"
+                                                        @if($product->ReleaseStatus==='پیشنویس') selected='selected' @endif>
+                                                    پیشنویس
+                                                </option>
+                                                <option value="pending"
+                                                        @if($product->ReleaseStatus==='در انتظار انتشار') selected='selected' @endif>
+                                                    در انتظار انتشار
+                                                </option>
+                                                <option value="published"
+                                                        @if($product->ReleaseStatus==='منتشر شده') selected='selected' @endif>
+                                                    منتشر شده
+                                                </option>
+                                            </select>
+                                            @error('ReleaseStatus')
+                                            <span class="invalid-feedback" role="alert">
+                                                <strong>{{ $message }}</strong>
+                                            </span>
+                                            @enderror
+                                        </div>
+                                    </div>
+                                    <div class="attribute_style">
+                                        @include('product::product.include.simpleProduct')
+                                    </div>
+                                    <div class="form-group col-lg-6">
+                                        <label for="slug">  {{ __('product.title') }}</label>
+                                        <input id="slug" type="text" class="form-control @error('slug') is-invalid @enderror" name="slug"  value="{{$product->slug}}" autocomplete="slug" autofocus>
+                                        @error('slug')
+                                            <span class="invalid-feedback" role="alert">
+                                                <strong>{{ $message }}</strong>
+                                            </span>
+                                        @enderror
+                                    </div>
+                                </div>
                             </div>
-                        </div>
-
-                    </form>
-                </div>
-                <div class="card-footer">
+                        </form>
+                    </div>
+                    <div class="card-footer">
+                    </div>
                 </div>
             </div>
         </div>
-        </div>
-
     @endslot
-
     @slot('script')
 
     @endslot
-
 @endcomponent
 

+ 1 - 0
resources/lang/fa/product.php

@@ -14,5 +14,6 @@ return [
   'gallery_images'       => 'ساخت گالری',
   'featured_image'       => 'تصویر شاخص',
   'titleVariable'       => 'محصول متغیر',
+  'Country'       => 'کشور سازنده',
 ];