|
@@ -94,19 +94,19 @@ class ProductController extends Controller
|
|
|
public function productStepVariable(Request $request, $id)
|
|
|
{
|
|
|
$attributes = Attribute::orderBy('id')->where('use_in_veriation', 1)->get();
|
|
|
-// $attributes = Attribute::query()->where('id', $request->id)->where('use_in_veriation', 1)->first();
|
|
|
+
|
|
|
+ $attributables = \DB::table('attributables')->where('val_attribute', true)->get();
|
|
|
+// dd($attributables->val_attribute);
|
|
|
$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', 'attributables'))->with('success', $msg);
|
|
|
}else{
|
|
|
return abort(419);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
public function productStepThree(Request $request)
|
|
|
{
|
|
|
-// dd($request->all());
|
|
|
$product = $this->productChecker($request->product_id);
|
|
|
if ($product != false){
|
|
|
$request->validate([
|
|
@@ -141,7 +141,6 @@ class ProductController extends Controller
|
|
|
return abort(419);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
public function productChecker($id)
|
|
|
{
|
|
|
$product = Product::where('id', $id)->where('creator_id', Auth::user()->id)->first();
|
|
@@ -153,7 +152,6 @@ class ProductController extends Controller
|
|
|
}
|
|
|
// ******************************************************edit page product*********************************************
|
|
|
public function edit(Product $product)
|
|
|
-
|
|
|
{
|
|
|
$categories = Category::orderBy('id', 'DESC')->get();
|
|
|
return view('product::product.edit', compact('product', 'categories'));
|
|
@@ -178,27 +176,11 @@ class ProductController extends Controller
|
|
|
'discription' => $request->discription,
|
|
|
'creator_id' => auth()->user()->id,
|
|
|
];
|
|
|
-
|
|
|
-
|
|
|
- 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']);
|
|
|
- $file = $request->file('featured_image');
|
|
|
- $type = 'featured_image';
|
|
|
- $diskName = 'product';
|
|
|
- $this->updateFeature($file, $diskName, $product, $type, $info);
|
|
|
- }
|
|
|
$product->update($data);
|
|
|
$product->categories()->sync($request->categories);
|
|
|
$msg = 'ویرایش محصول با موفقیت انجام شد ';
|
|
|
return redirect(route('products.index'))->with('success', $msg);
|
|
|
}
|
|
|
-
|
|
|
//***************************** delete products*****************************************
|
|
|
public function destroy(Product $product)
|
|
|
{
|
|
@@ -207,7 +189,6 @@ class ProductController extends Controller
|
|
|
return back();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//************************delete image in the product**********************
|
|
|
public function destroyFile(Upload $upload)
|
|
|
{
|
|
@@ -216,39 +197,50 @@ class ProductController extends Controller
|
|
|
session()->flash('image_deleted', $msg);
|
|
|
return redirect()->back();
|
|
|
}
|
|
|
-
|
|
|
// ****************************uploadGallery********************
|
|
|
-
|
|
|
public function uploadValAttribute(Request $request)
|
|
|
{
|
|
|
-// $attributes = Attribute::orderBy('id')->where('use_in_veriation', 1)->get();
|
|
|
$productID = $request->productID;
|
|
|
$product = Product::where('id', $productID)->first();
|
|
|
- $info = json_decode($request->info);
|
|
|
- $type = json_decode($request->type);
|
|
|
- $attributables = $product->attributes()->where($info,'val_attribute');
|
|
|
-// dd($attributables);
|
|
|
- dd($type);
|
|
|
- if (($attributables)){
|
|
|
- foreach ($info as $item){
|
|
|
- $data = [
|
|
|
- 'val_attribute' => $item,
|
|
|
- 'attribute_id' => $type,
|
|
|
- 'attributable_id' => $productID,
|
|
|
- 'attributable_type' => 'products',
|
|
|
- 'created_at' => Carbon::now(),
|
|
|
- 'updated_at' => Carbon::now(),
|
|
|
- ];
|
|
|
+ $attributes = [];
|
|
|
+ foreach ( $request->val_attribute as $attr_id => $values ){
|
|
|
+ $attributes[$attr_id] = ['val_attribute' => $values];
|
|
|
|
|
|
- \DB::table('attributables')->insert($data);
|
|
|
- }
|
|
|
- $operate['status'] = 200;
|
|
|
- $operate['msg'] = 'با موفقیت ذخیره شد !';
|
|
|
- }else{
|
|
|
- $operate['status'] = 500;
|
|
|
- $operate['msg'] = 'اطلاعات قبلا ذخیره شده';
|
|
|
- }
|
|
|
- return $operate;
|
|
|
}
|
|
|
+// dd( $attributes );
|
|
|
+ $product->attributes()->sync( $attributes );
|
|
|
+ dd( $attributes );
|
|
|
+ foreach ( $request->val_attribute as $attr_id => $values ){
|
|
|
+ $values = array_values( $values );
|
|
|
+ echo $attr_id . ' ';
|
|
|
+ var_dump( $values );
|
|
|
+ echo "<hr>";
|
|
|
|
|
|
+ }
|
|
|
+ dd();
|
|
|
+ $product->attributes()->sync($request->val_attribute);
|
|
|
+ dd(1);
|
|
|
+
|
|
|
+// if ((!$attributables->attribute_id='attribute_id' && !$attributables->attributable_id='attributable_id')){
|
|
|
+// foreach ($info as $item){
|
|
|
+// $data = [
|
|
|
+// 'val_attribute' => $item,
|
|
|
+// 'attribute_id' => $type,
|
|
|
+// 'attributable_id' => $productID,
|
|
|
+// 'attributable_type' => 'products',
|
|
|
+// 'created_at' => Carbon::now(),
|
|
|
+// 'updated_at' => Carbon::now(),
|
|
|
+// ];
|
|
|
+//
|
|
|
+// \DB::table('attributables')->insert($data);
|
|
|
+// }
|
|
|
+// $operate['status'] = 200;
|
|
|
+// $operate['msg'] = 'با موفقیت ذخیره شد !';
|
|
|
+// }else{
|
|
|
+// $operate['status'] = 500;
|
|
|
+// $operate['msg'] = 'اطلاعات قبلا ذخیره شده';
|
|
|
+// }
|
|
|
+// return $operate;
|
|
|
+// }
|
|
|
+ }
|
|
|
}
|