2023-08-25 09:54:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Sarga\API\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use Sarga\API\Http\Resources\Customer\CustomerResource;
|
|
|
|
|
use Webkul\Customer\Repositories\CustomerAddressRepository;
|
|
|
|
|
use Webkul\Customer\Repositories\CustomerGroupRepository;
|
|
|
|
|
use Webkul\Customer\Repositories\CustomerRepository;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Webkul\Marketplace\Http\Controllers\Shop\Account\ProductController as SellerProductController;
|
|
|
|
|
use Webkul\Product\Models\ProductFlat;
|
|
|
|
|
use Webkul\Product\Models\ProductInventory;
|
|
|
|
|
|
|
|
|
|
class SellerProduct extends SellerProductController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* SellerRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var Object
|
|
|
|
|
*/
|
|
|
|
|
protected $sellerRepository;
|
|
|
|
|
/**
|
|
|
|
|
* Method to store user's sign up form data to DB.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function storeSellerProd(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$data = $request->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"
|
|
|
|
|
]);
|
|
|
|
|
}
|
2023-08-25 11:04:39 +00:00
|
|
|
|
|
|
|
|
return response([
|
|
|
|
|
'status' => 200,
|
|
|
|
|
'data' => $product,
|
|
|
|
|
'message' => 'succesfully created product'
|
|
|
|
|
]);
|
2023-08-25 09:54:48 +00:00
|
|
|
} else {
|
|
|
|
|
return response([
|
|
|
|
|
'status' => 500,
|
|
|
|
|
'message' => 'not authorized'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-25 11:04:39 +00:00
|
|
|
|
2023-08-25 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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('id', $prodId)->first();
|
|
|
|
|
|
2023-08-25 11:15:30 +00:00
|
|
|
//$product->product_number = $request->get('product_number');
|
2023-08-25 09:54:48 +00:00
|
|
|
$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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|