scraper controller
This commit is contained in:
parent
c4f2ba491b
commit
607aed02a5
|
|
@ -2,11 +2,23 @@
|
|||
|
||||
namespace Sarga\API\Http\Controllers;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Webkul\API\Http\Controllers\Shop\Controller;
|
||||
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
|
||||
use Webkul\Core\Contracts\Validations\Slug;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
|
||||
class IntegrationController extends Controller
|
||||
{
|
||||
protected $productRepository;
|
||||
protected $attributeFamilyRepository;
|
||||
|
||||
public function __construct(ProductRepository $productRepository, AttributeFamilyRepository $attributeFamilyRepository)
|
||||
{
|
||||
$this->productRepository = $productRepository;
|
||||
$this->attributeFamilyRepository = $attributeFamilyRepository;
|
||||
}
|
||||
|
||||
public function store(){
|
||||
if(!request()->has('product')){
|
||||
return response()->json(['status' =>false, 'message' => 'bad request'],405);
|
||||
|
|
@ -34,4 +46,44 @@ class IntegrationController extends Controller
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public function create(){
|
||||
|
||||
$data = json_decode(request()->getContent(),true);
|
||||
|
||||
$validation = Validator::make($data, [
|
||||
'type' => 'required',
|
||||
'category' => 'required',
|
||||
'sku' => ['required', 'unique:products,sku', new Slug],
|
||||
'images' => 'required',
|
||||
'name' => 'required',
|
||||
'url_key'=> 'required',
|
||||
'price' => 'required',
|
||||
]);
|
||||
|
||||
if ($validation->fails()) {
|
||||
return response()->json($validation->getMessageBag()->all());
|
||||
}
|
||||
|
||||
$product['sku'] = $data['sku'];
|
||||
|
||||
//todo test here add some attributes,families
|
||||
$product['attribute_family_id'] = $this->getAttributeFamily(array_keys($data['attributes']));
|
||||
|
||||
$product['super_attributes']= [];
|
||||
|
||||
$product['type'] = ($data->color_variants != null || $data->size_variants != null) ? 'configurable':'simple';
|
||||
|
||||
//$this->productRepository->create($product);
|
||||
|
||||
}
|
||||
|
||||
//find attribute family
|
||||
private function getAttributeFamily($attrubetCodes){
|
||||
if($attrubetCodes)
|
||||
return $this->attributeFamilyRepository->whereHas('custom_attributes',function ($query) use ($attrubetCodes){
|
||||
$query->whereIn('attributes.code', $attrubetCodes);
|
||||
},'=',count($attrubetCodes))->first()->id ?? 1;
|
||||
return 1; //default attribute family
|
||||
}
|
||||
}
|
||||
|
|
@ -36,5 +36,6 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
|
||||
Route::group(['prefix' => 'scrap','middleware' =>['scrap']], function ($router){
|
||||
Route::put('upload',[IntegrationController::class,'bulk_upload']);
|
||||
Route::put('create',[IntegrationController::class,'create']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Webkul\Product\Http\Controllers;
|
|||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
|
||||
use Webkul\Category\Repositories\CategoryRepository;
|
||||
|
|
@ -183,6 +184,7 @@ class ProductController extends Controller
|
|||
'sku' => ['required', 'unique:products,sku', new Slug],
|
||||
]);
|
||||
|
||||
Log::info(request());
|
||||
$product = $this->productRepository->create(request()->all());
|
||||
|
||||
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Product']));
|
||||
|
|
|
|||
Loading…
Reference in New Issue