|
@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Facade;
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Str;
|
|
|
-use Packages\Product\Http\Requests\AttributableRequest;
|
|
|
+use Packages\Product\Http\Requests\AttributproductRequest;
|
|
|
use Packages\Product\Http\Requests\AttributeRequest;
|
|
|
use Packages\Product\Models\AttributeProduct;
|
|
|
use Packages\Product\Models\Attribute;
|
|
@@ -200,32 +200,24 @@ class ProductController extends Controller
|
|
|
return redirect()->back();
|
|
|
}
|
|
|
// **************************** ********************
|
|
|
- public function addValAttribute(AttributableRequest $request )
|
|
|
+ public function syncAttribute(AttributProductRequest $request )
|
|
|
{
|
|
|
$productID = $request->productID;
|
|
|
$product = Product::where('id', $productID)->first();
|
|
|
-
|
|
|
+ $attribute_products = AttributeProduct::where('product_id',$request->productID)->get();
|
|
|
+ foreach($attribute_products as $deleteAP){
|
|
|
+ $deleteAP->delete();
|
|
|
+ }
|
|
|
foreach ( $request->val_attribute as $attr_id => $values){
|
|
|
foreach ( $values as $value ){
|
|
|
$data = [
|
|
|
'val_attribute' => $value,
|
|
|
- 'attribute_id'=> $attr_id,
|
|
|
- 'attributable_id' => $request->productID,
|
|
|
- 'attributable_type' => 'Packages\Product\Models\Product',
|
|
|
+ 'attribute_id' => $attr_id,
|
|
|
+ 'product_id' => $request->productID,
|
|
|
];
|
|
|
- $attribute_products = AttributeProduct::where('val_attribute',$value)->where('attribute_id',$attr_id)->first();
|
|
|
-
|
|
|
- if ($attribute_products == false) {
|
|
|
- $attributeProducts = AttributeProduct::create($data);
|
|
|
-// $attribute_products->delete();
|
|
|
- } else {
|
|
|
-
|
|
|
- $attribute_products->update($data);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ $attribute_products = AttributeProduct::create($data);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|