From 296f09d424c3edfe0d7f6971413038cad5672686 Mon Sep 17 00:00:00 2001 From: merdiano Date: Wed, 29 Dec 2021 08:05:55 +0500 Subject: [PATCH] vendor categories --- .env.example | 71 -------- config/ignition.php | 2 +- .../Sarga/API/Http/Controllers/Vendors.php | 5 +- .../Http/Resources/Catalog/SellerCategory.php | 23 +++ .../Sarga/API/Http/Resources/Core/Vendor.php | 3 +- .../src/DataGrids/SellerCategoryDataGrid.php | 105 +++++++++++ ..._212834_update_seller_categories_table.php | 31 ++++ .../views/sellers/category/create.blade.php | 64 +++++++ .../views/sellers/category/edit.blade.php | 63 +++++++ .../views/sellers/category/index.blade.php | 28 +++ .../Sarga/Admin/src/Routes/catalog-routes.php | 15 ++ .../Webkul/Marketplace/src/Models/Seller.php | 4 + .../src/Repositories/InvoiceRepository.php | 170 +++++++++++------- .../src/Http/Controllers/Shop/Controller.php | 8 +- .../Http/Controllers/Shop/ShopController.php | 85 ++++----- 15 files changed, 480 insertions(+), 197 deletions(-) delete mode 100644 .env.example create mode 100644 packages/Sarga/API/Http/Resources/Catalog/SellerCategory.php create mode 100644 packages/Sarga/Admin/src/DataGrids/SellerCategoryDataGrid.php create mode 100644 packages/Sarga/Admin/src/Database/Migrations/2021_12_29_212834_update_seller_categories_table.php create mode 100644 packages/Sarga/Admin/src/Resources/views/sellers/category/create.blade.php create mode 100644 packages/Sarga/Admin/src/Resources/views/sellers/category/edit.blade.php create mode 100644 packages/Sarga/Admin/src/Resources/views/sellers/category/index.blade.php diff --git a/.env.example b/.env.example deleted file mode 100644 index b94ee3f20..000000000 --- a/.env.example +++ /dev/null @@ -1,71 +0,0 @@ -APP_NAME=Bagisto -APP_ENV=local -APP_VERSION=1.3.3 -APP_KEY= -APP_DEBUG=true -APP_URL=http://localhost -APP_ADMIN_URL=admin -APP_TIMEZONE=Asia/Kolkata -APP_LOCALE=en -LOG_CHANNEL=stack -APP_CURRENCY=USD - -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE= -DB_USERNAME= -DB_PASSWORD= -DB_PREFIX= - -BROADCAST_DRIVER=log -CACHE_DRIVER=file -SESSION_DRIVER=file -SESSION_LIFETIME=120 -QUEUE_DRIVER=sync - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_DRIVER=smtp -MAIL_HOST=smtp.mailtrap.io -MAIL_PORT=2525 -MAIL_USERNAME= -MAIL_PASSWORD= -MAIL_ENCRYPTION=tls - -SHOP_MAIL_FROM= -ADMIN_MAIL_TO= -MAIL_FROM_NAME= - -FIXER_API_KEY= -EXCHANGE_RATES_API_KEY= - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_APP_CLUSTER=mt1 - -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" - -FACEBOOK_CLIENT_ID= -FACEBOOK_CLIENT_SECRET= -FACEBOOK_CALLBACK_URL=https://yourhost.com/customer/social-login/facebook/callback - -TWITTER_CLIENT_ID= -TWITTER_CLIENT_SECRET= -TWITTER_CALLBACK_URL=https://yourhost.com/customer/social-login/twitter/callback - -GOOGLE_CLIENT_ID= -GOOGLE_CLIENT_SECRET= -GOOGLE_CALLBACK_URL=https://yourhost.com/customer/social-login/google/callback - -LINKEDIN_CLIENT_ID= -LINKEDIN_CLIENT_SECRET= -LINKEDIN_CALLBACK_URL=https://yourhost.com/customer/social-login/linkedin/callback - -GITHUB_CLIENT_ID= -GITHUB_CLIENT_SECRET= -GITHUB_CALLBACK_URL=https://yourhost.com/customer/social-login/github/callback diff --git a/config/ignition.php b/config/ignition.php index b46542319..268d2f233 100644 --- a/config/ignition.php +++ b/config/ignition.php @@ -28,7 +28,7 @@ return [ | */ - 'theme' => env('IGNITION_THEME', 'dark'), + 'theme' => env('IGNITION_THEME', 'light'), /* |-------------------------------------------------------------------------- diff --git a/packages/Sarga/API/Http/Controllers/Vendors.php b/packages/Sarga/API/Http/Controllers/Vendors.php index 6643b338a..942ea7859 100644 --- a/packages/Sarga/API/Http/Controllers/Vendors.php +++ b/packages/Sarga/API/Http/Controllers/Vendors.php @@ -18,9 +18,10 @@ class Vendors extends Controller public function index() { - $vendors = $this->vendorRepository->select('marketplace_sellers.id','url','logo','banner','shop_title','categories') + $vendors = $this->vendorRepository->select('marketplace_sellers.id','url','logo','banner','shop_title') ->where('is_approved',true) - ->leftJoin('seller_categories','marketplace_sellers.id','=','seller_categories.seller_id') + ->with(['categories:seller_id,type,categories']) +// ->leftJoin('seller_categories','marketplace_sellers.id','=','seller_categories.seller_id') ->get(); return Vendor::collection($vendors); diff --git a/packages/Sarga/API/Http/Resources/Catalog/SellerCategory.php b/packages/Sarga/API/Http/Resources/Catalog/SellerCategory.php new file mode 100644 index 000000000..9f3580350 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Catalog/SellerCategory.php @@ -0,0 +1,23 @@ + $this->type, + 'ids' => json_decode($this->categories) + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Core/Vendor.php b/packages/Sarga/API/Http/Resources/Core/Vendor.php index 11844fc4d..9d65873ed 100644 --- a/packages/Sarga/API/Http/Resources/Core/Vendor.php +++ b/packages/Sarga/API/Http/Resources/Core/Vendor.php @@ -3,6 +3,7 @@ namespace Sarga\API\Http\Resources\Core; use Illuminate\Http\Resources\Json\JsonResource; +use Sarga\API\Http\Resources\Catalog\SellerCategory; class Vendor extends JsonResource { @@ -20,7 +21,7 @@ class Vendor extends JsonResource 'shop_title' => $this->shop_title, 'logo' => $this->logo_url, 'banner' => $this->banner_url, - 'categories' => json_decode($this->categories), + 'categories' => SellerCategory::collection($this->categories), ]; } } \ No newline at end of file diff --git a/packages/Sarga/Admin/src/DataGrids/SellerCategoryDataGrid.php b/packages/Sarga/Admin/src/DataGrids/SellerCategoryDataGrid.php new file mode 100644 index 000000000..cca66e5df --- /dev/null +++ b/packages/Sarga/Admin/src/DataGrids/SellerCategoryDataGrid.php @@ -0,0 +1,105 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ +class SellerCategoryDataGrid extends DataGrid +{ + /** + * + * @var integer + */ + public $index = 'id'; + + protected $sortOrder = 'desc'; //asc or desc + + protected $enableFilterMap = true; + + public function prepareQueryBuilder() + { + $queryBuilder = DB::table('seller_categories') + ->leftJoin('marketplace_sellers', 'seller_categories.seller_id', 'marketplace_sellers.id') + ->leftJoin('customers', 'marketplace_sellers.customer_id', 'customers.id') + + ->select(DB::raw('CONCAT(customers.first_name, " ", customers.last_name) as name'), + 'seller_categories.categories', + 'seller_categories.id', + 'seller_categories.type' + ); + + $this->addFilter('customer_name', DB::raw('CONCAT(customers.first_name, " ", customers.last_name)')); + + + $this->setQueryBuilder($queryBuilder); + } + + public function addColumns() + { + $this->addColumn([ + 'index' => 'id', + 'label' => trans('marketplace::app.admin.sellers.id'), + 'type' => 'number', + 'searchable' => false, + 'sortable' => true, + 'filterable' => true + ]); + + $this->addColumn([ + 'index' => 'name', + 'label' => trans('marketplace::app.admin.flag.name'), + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'filterable' => true + ]); + + $this->addColumn([ + 'index' => 'type', + 'label' => 'Type', + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'filterable' => true + ]); + + } + + public function prepareActions() + { + $this->addAction([ + 'type' => 'edit', + 'method' => 'GET', + 'route' => 'admin.marketplace.seller.category.edit', + 'icon' => 'icon pencil-lg-icon', + 'title' => '' + ], true); + + $this->addAction([ + 'type' => 'Delete', + 'method' => 'delete', + 'route' => 'admin.marketplace.seller.category.delete', + 'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'product']), + 'icon' => 'icon trash-icon', + 'title' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'product']) + ], true); + } + + public function prepareMassActions() + { + $this->addMassAction([ + 'type' => 'delete', + 'label' => trans('marketplace::app.admin.sellers.delete'), + 'action' => route('admin.marketplace.sellers.massdelete'), + 'method' => 'POST', + 'title' => '' + ], true) ; + } +} \ No newline at end of file diff --git a/packages/Sarga/Admin/src/Database/Migrations/2021_12_29_212834_update_seller_categories_table.php b/packages/Sarga/Admin/src/Database/Migrations/2021_12_29_212834_update_seller_categories_table.php new file mode 100644 index 000000000..61f055be6 --- /dev/null +++ b/packages/Sarga/Admin/src/Database/Migrations/2021_12_29_212834_update_seller_categories_table.php @@ -0,0 +1,31 @@ +string('type')->nullable(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('seller_categories', function (Blueprint $table) { + $table->dropColumn('type'); + }); + } +} diff --git a/packages/Sarga/Admin/src/Resources/views/sellers/category/create.blade.php b/packages/Sarga/Admin/src/Resources/views/sellers/category/create.blade.php new file mode 100644 index 000000000..322d93d01 --- /dev/null +++ b/packages/Sarga/Admin/src/Resources/views/sellers/category/create.blade.php @@ -0,0 +1,64 @@ +@extends('admin::layouts.content') + +@section('page_title') + {{ __('marketplace::app.admin.sellers.category.add-title') }} +@stop + +@section('content') +
+
+ + + +
+ +
+ @csrf() + +
+ + + + @{{ errors.first('seller_id') }} +
+
+ + +
+ + @if ($categories->count()) + + + @endif +
+
+
+
+@stop \ No newline at end of file diff --git a/packages/Sarga/Admin/src/Resources/views/sellers/category/edit.blade.php b/packages/Sarga/Admin/src/Resources/views/sellers/category/edit.blade.php new file mode 100644 index 000000000..01cc5b615 --- /dev/null +++ b/packages/Sarga/Admin/src/Resources/views/sellers/category/edit.blade.php @@ -0,0 +1,63 @@ +@extends('admin::layouts.content') + +@section('page_title') + {{ __('marketplace::app.admin.sellers.category.edit-title') }} +@stop + +@section('content') +
+
+ + + +
+ +
+ @csrf() + +
+ + + + @{{ errors.first('seller_id') }} +
+
+ + +
+ @if ($categories->count()) + + + @endif +
+
+
+
+@stop \ No newline at end of file diff --git a/packages/Sarga/Admin/src/Resources/views/sellers/category/index.blade.php b/packages/Sarga/Admin/src/Resources/views/sellers/category/index.blade.php new file mode 100644 index 000000000..1d441ecd6 --- /dev/null +++ b/packages/Sarga/Admin/src/Resources/views/sellers/category/index.blade.php @@ -0,0 +1,28 @@ +@extends('marketplace::admin.layouts.content') + +@section('page_title') + {{ __('marketplace::app.admin.sellers.category.title') }} +@stop + +@section('content') + +
+ + +
+ + @inject('sellerCategory', 'Sarga\Admin\DataGrids\SellerCategoryDataGrid') + {!! $sellerCategory->render() !!} + +
+
+ +@stop diff --git a/packages/Sarga/Admin/src/Routes/catalog-routes.php b/packages/Sarga/Admin/src/Routes/catalog-routes.php index af4059a9a..34153e3ea 100644 --- a/packages/Sarga/Admin/src/Routes/catalog-routes.php +++ b/packages/Sarga/Admin/src/Routes/catalog-routes.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use Webkul\Attribute\Http\Controllers\AttributeController; use Webkul\Attribute\Http\Controllers\AttributeFamilyController; use Webkul\Category\Http\Controllers\CategoryController; +use Webkul\Marketplace\Http\Controllers\Admin\SellerCategoryController; use Webkul\Product\Http\Controllers\ProductController; /** @@ -23,4 +24,18 @@ Route::group(['middleware' => ['web', 'admin', 'admin_locale'], 'prefix' => conf ])->name('admin.catalog.categories.edit'); }); + Route::prefix('marketplace/seller-categories')->group(function () { + + Route::get('/', 'Webkul\Marketplace\Http\Controllers\Admin\SellerCategoryController@index')->defaults('_config', [ + 'view' => 'sarga_admin::sellers.category.index' + ])->name('admin.marketplace.seller.category.index'); + + Route::get('create', [SellerCategoryController::class, 'create'])->defaults('_config', [ + 'view' => 'sarga_admin::sellers.category.create', + ])->name('admin.marketplace.seller.category.create'); + + Route::get('edit/{id}', 'Webkul\Marketplace\Http\Controllers\Admin\SellerCategoryController@edit')->defaults('_config', [ + 'view' => 'sarga_admin::sellers.category.edit', + ])->name('admin.marketplace.seller.category.edit'); + }); }); diff --git a/packages/Webkul/Marketplace/src/Models/Seller.php b/packages/Webkul/Marketplace/src/Models/Seller.php index 015e7fc15..7c98c66d6 100644 --- a/packages/Webkul/Marketplace/src/Models/Seller.php +++ b/packages/Webkul/Marketplace/src/Models/Seller.php @@ -82,4 +82,8 @@ class Seller extends Model implements SellerContract { return $this->hasMany(OrderProxy::modelClass(), 'marketplace_seller_id'); } + + public function categories(){ + return $this->hasMany(SellerCategoryProxy::modelClass(),'seller_id'); + } } \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php index 623d01ac9..ab953a82b 100755 --- a/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php +++ b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php @@ -3,37 +3,60 @@ namespace Webkul\Sales\Repositories; use Illuminate\Container\Container as App; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\DB; use Webkul\Core\Eloquent\Repository; use Webkul\Sales\Contracts\Invoice; -use Webkul\Sales\Generators\InvoiceSequencer; - +use Webkul\Marketplace\Repositories\OrderRepository as SellerOrderRepository; +use Webkul\Marketplace\Repositories\SellerRepository; +use Webkul\Marketplace\Repositories\ProductRepository as MpProductRepository; class InvoiceRepository extends Repository { /** - * Order repository instance. + * OrderRepository object * * @var \Webkul\Sales\Repositories\OrderRepository */ protected $orderRepository; + /** + * SellerRepository object + * + * @var mixed + */ + protected $sellerRepository; + + /** - * Order's item repository instance. + * MpProductRepository object + * + * @var mixed + */ + protected $mpProductRepository; + + /** + * SellerOrderRepository object + * + * @var \Webkul\Marketplace\Repositories\OrderRepository as SellerOrderRepository + */ + protected $sellerOrderRepository; + + /** + * OrderItemRepository object * * @var \Webkul\Sales\Repositories\OrderItemRepository */ protected $orderItemRepository; /** - * Invoice's item repository instance. + * InvoiceItemRepository object * * @var \Webkul\Sales\Repositories\InvoiceItemRepository */ protected $invoiceItemRepository; /** - * Downloadable link purchased repository instance. + * DownloadableLinkPurchasedRepository object * * @var \Webkul\Sales\Repositories\DownloadableLinkPurchasedRepository */ @@ -53,8 +76,12 @@ class InvoiceRepository extends Repository OrderItemRepository $orderItemRepository, InvoiceItemRepository $invoiceItemRepository, DownloadableLinkPurchasedRepository $downloadableLinkPurchasedRepository, + SellerOrderRepository $sellerOrderRepository, + SellerRepository $sellerRepository, + MpProductRepository $mpProductRepository, App $app - ) { + ) + { $this->orderRepository = $orderRepository; $this->orderItemRepository = $orderItemRepository; @@ -65,31 +92,37 @@ class InvoiceRepository extends Repository $this->downloadableLinkPurchasedRepository = $downloadableLinkPurchasedRepository; + $this->sellerOrderRepository = $sellerOrderRepository; + + $this->sellerRepository = $sellerRepository; + + $this->mpProductRepository = $mpProductRepository; + parent::__construct($app); } /** - * Specify model class name. + * Specify Model class name * * @return string */ - public function model() + + function model() { return Invoice::class; } /** - * Create invoice. - * * @param array $data - * @param string $invoiceState - * @param string $orderState * @return \Webkul\Sales\Contracts\Invoice */ - public function create(array $data, $invoiceState = null, $orderState = null) + public function create(array $data) { + DB::beginTransaction(); + + try { Event::dispatch('sales.invoice.save.before', $data); @@ -97,17 +130,10 @@ class InvoiceRepository extends Repository $totalQty = array_sum($data['invoice']['items']); - if (isset($invoiceState)) { - $state = $invoiceState; - } else { - $state = "paid"; - } - $invoice = $this->model->create([ - 'increment_id' => $this->generateIncrementId(), 'order_id' => $order->id, 'total_qty' => $totalQty, - 'state' => $state, + 'state' => 'paid', 'base_currency_code' => $order->base_currency_code, 'channel_currency_code' => $order->channel_currency_code, 'order_currency_code' => $order->order_currency_code, @@ -135,10 +161,10 @@ class InvoiceRepository extends Repository 'base_price' => $orderItem->base_price, 'total' => $orderItem->price * $qty, 'base_total' => $orderItem->base_price * $qty, - 'tax_amount' => (($orderItem->tax_amount / $orderItem->qty_ordered) * $qty), - 'base_tax_amount' => (($orderItem->base_tax_amount / $orderItem->qty_ordered) * $qty), - 'discount_amount' => (($orderItem->discount_amount / $orderItem->qty_ordered) * $qty), - 'base_discount_amount' => (($orderItem->base_discount_amount / $orderItem->qty_ordered) * $qty), + 'tax_amount' => ( ($orderItem->tax_amount / $orderItem->qty_ordered) * $qty ), + 'base_tax_amount' => ( ($orderItem->base_tax_amount / $orderItem->qty_ordered) * $qty ), + 'discount_amount' => ( ($orderItem->discount_amount / $orderItem->qty_ordered) * $qty ), + 'base_discount_amount' => ( ($orderItem->base_discount_amount / $orderItem->qty_ordered) * $qty ), 'product_id' => $orderItem->product_id, 'product_type' => $orderItem->product_type, 'additional' => $orderItem->additional, @@ -147,8 +173,8 @@ class InvoiceRepository extends Repository if ($orderItem->getTypeInstance()->isComposite()) { foreach ($orderItem->children as $childOrderItem) { $finalQty = $childOrderItem->qty_ordered - ? ($childOrderItem->qty_ordered / $orderItem->qty_ordered) * $qty - : $orderItem->qty_ordered; + ? ($childOrderItem->qty_ordered / $orderItem->qty_ordered) * $qty + : $orderItem->qty_ordered; $this->invoiceItemRepository->create([ 'invoice_id' => $invoice->id, @@ -170,8 +196,7 @@ class InvoiceRepository extends Repository 'additional' => $childOrderItem->additional, ]); - if ( - $childOrderItem->product + if ($childOrderItem->product && ! $childOrderItem->getTypeInstance()->isStockable() && $childOrderItem->getTypeInstance()->showQuantityBox() ) { @@ -185,8 +210,7 @@ class InvoiceRepository extends Repository $this->orderItemRepository->collectTotals($childOrderItem); } - } elseif ( - $orderItem->product + } elseif ($orderItem->product && ! $orderItem->getTypeInstance()->isStockable() && $orderItem->getTypeInstance()->showQuantityBox() ) { @@ -207,11 +231,7 @@ class InvoiceRepository extends Repository $this->orderRepository->collectTotals($order); - if (isset($orderState)) { - $this->orderRepository->updateOrderStatus($order, $orderState); - } else { - $this->orderRepository->updateOrderStatus($order); - } + $this->orderRepository->updateOrderStatus($order); Event::dispatch('sales.invoice.save.after', $invoice); } catch (\Exception $e) { @@ -226,23 +246,12 @@ class InvoiceRepository extends Repository } /** - * Generate increment id. - * - * @return int - */ - public function generateIncrementId() - { - return app(InvoiceSequencer::class)->resolveGeneratorClass(); - } - - /** - * Collect totals. - * - * @param \Webkul\Sales\Models\Invoice $invoice - * @return \Webkul\Sales\Models\Invoice + * @param \Webkul\Sales\Contracts\Invoice $invoice + * @return \Webkul\Sales\Contracts\Invoice */ public function collectTotals($invoice) { + $invoice->sub_total = $invoice->base_sub_total = 0; $invoice->tax_amount = $invoice->base_tax_amount = 0; $invoice->discount_amount = $invoice->base_discount_amount = 0; @@ -261,13 +270,54 @@ class InvoiceRepository extends Repository $invoice->shipping_amount = $invoice->order->shipping_amount; $invoice->base_shipping_amount = $invoice->order->base_shipping_amount; + $mpProduct = $this->mpProductRepository->findOneWhere(['product_id' => $invoiceItem->product_id, 'price' => $invoiceItem->price]); + + $seller = null; + + if ($mpProduct) { + $seller = $mpProduct->seller; + } + + if($seller) { + + $shipping = $this->sellerOrderRepository->where('order_id',$invoice->order->id) + ->where('marketplace_seller_id',$seller->id) + ->first(); + + if($shipping->shipping_amount) { + + $invoice->shipping_amount = $shipping->shipping_amount; + $invoice->base_shipping_amount = $shipping->shipping_amount; + + } + + } + $invoice->discount_amount += $invoice->order->shipping_discount_amount; $invoice->base_discount_amount += $invoice->order->base_shipping_discount_amount; if ($invoice->order->shipping_amount) { + foreach ($invoice->order->invoices as $prevInvoice) { + if ((float) $prevInvoice->shipping_amount) { - $invoice->shipping_amount = $invoice->base_shipping_amount = 0; + + if($seller) { + + $shipping = $this->sellerOrderRepository->where('order_id',$invoice->order->id) + ->where('marketplace_seller_id',$seller->id) + ->first(); + + if($shipping->shipping_amount) { + + $invoice->shipping_amount = $shipping->shipping_amount; + + } + + } else { + $invoice->shipping_amount = $invoice->base_shipping_amount = 0; + } + } if ($prevInvoice->id != $invoice->id) { @@ -284,16 +334,4 @@ class InvoiceRepository extends Repository return $invoice; } - - /** - * @param \Webkul\Sales\Contracts\Invoice $invoice - * @return void - */ - public function updateState($invoice, $status) - { - $invoice->state = $status; - $invoice->save(); - - return true; - } -} +} \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php b/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php index d90951a41..caec17bb8 100755 --- a/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php +++ b/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php @@ -13,6 +13,7 @@ use Webkul\Customer\Repositories\WishlistRepository; use Webkul\Category\Repositories\CategoryRepository; use Webkul\Velocity\Repositories\Product\ProductRepository as VelocityProductRepository; use Webkul\Velocity\Repositories\VelocityCustomerCompareProductRepository as CustomerCompareProductRepository; +use Webkul\Marketplace\Repositories\ProductRepository as MpProductRepository; class Controller extends BaseController { @@ -74,6 +75,8 @@ class Controller extends BaseController */ protected $compareProductsRepository; + protected $mpProductRepository; + /** * Create a new controller instance. @@ -94,7 +97,8 @@ class Controller extends BaseController WishlistRepository $wishlistRepository, CategoryRepository $categoryRepository, VelocityProductRepository $velocityProductRepository, - CustomerCompareProductRepository $compareProductsRepository + CustomerCompareProductRepository $compareProductsRepository, + MpProductRepository $mpProductRepository ) { $this->_config = request('_config'); @@ -111,5 +115,7 @@ class Controller extends BaseController $this->velocityProductRepository = $velocityProductRepository; $this->compareProductsRepository = $compareProductsRepository; + + $this->mpProductRepository = $mpProductRepository; } } diff --git a/packages/Webkul/Velocity/src/Http/Controllers/Shop/ShopController.php b/packages/Webkul/Velocity/src/Http/Controllers/Shop/ShopController.php index b227ee34e..cfa2adb4e 100644 --- a/packages/Webkul/Velocity/src/Http/Controllers/Shop/ShopController.php +++ b/packages/Webkul/Velocity/src/Http/Controllers/Shop/ShopController.php @@ -3,13 +3,14 @@ namespace Webkul\Velocity\Http\Controllers\Shop; use Illuminate\Http\Request; -use Webkul\Product\Facades\ProductImage; use Webkul\Velocity\Http\Shop\Controllers; use Webkul\Checkout\Contracts\Cart as CartModel; use Cart; + class ShopController extends Controller { + /** * Index to handle the view loaded with the search results * @@ -29,14 +30,14 @@ class ShopController extends Controller if ($product) { $productReviewHelper = app('Webkul\Product\Helpers\Review'); - $galleryImages = ProductImage::getProductBaseImage($product); + $galleryImages = productimage()->getProductBaseImage($product); $response = [ 'status' => true, 'details' => [ 'name' => $product->name, 'urlKey' => $product->url_key, - 'priceHTML' => view('shop::products.price', ['product' => $product])->render(), + 'priceHTML' => $product->getTypeInstance()->getPriceHtml(), 'totalReviews' => $productReviewHelper->getTotalReviews($product), 'rating' => ceil($productReviewHelper->getAverageRating($product)), 'image' => $galleryImages['small_image_url'], @@ -62,16 +63,18 @@ class ShopController extends Controller if (! $slug) { abort(404); } - + + $unApprovedProductId = $this->mpProductRepository->findWhere(['is_approved' => 0, 'is_owner' => 1])->pluck('product_id'); + switch ($slug) { case 'new-products': case 'featured-products': $count = request()->get('count'); if ($slug == "new-products") { - $products = $this->velocityProductRepository->getNewProducts($count); + $products = $this->velocityProductRepository->getNewProducts($count)->whereNotIn('product_id', $unApprovedProductId);; } else if ($slug == "featured-products") { - $products = $this->velocityProductRepository->getFeaturedProducts($count); + $products = $this->velocityProductRepository->getFeaturedProducts($count)->whereNotIn('product_id', $unApprovedProductId);; } $response = [ @@ -84,9 +87,7 @@ class ShopController extends Controller return $this->velocityHelper->formatProduct($product); } } - })->reject(function ($product) { - return is_null($product); - })->values(), + }), ]; break; @@ -178,7 +179,6 @@ class ShopController extends Controller 'name' => $category->name, 'children' => $formattedChildCategory, 'category_icon_path' => $category->category_icon_path, - 'image' => $category->image ]; } @@ -198,25 +198,10 @@ class ShopController extends Controller public function getItemsCount() { if ($customer = auth()->guard('customer')->user()) { - - if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) { - $wishlistItemsCount = $this->wishlistRepository->getModel() - ->leftJoin('products as ps', 'wishlist.product_id', '=', 'ps.id') - ->leftJoin('product_inventories as pv', 'ps.id', '=', 'pv.product_id') - ->where(function ($qb) { - $qb - ->WhereIn('ps.type', ['configurable', 'grouped', 'downloadable', 'bundle', 'booking']) - ->orwhereIn('ps.type', ['simple', 'virtual'])->where('pv.qty' , '>' , 0); - }) - ->where('wishlist.customer_id' , $customer->id) - ->where('wishlist.channel_id' , core()->getCurrentChannel()->id) - ->count('wishlist.id'); - } else { - $wishlistItemsCount = $this->wishlistRepository->count([ - 'customer_id' => $customer->id, - 'channel_id' => core()->getCurrentChannel()->id, - ]); - } + $wishlistItemsCount = $this->wishlistRepository->count([ + 'customer_id' => $customer->id, + 'channel_id' => core()->getCurrentChannel()->id, + ]); $comparedItemsCount = $this->compareProductsRepository->count([ 'customer_id' => $customer->id, @@ -258,36 +243,26 @@ class ShopController extends Controller ]); } - /** - * This method will fetch products from category. - * - * @param int $categoryId - * - * @return \Illuminate\Http\Response - */ public function getCategoryProducts($categoryId) { - /* fetch category details */ - $categoryDetails = $this->categoryRepository->find($categoryId); + $products = $this->productRepository->getAll($categoryId); - /* if category not found then return empty response */ - if (! $categoryDetails) { - return response()->json([ - 'products' => [], - 'paginationHTML' => '' - ]); + $productItems = $products->items(); + $productsArray = $products->toArray(); + + if ($productItems) { + $formattedProducts = []; + + foreach ($productItems as $product) { + array_push($formattedProducts, $this->velocityHelper->formatProduct($product)); + } + + $productsArray['data'] = $formattedProducts; } - /* fetching products */ - $products = $this->productRepository->getAll($categoryId); - $products->withPath($categoryDetails->slug); - - /* sending response */ - return response()->json([ - 'products' => collect($products->items())->map(function ($product) { - return $this->velocityHelper->formatProduct($product); - }), - 'paginationHTML' => $products->appends(request()->input())->links()->toHtml() + return response()->json($response ?? [ + 'products' => $productsArray['data'], + 'paginationHTML' => $products->appends(request()->input())->links()->toHtml(), ]); } -} \ No newline at end of file +}