소스 검색

test value select attriute

Azam Rezayi 4 년 전
부모
커밋
d7f92a8339

+ 10 - 6
packages/product/src/Http/Controllers/ProductController.php

@@ -95,14 +95,20 @@ class ProductController extends Controller
 
     public function productStepVariable(Request $request, $id)
     {
-        $attributes = Attribute::orderBy('id')->where('use_in_veriation', 1)->get();
+//
 
-//        $attributables = \DB::table('attributables')->where('val_attribute', true)->get();
-//        dd($attributables->val_attribute);
+        $attributeTitle = AttributeProduct::query()->select('attribute_id')->where('product_id',$id)->groupBy('attribute_id')->get();
+        $attributes = Attribute::orderBy('id')->where('use_in_veriation', 1)->get();
+        $attributeProduct = AttributeProduct::orderBy('id')->where('product_id',$id)->get();
+        $productID = $request->productID;
+        $product = Product::where('id', $productID)->first();
+        $attribute_products = AttributeProduct::where('product_id',$request->productID)->get();
+//       dd($attributeProduct);
+//dd($attribute_products);
         $product = $this->productChecker($id);
         if ($product != false){
             $msg = 'ذخیره محصول با موفقیت انجام شد ';
-            return view('product::product.variableProduct', compact('product', 'attributes'))->with('success', $msg);
+            return view('product::product.variableProduct', compact('product', 'attributes', 'attributeProduct', 'attributeTitle','attribute_products'))->with('success', $msg);
         }else{
             return abort(419);
         }
@@ -120,7 +126,6 @@ class ProductController extends Controller
                 'status' => 'required',
                 'price' => 'required',
                 'sale_price' => 'required',
-
             ]);
             /**
              * update product
@@ -219,5 +224,4 @@ class ProductController extends Controller
            }
         }
     }
-
 }

+ 2 - 2
packages/product/src/Models/Attribute.php

@@ -9,9 +9,9 @@ class Attribute extends Model
     use SoftDeletes;
     protected $table = 'attributes';
     protected $fillable=['title', 'key', 'use_in_veriation'];
-    public function products()
+    public function attributeProducts()
     {
-        return $this->morphedByMany(Product::class, 'attributable')->withPivot(['val_attribute']);
+        return $this->belongsToMany(AttributeProduct::class);
     }
     public function getUseInVeriationAttribute($value)
     {

+ 11 - 14
packages/product/src/Models/AttributeProduct.php

@@ -9,21 +9,18 @@ class AttributeProduct extends Model
     public $timestamps = false;
     protected $table = 'attribute_products';
     protected $fillable = ['attribute_id', 'product_id', 'val_attribute'];
-//    public static function sync_attr(array $attributes = [])
-//    {
-//        $changes_attribute_products = new static($attributes);
-//        if (!$changes_attribute_products ){
-//            $changes_attribute_products->save();
-//
-//        }else {
-//            $changes_attribute_products->delete();
-//            $changes_attribute_products->update();
-////
-//        }
+    public function attribute()
+    {
+//        $attr = Attribute::query()->where('id', $this->attribute_id)->get()->pluck('title');
+//        return $this->hasOne(Attribute::class, 'attribute_id', 'id');
+        $attr = $this->hasOne(Attribute::class, 'id','attribute_id');
+        return $attr;
+    }
+    public function product()
+    {
+        return $this->belongsToMany(Product::class);
 
-
-//        return $changes_attribute_products;
-//    }
+    }
 
 }
 

+ 3 - 3
packages/product/src/Models/Product.php

@@ -22,10 +22,10 @@ class Product extends Model
     {
         return $this->morphToMany(Category::class, 'categorizable');
     }
-    public function attributes()
-    {
-        return $this->morphToMany(Attribute::class, 'attributable');
 
+    public function attributeProduct()
+    {
+        return $this->belongsToMany(AttributeProduct::class);
     }
     public function uploads()
     {

+ 8 - 0
packages/product/src/js/product.js

@@ -71,3 +71,11 @@ $(document).on('click', '.variable_creator', function () {
     $("div.added_variable:last").show();
 });
 
+
+function refreshSelect() {
+    $('div.select-container').fadeOut();
+    $('div.select-container').load(url, function() {
+        $('div.select-container').fadeIn();
+    });
+}
+

+ 2 - 2
packages/product/src/views/product/include/createAttribute.blade.php

@@ -33,8 +33,8 @@
                     <div class="form-group Attr_item">
 {{--                        <input type="hidden" name="attributeID" id="productID" value="{{ $attributes->id }}">--}}
 {{--                        <input name="val_attribute[]" id="" class="attr js-example-tokenizer saveItemAttribute" multiple="multiple">--}}
-                    <select name="val_attribute[]" id="" class="val_attributes_all attr js-example-tokenizer " multiple="multiple">
-                        <option value=""></option>
+                    <select name="val_attribute[]" id="" class="val_attributes_all attr js-example-tokenizer " multiple="multiple" >
+                        <option value="{{$attribute_products}}"></option>
                     </select>
                     <a href="" class="deleteGallery btn btn-danger ">
                         <i class="icon fa fa-close AddPad"></i>

+ 56 - 0
packages/product/src/views/product/include/firstProduct.blade.php

@@ -0,0 +1,56 @@
+<div class="p-2">
+<input type="hidden" value="{{$product->id}}" name="product_id">
+<div class="form-group">
+    <label for="title">{{ __('product.title') }}</label><i class="required">&nbsp;*</i>
+    <input id="title" type="text" class="form-control @error('title') is-invalid @enderror" name="title"
+           value="{{$product->title}}" autocomplete="title" autofocus>
+    @error('title')
+    <span class="invalid-feedback" role="alert">
+        <strong>{{ $message }}</strong>
+     </span>
+    @enderror
+</div>
+<div class="form-row ">
+    <div class="form-group col-lg-6">
+        <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-6">
+    <label for="ReleaseStatus">{{ __('product.ReleaseStatus') }}</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>
+    <label for="discription">{{ __('product.discription') }}</label><i class="required">&nbsp;*</i>
+    <textarea id="discription" type="text" class="form-control editor @error('discription') is-invalid @enderror" name="discription" autocomplete="discription">
+        {{$product->discription}}
+    </textarea>
+    @error('discription')
+    <span class="invalid-feedback" role="alert">
+        <strong>{{ $message }}</strong>
+    </span>
+    @enderror
+</div>
+</div>
+
+
+
+

+ 1 - 58
packages/product/src/views/product/simpleEditProduct.blade.php

@@ -27,64 +27,7 @@
                                 @endcomponent
                                 <form method="POST" action="{{ route('saveProductStepThree') }}" enctype="multipart/form-data" >
                                     @csrf
-                                    <input type="hidden" value="{{$product->id}}" name="product_id">
-                                    <div class="form-group">
-                                        <label for="title">{{ __('product.title') }}</label><i class="required">&nbsp;*</i>
-                                        <input id="title" type="text"class="form-control @error('title') is-invalid @enderror"name="title" value="{{$product->title}}" autocomplete="title" autofocus>
-                                        @error('title')
-                                        <span class="invalid-feedback" role="alert">
-                                                <strong>{{ $message }}</strong>
-                                            </span>
-                                        @enderror
-                                    </div>
-                                    <div class="form-row ">
-                                        <div class="form-group col-lg-6">
-                                            <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-6">
-                                            <label for="ReleaseStatus">{{ __('product.ReleaseStatus') }}</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="form-group">
-                                            <label for="discription">{{ __('product.discription') }}</label><i class="required">&nbsp;*</i>
-                                            <textarea id="discription" type="text" class="form-control editor @error('discription') is-invalid @enderror" name="discription" autocomplete="discription">
-                                            {{$product->discription}}
-                                        </textarea>
-                                            @error('discription')
-                                            <span class="invalid-feedback" role="alert">
-                                                <strong>{{ $message }}</strong>
-                                            </span>
-                                            @enderror
-                                        </div>
+                                    @include('product::product.include.firstProduct')
                                     @include('product::product.include.simpleProduct')
                                     <div class="form-group mb-0">
                                         <div class="">

+ 22 - 15
packages/product/src/views/product/variableProduct.blade.php

@@ -30,25 +30,32 @@
                                 </div>
                             </div>
                             <div class="form-row ">
+
                                 <div class="col-lg-12 added_variable">
+                                    @include('product::product.include.firstProduct')
                                     <div><label for="" class="label attribute">ویژگی ها</label></div>
                                     <div class="form-row attribute_style">
-
-{{--                                        @foreach ($attributables as $item)--}}
-{{--                                            {{dd($attributables)}}--}}
-{{--                                            <div class="form-group col-lg-3">--}}
-{{--                                                <label for="slug">{{$item->attribute_id}}</label>--}}
-{{--                                                <select id="slug" type="text" class="form-control @error('slug') is-invalid @enderror" name="slug"  value="{{$item->val_attribute}}" autocomplete="slug" autofocus>--}}
-{{--                                                     <option value="{{$item->val_attribute}}"></option>--}}
-{{--                                                </select>--}}
-{{--                                                @error('slug')--}}
-{{--                                                <span class="invalid-feedback" role="alert">--}}
-{{--                                                        <strong>{{ $message }}</strong>--}}
-{{--                                                </span>--}}
-{{--                                                @enderror--}}
-{{--                                            </div>--}}
-{{--                                        @endforeach--}}
+                                            <div class="form-group col-lg-3">
+                                                <div class="col-lg-12 ">
+                                                    @foreach($attributeTitle as $productTitle)
+                                                        <label for="slug">
+                                                            {{ $productTitle->attribute()->first()->title }}
+                                                        </label>
+                                                        <select id="slug" type="text" class="form-control @error('slug') is-invalid @enderror" name="slug"  value="" autocomplete="slug" autofocus>
+                                                            @foreach($attributeProduct as $attrVal)
+                                                                <option value="{{$attrVal->id}}">{{$attrVal->val_attribute}}</option>
+                                                            @endforeach
+                                                        </select>
+                                                    @endforeach
+                                                </div>
+                                                @error('slug')
+                                                <span class="invalid-feedback" role="alert">
+                                                        <strong>{{ $message }}</strong>
+                                                </span>
+                                                @enderror
+                                            </div>
                                     </div>
+
                                     <div class="attribute_style">
                                         @include('product::product.include.simpleProduct')
                                     </div>