vendor categories

This commit is contained in:
merdiano 2021-12-29 08:05:55 +05:00
parent cd690289dd
commit 296f09d424
15 changed files with 480 additions and 197 deletions

View File

@ -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

View File

@ -28,7 +28,7 @@ return [
|
*/
'theme' => env('IGNITION_THEME', 'dark'),
'theme' => env('IGNITION_THEME', 'light'),
/*
|--------------------------------------------------------------------------

View File

@ -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);

View File

@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: merdan
* Date: 12/29/2021
* Time: 7:30
*/
namespace Sarga\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class SellerCategory extends JsonResource
{
public function toArray($request)
{
return [
'type' => $this->type,
'ids' => json_decode($this->categories)
];
}
}

View File

@ -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),
];
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace Sarga\Admin\DataGrids;
use DB;
use Webkul\Ui\DataGrid\DataGrid;
/**
* Seller Data Grid class
*
* @author Jitendra Singh <jitendra@webkul.com>
* @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) ;
}
}

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateSellerCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('seller_categories', function (Blueprint $table) {
$table->string('type')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('seller_categories', function (Blueprint $table) {
$table->dropColumn('type');
});
}
}

View File

@ -0,0 +1,64 @@
@extends('admin::layouts.content')
@section('page_title')
{{ __('marketplace::app.admin.sellers.category.add-title') }}
@stop
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.marketplace.seller.category.store') }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
<h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ route('admin.dashboard.index') }}';"></i>
{{ __('marketplace::app.admin.sellers.category.add-title') }}
{{-- {{ Config::get('carrier.social.facebook.url') }} --}}
</h1>
</div>
<div class="page-action">
<button type="submit" class="btn btn-lg btn-primary">
{{ __('marketplace::app.admin.sellers.category.save-btn-title') }}
</button>
</div>
</div>
<div class="page-content">
<div class="form-container">
@csrf()
<div class="control-group" :class="[errors.has('seller_id') ? 'has-error' : '']">
<label for="seller_id" class="required">{{ __('marketplace::app.admin.sellers.category.seller') }}</label>
<select name="seller_id" id="seller_id" class="control"
data-vv-as="&quot;{{ __('marketplace::app.admin.sellers.category.seller') }}&quot;"
>
@foreach ($sellers as $seller)
<option value="{{$seller->id}}"> {{$seller->customer->name}}</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('seller_id')">@{{ errors.first('seller_id') }}</span>
</div>
<div class="control-group" :class="[errors.has('type') ? 'has-error' : '']">
<label for="type" class="required">Type</label>
<select name="type" id="type" class="control" data-vv-as="&quot;Type&quot;">
<option value="main">Main</option>
<option value="promo">Promo</option>
<option value="featured">Featured</option>
</select>
</div>
@if ($categories->count())
<tree-view behavior="normal" value-field="id" name-field="categories" input-type="checkbox" items='@json($categories)' value='' fallback-locale="{{ config('app.fallback_locale') }}"></tree-view>
@endif
</div>
</div>
</form>
</div>
@stop

View File

@ -0,0 +1,63 @@
@extends('admin::layouts.content')
@section('page_title')
{{ __('marketplace::app.admin.sellers.category.edit-title') }}
@stop
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.marketplace.seller.category.update', $sellerCategories->id) }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
<h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ route('admin.dashboard.index') }}';"></i>
{{ __('marketplace::app.admin.sellers.category.edit-title') }}
{{-- {{ Config::get('carrier.social.facebook.url') }} --}}
</h1>
</div>
<div class="page-action">
<button type="submit" class="btn btn-lg btn-primary">
{{ __('marketplace::app.admin.sellers.category.update-btn-title') }}
</button>
</div>
</div>
<div class="page-content">
<div class="form-container">
@csrf()
<div class="control-group" :class="[errors.has('seller_id') ? 'has-error' : '']">
<label for="seller_id" class="required">{{ __('marketplace::app.admin.sellers.category.seller') }}</label>
<select name="seller_id" id="seller_id" class="control"
data-vv-as="&quot;{{ __('marketplace::app.admin.sellers.category.seller') }}&quot;"
>
@foreach ($sellers as $seller)
<option value="{{$seller->id}}" @if(old('seller_id',$sellerCategories->seller_id)==$seller->id)selected @endif> {{$seller->customer->name}}</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('seller_id')">@{{ errors.first('seller_id') }}</span>
</div>
<div class="control-group" :class="[errors.has('type') ? 'has-error' : '']">
<label for="type" class="required">Type</label>
<select name="type" id="type" class="control" data-vv-as="&quot;Type&quot;">
<option value="main" @if(old('type',$sellerCategories->type)=="main")selected @endif>Main</option>
<option value="promo" @if(old('type',$sellerCategories->type)=="promo")selected @endif>Promo</option>
<option value="featured" @if(old('type',$sellerCategories->type)=="featured")selected @endif>Featured</option>
</select>
</div>
@if ($categories->count())
<tree-view behavior="normal" value-field="id" name-field="categories" input-type="checkbox" items='@json($categories)' value='@json(json_decode($sellerCategories->categories))' fallback-locale="{{ config('app.fallback_locale') }}"></tree-view>
@endif
</div>
</div>
</form>
</div>
@stop

View File

@ -0,0 +1,28 @@
@extends('marketplace::admin.layouts.content')
@section('page_title')
{{ __('marketplace::app.admin.sellers.category.title') }}
@stop
@section('content')
<div class="content">
<div class="page-header">
<div class="page-title">
<h1>{{ __('marketplace::app.admin.sellers.category.title') }}</h1>
</div>
<div class="page-action">
<a href="{{route('admin.marketplace.seller.category.create')}}" class="btn btn-lg btn-primary">{{ __('marketplace::app.admin.sellers.category.create') }}</a>
</div>
</div>
<div class="page-content">
@inject('sellerCategory', 'Sarga\Admin\DataGrids\SellerCategoryDataGrid')
{!! $sellerCategory->render() !!}
</div>
</div>
@stop

View File

@ -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');
});
});

View File

@ -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');
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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(),
]);
}
}
}