Removed ProductRepository from Velocity
This commit is contained in:
parent
3ae977a49c
commit
c457b98b8e
|
|
@ -6,7 +6,6 @@ use Webkul\Velocity\Helpers\Helper;
|
|||
use Webkul\Product\Repositories\ProductRepository;
|
||||
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\Product\Facades\ProductImage;
|
||||
|
||||
|
|
@ -26,7 +25,6 @@ class ShopController extends Controller
|
|||
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
|
||||
* @param \Webkul\Product\Repositories\WishlistRepository $wishlistRepository
|
||||
* @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository
|
||||
* @param \Webkul\Velocity\Repositories\Product\ProductRepository $velocityProductRepository
|
||||
* @param \Webkul\Velocity\Repositories\VelocityCustomerCompareProductRepository $compareProductsRepository
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -36,7 +34,6 @@ class ShopController extends Controller
|
|||
protected ProductRepository $productRepository,
|
||||
protected WishlistRepository $wishlistRepository,
|
||||
protected CategoryRepository $categoryRepository,
|
||||
protected VelocityProductRepository $velocityProductRepository,
|
||||
protected CustomerCompareProductRepository $compareProductsRepository
|
||||
)
|
||||
{
|
||||
|
|
@ -50,7 +47,9 @@ class ShopController extends Controller
|
|||
*/
|
||||
public function search()
|
||||
{
|
||||
$results = $this->velocityProductRepository->searchProductsFromCategory(request()->all());
|
||||
request()->query->add(['name' => request('term')]);
|
||||
|
||||
$results = $this->productRepository->getAll(request('category'));
|
||||
|
||||
return view($this->_config['view'])->with('results', $results ? $results : null);
|
||||
}
|
||||
|
|
@ -123,7 +122,7 @@ class ShopController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
$products = $this->velocityProductRepository->getAll();
|
||||
$products = $this->productRepository->getAll();
|
||||
|
||||
$response = [
|
||||
'status' => true,
|
||||
|
|
|
|||
|
|
@ -1,128 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Velocity\Repositories\Product;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Webkul\Product\Repositories\ProductRepository as BaseProductRepository;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
use Webkul\Product\Repositories\ProductFlatRepository;
|
||||
use Webkul\Attribute\Repositories\AttributeRepository;
|
||||
|
||||
class ProductRepository extends BaseProductRepository
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository
|
||||
* @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository
|
||||
* @param \Webkul\Product\Repositories\ProductFlatRepository $productFlatRepository
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
CustomerRepository $customerRepository,
|
||||
protected AttributeRepository $attributeRepository,
|
||||
protected ProductFlatRepository $productFlatRepository,
|
||||
Container $container
|
||||
)
|
||||
{
|
||||
parent::__construct(
|
||||
$customerRepository,
|
||||
$attributeRepository,
|
||||
$productFlatRepository,
|
||||
$container
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Product by Attribute
|
||||
*
|
||||
* @param array $params
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function searchProductsFromCategory($params)
|
||||
{
|
||||
$results = $this->productFlatRepository->scopeQuery(function($query) use($params) {
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
$locale = core()->getRequestedLocaleCode();
|
||||
|
||||
$query = $query->distinct()
|
||||
->addSelect('product_flat.*')
|
||||
->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
|
||||
->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id')
|
||||
->where('product_flat.status', 1)
|
||||
->where('product_flat.visible_individually', 1)
|
||||
->where('product_flat.channel', $channel)
|
||||
->where('product_flat.locale', $locale)
|
||||
->whereNotNull('product_flat.url_key');
|
||||
|
||||
if (! empty($params['term'])) {
|
||||
$query->where('product_flat.name', 'like', '%' . urldecode($params['term']) . '%');
|
||||
}
|
||||
|
||||
if (! empty($params['category'])) {
|
||||
$query = $query->where('product_categories.category_id', $params['category']);
|
||||
}
|
||||
|
||||
if (isset($params['sort'])) {
|
||||
$attribute = $this->attributeRepository->findOneByField('code', $params['sort']);
|
||||
|
||||
if ($params['sort'] == 'price') {
|
||||
if ($attribute->code == 'price') {
|
||||
$query->orderBy('min_price', $params['order']);
|
||||
} else {
|
||||
$query->orderBy($attribute->code, $params['order']);
|
||||
}
|
||||
} else {
|
||||
$query->orderBy($params['sort'] == 'created_at' ? 'product_flat.created_at' : $attribute->code, $params['order']);
|
||||
}
|
||||
}
|
||||
|
||||
$query = $query->leftJoin('products as variants', 'products.id', '=', 'variants.parent_id');
|
||||
|
||||
$query = $query->where(function($query1) use($query) {
|
||||
$aliases = [
|
||||
'products' => 'filter_',
|
||||
'variants' => 'variant_filter_',
|
||||
];
|
||||
|
||||
foreach($aliases as $table => $alias) {
|
||||
$query1 = $query1->orWhere(function($query2) use ($query, $table, $alias) {
|
||||
|
||||
foreach ($this->attributeRepository->getProductDefaultAttributes(array_keys(request()->input())) as $code => $attribute) {
|
||||
$aliasTemp = $alias . $attribute->code;
|
||||
|
||||
$query = $query->leftJoin('product_attribute_values as ' . $aliasTemp, $table . '.id', '=', $aliasTemp . '.product_id');
|
||||
|
||||
$column = $attribute->column_name;
|
||||
|
||||
$temp = explode(',', request()->get($attribute->code));
|
||||
|
||||
if ($attribute->type != 'price') {
|
||||
$query2 = $query2->where($aliasTemp . '.attribute_id', $attribute->id);
|
||||
|
||||
$query2 = $query2->where(function($query3) use($aliasTemp, $column, $temp) {
|
||||
foreach($temp as $code => $filterValue) {
|
||||
if (! is_numeric($filterValue))
|
||||
continue;
|
||||
|
||||
$columns = $aliasTemp . '.' . $column;
|
||||
$query3 = $query3->orWhereRaw("find_in_set($filterValue, $columns)");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$query2->where('product_flat.min_price', '>=', core()->convertToBasePrice(current($temp)))
|
||||
->where('product_flat.min_price', '<=', core()->convertToBasePrice(end($temp)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return $query->groupBy('product_flat.id');
|
||||
})->paginate($params['limit'] ?? 9);
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue