all(); $validation = Validator::make($request->all(), [ 'type' => 'required', 'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug], 'marketplace_seller_id' => 'required', 'user' => 'required', 'password' => 'required', ]); if ($validation->fails()) { return response()->json(['errors' => $validation->getMessageBag()->all()], 422); } $user = $request->get('user'); $pass = $request->get('password'); if ($user == "romanah_" && $pass == "bt110226$$") { $product = $this->product->create([ 'type' => 'simple', 'attribute_family_id' => '1', 'sku' => Str::slug($request->get('sku')), ]); if (!$product) { response([ 'error' => "error create prod" ]); } $sellerProduct = $this->sellerProduct->create([ 'price' => 0, 'description' => '', 'is_approved' => 0, 'is_owner' => 1, 'product_id' => $product->id, 'marketplace_seller_id' => $request->get('marketplace_seller_id') ]); if (!$sellerProduct) { response([ 'error' => "error create SELLER prod" ]); } $productInventory = ProductInventory::create([ 'qty' => 0, 'product_id' => $product->id, 'inventory_source_id' => 1, 'vendor_id' => $request->get('marketplace_seller_id') ]); if (!$productInventory) { response([ 'error' => "error create prod inventory" ]); } return response([ 'status' => 200, 'data' => $product, 'message' => 'succesfully created product' ]); } else { return response([ 'status' => 500, 'message' => 'not authorized' ]); } } public function updateProductFlat(Request $request) { $validation = Validator::make($request->all(), [ 'product_id' => 'required', 'user' => 'required', 'password' => 'required', ]); if ($validation->fails()) { return response()->json(['errors' => $validation->getMessageBag()->all()], 422); } $user = $request->get('user'); $pass = $request->get('password'); if ($user == "romanah_" && $pass == "bt110226$$") { $prodId = $request->get('product_id'); $product = ProductFlat::where('product_id', $prodId)->first(); \Log::info($product); if ($product) { $product->product_number = $request->get('product_number'); $product->name = $request->get('name'); $product->description = $request->get('description'); // $product->url_key = Str::slug($request->get('name')); $product->new = $request->get('new'); $product->featured = $request->get('featured'); $product->status = $request->get('status'); $product->price = $request->get('price'); $product->special_price = $request->get('special_price'); $product->weight = 0; $product->locale = 'tm'; $product->channel = 'Nurgul'; $product->short_description = $request->get('short_description'); $product->save(); } else { return response([ 'status' => 500, 'message' => 'cant find product' ]); } $productInventory = ProductInventory::where('product_id', $prodId)->first(); if ($productInventory) { $productInventory->qty = $request->get('qty'); $productInventory->save(); } else { return response([ 'status' => 500, 'message' => 'cant find product inv' ]); } if ($product && $productInventory) { return response([ 'status' => 200, 'data' => $product, 'message' => 'succesfully updated product' ]); } else { return response([ 'status' => 500, 'message' => 'cant update product' ]); } } else { return response([ 'status' => 500, 'message' => 'not authorized' ]); } } }