diff --git a/packages/Sarga/API/Http/Controllers/Vendors.php b/packages/Sarga/API/Http/Controllers/Vendors.php index 4ee091195..8d41c5718 100644 --- a/packages/Sarga/API/Http/Controllers/Vendors.php +++ b/packages/Sarga/API/Http/Controllers/Vendors.php @@ -2,10 +2,13 @@ namespace Sarga\API\Http\Controllers; +use Sarga\API\Http\Resources\Catalog\Brand; use Sarga\API\Http\Resources\Catalog\Product as ProductResource; use Sarga\API\Http\Resources\Core\Vendor; use Sarga\API\Repositories\ProductRepository; +use Sarga\Brand\Repositories\BrandRepository; use Sarga\Shop\Repositories\CategoryRepository; +use Sarga\Shop\Repositories\VendorRepository; use Webkul\API\Http\Controllers\Shop\Controller; use Webkul\Marketplace\Repositories\SellerRepository; use Webkul\Product\Repositories\ProductFlatRepository; @@ -15,15 +18,12 @@ class Vendors extends Controller protected $vendorRepository; protected $categoryRepository; - protected $productRepository; - public function __construct(SellerRepository $sellerRepository, - ProductRepository $productRepository, + public function __construct(VendorRepository $sellerRepository, CategoryRepository $categoryRepository) { $this->vendorRepository = $sellerRepository; $this->categoryRepository = $categoryRepository; - $this->productRepository = $productRepository; } public function index() @@ -58,7 +58,14 @@ class Vendors extends Controller return Vendor::collection($vendors); } - public function vendor_products($vendor_id){ - return ProductResource::collection($this->productRepository->findAllBySeller($vendor_id,request()->input('category_id'))); + public function products(ProductRepository $productRepository,$seller_id){ + $products = $productRepository->findAllBySeller($seller_id,request()->input('category_id')); + + return ProductResource::collection($products); + } + + public function brands(BrandRepository $brandRepository, $seller_id){ + + return Brand::collection($brandRepository->findAllBySeller($seller_id)); } } \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Catalog/Brand.php b/packages/Sarga/API/Http/Resources/Catalog/Brand.php new file mode 100644 index 000000000..7aabc46f4 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Catalog/Brand.php @@ -0,0 +1,25 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'image_url' => $this->image_url, + 'postion' => $this->position, + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/routes.php b/packages/Sarga/API/Http/routes.php index aab750e58..21e14954b 100644 --- a/packages/Sarga/API/Http/routes.php +++ b/packages/Sarga/API/Http/routes.php @@ -21,7 +21,8 @@ Route::group(['prefix' => 'api'], function ($router) { //Vendors Route::get('vendors',[Vendors::class,'index'])->name('api.vendors'); - Route::get('vendor/products/{vendor_id}',[Vendors::class,'vendor_products'])->name('api.vendor.products'); + Route::get('vendor/products/{vendor_id}',[Vendors::class,'products'])->name('api.vendor.products'); + Route::get('vendor/brands/{vendor_id}',[Vendors::class,'brands'])->name('api.vendor.brands'); //category routes diff --git a/packages/Sarga/Brand/src/Repositories/BrandRepository.php b/packages/Sarga/Brand/src/Repositories/BrandRepository.php index a9880f1c4..eaad6c1f2 100644 --- a/packages/Sarga/Brand/src/Repositories/BrandRepository.php +++ b/packages/Sarga/Brand/src/Repositories/BrandRepository.php @@ -77,4 +77,22 @@ class BrandRepository extends Repository public function actives(){ return $this->findByField('status',1); } + + public function findAllBySeller($seller_id){ + $query = $this->leftJoin('seller_brands as sb','sb.brand_id','=','brands.id') + ->where('sb.seller_id',$seller_id); + + if(request()->has('category_id')){ + $query->leftJoin('category_brands as cb','cb.brand_id','=','brands.id') + ->where('cb.category_id',request()->get('category_id')); + } + + $limit = request()->get('limit') ?? 10; + $page = request()->get('page') ?? 1; + + return $query->orderBy('position', 'ASC') + ->skip(($page-1) * $limit) + ->take($limit) + ->get(); + } } \ No newline at end of file diff --git a/packages/Sarga/Shop/src/Models/Vendor.php b/packages/Sarga/Shop/src/Models/Vendor.php index 1e8ab4902..27a7b92ea 100644 --- a/packages/Sarga/Shop/src/Models/Vendor.php +++ b/packages/Sarga/Shop/src/Models/Vendor.php @@ -2,6 +2,7 @@ namespace Sarga\Shop\Models; +use Sarga\Brand\Models\BrandProxy; use Webkul\Category\Models\CategoryProxy; use Webkul\Marketplace\Models\Seller; use Webkul\Marketplace\Models\SellerCategory; @@ -9,7 +10,12 @@ use Webkul\Marketplace\Models\SellerCategoryProxy; class Vendor extends Seller { - public function categories(){ + public function categories() + { return $this->hasOne(SellerCategoryProxy::modelClass(),'seller_id',); } + + public function brands(){ + return $this->belongsToMany(BrandProxy::modelClass(),'seller_brands','seller_id'); + } } \ No newline at end of file diff --git a/packages/Sarga/Shop/src/Repositories/VendorRepository.php b/packages/Sarga/Shop/src/Repositories/VendorRepository.php new file mode 100644 index 000000000..89531fc45 --- /dev/null +++ b/packages/Sarga/Shop/src/Repositories/VendorRepository.php @@ -0,0 +1,20 @@ +