Slider Issue Fixed
This commit is contained in:
parent
a3cdcfedfd
commit
207feec214
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
namespace Webkul\Core\Repositories;
|
||||
|
||||
use Storage;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Container\Container as App;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ class SliderRepository extends Repository
|
|||
use CacheableRepository;
|
||||
|
||||
/**
|
||||
* ChannelRepository object
|
||||
* Channel repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\ChannelRepository
|
||||
*/
|
||||
|
|
@ -30,15 +31,14 @@ class SliderRepository extends Repository
|
|||
public function __construct(
|
||||
ChannelRepository $channelRepository,
|
||||
App $app
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->channelRepository = $channelRepository;
|
||||
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify Model class name
|
||||
* Specify model class name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
|
@ -48,8 +48,10 @@ class SliderRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Save slider.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Webkul\Core\Contracts\Slider
|
||||
* @return bool|\Webkul\Core\Contracts\Slider
|
||||
*/
|
||||
public function save(array $data)
|
||||
{
|
||||
|
|
@ -91,7 +93,10 @@ class SliderRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Update item.
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function updateItem(array $data, $id)
|
||||
|
|
@ -134,7 +139,7 @@ class SliderRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete a slider item and delete the image from the disk or where ever it is
|
||||
* Delete a slider item and delete the image from the disk or where ever it is.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
|
|
@ -149,4 +154,26 @@ class SliderRepository extends Repository
|
|||
|
||||
return $this->model->destroy($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get only active sliders.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getActiveSliders()
|
||||
{
|
||||
$currentChannel = core()->getCurrentChannel();
|
||||
|
||||
$currentLocale = core()->getCurrentLocale();
|
||||
|
||||
return $this->where('channel_id', $currentChannel->id)
|
||||
->whereRaw("find_in_set(?, locale)", [$currentLocale->code])
|
||||
->where(function ($query) {
|
||||
$query->where('expired_at', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->orWhereNull('expired_at');
|
||||
})
|
||||
->orderBy('sort_order', 'ASC')
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Webkul\Shop\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Webkul\Shop\Http\Controllers\Controller;
|
||||
use Webkul\Core\Repositories\SliderRepository;
|
||||
use Webkul\Product\Repositories\SearchRepository;
|
||||
|
|
@ -10,14 +9,14 @@ use Webkul\Product\Repositories\SearchRepository;
|
|||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* SliderRepository object
|
||||
* Slider repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\SliderRepository
|
||||
*/
|
||||
protected $sliderRepository;
|
||||
|
||||
/**
|
||||
* SearchRepository object
|
||||
* Search repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\SearchRepository
|
||||
*/
|
||||
|
|
@ -33,8 +32,7 @@ class HomeController extends Controller
|
|||
public function __construct(
|
||||
SliderRepository $sliderRepository,
|
||||
SearchRepository $searchRepository
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->sliderRepository = $sliderRepository;
|
||||
|
||||
$this->searchRepository = $searchRepository;
|
||||
|
|
@ -43,39 +41,19 @@ class HomeController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* loads the home page for the storefront
|
||||
* Loads the home page for the storefront.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$currentChannel = core()->getCurrentChannel();
|
||||
|
||||
$currentLocale = core()->getCurrentLocale();
|
||||
|
||||
$sliderData = $this->sliderRepository
|
||||
->where('channel_id', $currentChannel->id)
|
||||
->whereRaw("find_in_set(?, locale)", [$currentLocale->code])
|
||||
->where(function ($query) {
|
||||
$query->where('expired_at', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->orWhereNull('expired_at');
|
||||
})
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
usort($sliderData, function ($a, $b) {
|
||||
if ($a['sort_order'] == $b['sort_order']) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a['sort_order'] < $b['sort_order']) ? -1 : 1;
|
||||
});
|
||||
$sliderData = $this->sliderRepository->getActiveSliders();
|
||||
|
||||
return view($this->_config['view'], compact('sliderData'));
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the home page for the storefront
|
||||
* Loads the home page for the storefront if something wrong.
|
||||
*
|
||||
* @return \Exception
|
||||
*/
|
||||
|
|
@ -85,14 +63,12 @@ class HomeController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Upload image for product search with machine learning
|
||||
* Upload image for product search with machine learning.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$url = $this->searchRepository->uploadSearchImage(request()->all());
|
||||
|
||||
return $url;
|
||||
return $this->searchRepository->uploadSearchImage(request()->all());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +1,53 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Webkul\Shop\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Webkul\Category\Repositories\CategoryRepository;
|
||||
use Webkul\Core\Repositories\SliderRepository;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Category\Repositories\CategoryRepository;
|
||||
|
||||
class ProductsCategoriesProxyController extends Controller
|
||||
{
|
||||
/**
|
||||
* CategoryRepository object
|
||||
* Category repository instance.
|
||||
*
|
||||
* @var \Webkul\Category\Repositories\CategoryRepository
|
||||
*/
|
||||
protected $categoryRepository;
|
||||
|
||||
/**
|
||||
* ProductRepository object
|
||||
* Product repository instance.
|
||||
*
|
||||
* @var \Webkul\Product\Repositories\ProductRepository
|
||||
*/
|
||||
protected $productRepository;
|
||||
|
||||
/**
|
||||
* Slider repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\SliderRepository
|
||||
*/
|
||||
protected $sliderRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository
|
||||
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryRepository $categoryRepository,
|
||||
ProductRepository $productRepository
|
||||
)
|
||||
{
|
||||
ProductRepository $productRepository,
|
||||
SliderRepository $sliderRepository
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
|
||||
$this->sliderRepository = $sliderRepository;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
|
@ -73,13 +81,7 @@ class ProductsCategoriesProxyController extends Controller
|
|||
abort(404);
|
||||
}
|
||||
|
||||
$sliderRepository = app('Webkul\Core\Repositories\SliderRepository');
|
||||
|
||||
$sliderData = $sliderRepository
|
||||
->where('channel_id', core()->getCurrentChannel()->id)
|
||||
->where('locale', core()->getCurrentLocale()->code)
|
||||
->get()
|
||||
->toArray();
|
||||
$sliderData = $this->sliderRepository->getActiveSliders();
|
||||
|
||||
return view('shop::home.index', compact('sliderData'));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue