Change product repository
This commit is contained in:
parent
d01e2e25f2
commit
4a4c65faef
|
|
@ -30,7 +30,7 @@ class ProductRepository extends WProductRepository
|
|||
protected $vendorProductRepository;
|
||||
// protected $brandRepository;
|
||||
|
||||
protected $fillableTypes = ['sku', 'name', 'url_key', 'short_description', 'description', 'price', 'weight', 'status'];
|
||||
protected $fillableTypes = ['sku', 'name', 'url_key', 'short_description', 'description', 'price', 'weight', 'status', 'qty'];
|
||||
|
||||
public function __construct(AttributeRepository $attributeRepository,
|
||||
App $app,
|
||||
|
|
@ -40,7 +40,7 @@ class ProductRepository extends WProductRepository
|
|||
ProductImageRepository $productImageRepository,
|
||||
VendorProductRepository $vendorProductRepository,
|
||||
VendorRepository $vendorRepository,
|
||||
// BrandRepository $brandRepository,
|
||||
// BrandRepository $brandRepository,
|
||||
AttributeOptionRepository $optionRepository)
|
||||
{
|
||||
$this->attributeGroupRepo = $attributeGroupRepo;
|
||||
|
|
@ -50,7 +50,7 @@ class ProductRepository extends WProductRepository
|
|||
$this->imageRepository = $productImageRepository;
|
||||
$this->vendorProductRepository = $vendorProductRepository;
|
||||
// $this->brandRepository = $brandRepository;
|
||||
$this->vendorRepository = $vendorRepository;
|
||||
// $this->vendorRepository = $vendorRepository;
|
||||
|
||||
parent::__construct($attributeRepository, $app);
|
||||
}
|
||||
|
|
@ -59,6 +59,85 @@ class ProductRepository extends WProductRepository
|
|||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
|
||||
public function getProductsRelatedToCategoryNurgul($categoryId = null, $limit)
|
||||
{
|
||||
$qb = $this->model->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id');
|
||||
|
||||
if ($categoryId) {
|
||||
$qb->where('product_categories.category_id', $categoryId);
|
||||
}
|
||||
|
||||
return $qb->paginate($limit);
|
||||
}
|
||||
|
||||
public function searchProductByAttributeNurgul($term, $perPage)
|
||||
{
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
$locale = core()->getRequestedLocaleCode();
|
||||
|
||||
if (config('scout.driver') == 'algolia') {
|
||||
$results = app(ProductFlatRepository::class)->getModel()::search('query', function ($searchDriver, string $query, array $options) use ($term, $channel, $locale) {
|
||||
$queries = explode('_', $term);
|
||||
|
||||
$options['similarQuery'] = array_map('trim', $queries);
|
||||
|
||||
$searchDriver->setSettings([
|
||||
'attributesForFaceting' => [
|
||||
'searchable(locale)',
|
||||
'searchable(channel)',
|
||||
],
|
||||
]);
|
||||
|
||||
$options['facetFilters'] = ['locale:' . $locale, 'channel:' . $channel];
|
||||
|
||||
return $searchDriver->search($query, $options);
|
||||
})
|
||||
->where('status', 1)
|
||||
->where('visible_individually', 1)
|
||||
->orderBy('product_id', 'desc')
|
||||
->paginate($perPage);
|
||||
} else if (config('scout.driver') == 'elastic') {
|
||||
$queries = explode('_', $term);
|
||||
|
||||
$results = app(ProductFlatRepository::class)->getModel()::search(implode(' OR ', $queries))
|
||||
->where('status', 1)
|
||||
->where('visible_individually', 1)
|
||||
->where('channel', $channel)
|
||||
->where('locale', $locale)
|
||||
->orderBy('product_id', 'desc')
|
||||
->paginate($perPage);
|
||||
} else {
|
||||
$results = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term, $channel, $locale) {
|
||||
|
||||
$query = $query->distinct()
|
||||
->addSelect('product_flat.*')
|
||||
->where('product_flat.channel', $channel)
|
||||
->where('product_flat.locale', $locale)
|
||||
->whereNotNull('product_flat.url_key');
|
||||
|
||||
if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) {
|
||||
$query = $this->checkOutOfStockItem($query);
|
||||
}
|
||||
|
||||
return $query->where('product_flat.status', 1)
|
||||
->where('product_flat.visible_individually', 1)
|
||||
->where(function ($subQuery) use ($term) {
|
||||
$queries = explode('_', $term);
|
||||
|
||||
foreach (array_map('trim', $queries) as $value) {
|
||||
$subQuery->orWhere('product_flat.name', 'like', '%' . urldecode($value) . '%')
|
||||
->orWhere('product_flat.short_description', 'like', '%' . urldecode($value) . '%');
|
||||
}
|
||||
})
|
||||
->orderBy('product_id', 'desc');
|
||||
})->paginate($perPage);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getAll($categoryId = null)
|
||||
{
|
||||
$params = request()->input();
|
||||
|
|
@ -100,9 +179,9 @@ class ProductRepository extends WProductRepository
|
|||
// ->addSelect('marketplace_sellers.logo');
|
||||
}
|
||||
|
||||
// if(isset($params['brand'])){
|
||||
// $qb->whereIn('product_flat.brand_id', explode(',',$params['brand']));
|
||||
// }
|
||||
if(isset($params['brand'])){
|
||||
$qb->whereIn('product_flat.brand_id', explode(',',$params['brand']));
|
||||
}
|
||||
|
||||
if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) {
|
||||
$qb = $this->checkOutOfStockItem($qb);
|
||||
|
|
@ -279,7 +358,7 @@ class ProductRepository extends WProductRepository
|
|||
|
||||
$product['type'] = (!empty($data['color_variants']) || !empty($data['size_variants'])) ? 'configurable':'simple';
|
||||
|
||||
// $attributes = Arr::only($data,['brand','cinsiyet']);
|
||||
$attributes = Arr::only($data,['brand','cinsiyet']);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
|
@ -532,12 +611,6 @@ class ProductRepository extends WProductRepository
|
|||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the all products of the seller
|
||||
*
|
||||
* @param integer $seller
|
||||
* @return Collection
|
||||
*/
|
||||
public function findAllBySeller($seller_id,$category_id = null)
|
||||
{
|
||||
$params = request()->input();
|
||||
|
|
@ -557,6 +630,7 @@ class ProductRepository extends WProductRepository
|
|||
AND NOW( ) <= product_flat.special_price_to, IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , product_flat.price ) , IF( product_flat.special_price_from IS NULL , IF( product_flat.special_price_to IS NULL , IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , IF( NOW( ) <= product_flat.special_price_to, IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , product_flat.price ) ) , IF( product_flat.special_price_to IS NULL , IF( NOW( ) >= product_flat.special_price_from, IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , product_flat.price ) , product_flat.price ) ) ) AS price1'))
|
||||
|
||||
->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
|
||||
// ->leftJoin('product_inventories', 'product_flat.product_id', '=', 'product_inventories.product_id')
|
||||
->leftJoin('marketplace_products', 'product_flat.product_id', '=', 'marketplace_products.product_id')
|
||||
->where('product_flat.visible_individually', 1)
|
||||
->where('product_flat.status', 1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue