product scrap create vendor add

This commit is contained in:
merdan 2022-01-19 13:32:04 +05:00
parent edf20abe9f
commit e8df3fe871
5 changed files with 58 additions and 9 deletions

View File

@ -7,13 +7,16 @@ use Illuminate\Support\Facades\Validator;
use Webkul\API\Http\Controllers\Shop\Controller;
use Webkul\Core\Contracts\Validations\Slug;
use Sarga\API\Repositories\ProductRepository;
use Webkul\Marketplace\Repositories\SellerRepository;
class IntegrationController extends Controller
{
protected $productRepository;
protected $sellerRepository;
public function __construct(ProductRepository $productRepository)
public function __construct(ProductRepository $productRepository, SellerRepository $sellerRepository)
{
$this->sellerRepository = $sellerRepository;
$this->productRepository = $productRepository;
}
@ -55,20 +58,25 @@ class IntegrationController extends Controller
}
$validation = Validator::make($data, [
// 'category' => 'required',
'category' => 'required',
'product_code' => ['required', 'unique:products,sku', new Slug],
'images' => 'required',
'name' => 'required',
'url_key'=> 'required',
'price' => 'required',
'vendor' => 'required'
]);
if ($validation->fails()) {
return response()->json(['errors'=>$validation->getMessageBag()->all()],422);
}
if($id = $this->productRepository->create($data)){
return response()->json(['success'=>true,'product_id' => $id]);
if($product = $this->productRepository->create($data)){
$seller = $this->sellerRepository->findOneByField('shop_title',$data['vendor']);
if($seller){
$sellerProduct = $this->productRepository->createSellerProduct($product, $seller->id);
}
return response()->json(['success'=>true,'product_id' => $product->id]);
}else{
return response()->json(['success'=>false]);
}

View File

@ -34,6 +34,19 @@ class Products extends ProductController
);
}
/**
* Returns product's additional information.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function configurableConfig($id)
{
$product = $this->productRepository->findOrFail($id);
return response()->json([
'data' => app('Webkul\Product\Helpers\ConfigurableOption')->getConfigurationConfig($this->productRepository->findOrFail($id)),
]);
}
}

View File

@ -66,9 +66,9 @@ class Product extends JsonResource
$this->merge($this->specialPriceInfo()),
/* super attributes */
$this->mergeWhen($productTypeInstance->isComposite(), [
'super_attributes' => Attribute::collection($product->super_attributes),
]),
// $this->mergeWhen($productTypeInstance->isComposite(), [
// 'super_attributes' => Attribute::collection($product->super_attributes),
// ]),
];
}

View File

@ -162,7 +162,7 @@ class ProductRepository extends WProductRepository
Event::dispatch('catalog.product.create.after', $parentProduct);
DB::commit();
return $parentProduct->id;
return $parentProduct;
}
catch(\Exception $ex){
DB::rollBack();
@ -172,6 +172,34 @@ class ProductRepository extends WProductRepository
}
public function createSellerProduct($product, $seller_id){
Event::dispatch('marketplace.catalog.product.create.before');
$sellerProduct = parent::create([
'marketplace_seller_id' => $seller_id,
'is_approved' => 1,
'condition' => 'new',
'description' => 'scraped product',
'is_owner' => 1,
'product_id' => $product->id,
]);
foreach ($sellerProduct->product->variants as $baseVariant) {
parent::create([
'parent_id' => $sellerProduct->id,
'product_id' => $baseVariant->id,
'is_owner' => 1,
'marketplace_seller_id' => $seller_id,
'is_approved' => 1,
'condition' => 'new',
]);
}
Event::dispatch('marketplace.catalog.product.create.after', $sellerProduct);
return $sellerProduct;
}
private function assignImages($product,$images){
foreach($images as $image){
$this->imageRepository->create([

View File

@ -32,7 +32,7 @@
<div class="product-information" style="display: inline-flex;">
<div class="product-image">
<img src="{{ asset($product->product->base_image_url ?? 'vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png') }} }}" style="width: 300px; height: 350px;"/>
<img src="{{ asset($product->product->base_image_url ?? 'vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png') }}" style="width: 300px; height: 350px;"/>
</div>
<div class="product-details" style="padding-left: 20px;">