added bestseller twig function (fixed comment)

This commit is contained in:
Muammer Top 2021-06-28 16:42:00 +03:00
parent f987be6bc2
commit 8b320f93fc
3 changed files with 442 additions and 439 deletions

View File

@ -415,6 +415,13 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
}
}
public function currentAds() {
return $this->whereDate('finish_at', '>=', date("Y-m-d H:i:s"))
->where('status', '=', 'approved')
->where('slug', '!=', '')
->orderBy('publish_at', 'desc');
}
public function inStock()
{
return $this->is_get_adv && $this->stock;

View File

@ -379,21 +379,15 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
*/
public function latestAds()
{
$latest_advs = $this->model
->whereDate('finish_at', '>=', date("Y-m-d H:i:s"))
->where('status', '=', 'approved')
->where('slug', '!=', '')
->orderBy('publish_at', 'desc')
->limit(setting_value('visiosoft.module.advs::latest-limit'))->get();
$ads = $this->model->getLocationNames($latest_advs);
return $ads;
$latest_advs = $this->model->currentAds()
->limit(setting_value('visiosoft.module.advs::latest-limit'))
->get();
return $this->model->getLocationNames($latest_advs);
}
public function bestsellerAds($catId = null, $limit = 10)
{
return $this->model->orderBy('total_sales', 'desc')
return $this->model->currentAds()->orderBy('total_sales', 'desc')
->where(function ($query) use ($catId) {
if ($catId) {
$query->where('cat1', $catId);

View File

@ -1,20 +1,22 @@
<?php namespace Visiosoft\AdvsModule\OptionHandler;
use Anomaly\CheckboxesFieldType\CheckboxesFieldType;
use Visiosoft\AdvsModule\Adv\AdvModel;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\MultipleFieldType\MultipleFieldType;
class AdvsOptions
{
private $advRepository;
private $advModel;
public function __construct(AdvRepositoryInterface $advRepository)
public function __construct(AdvModel $advModel)
{
$this->advRepository = $advRepository;
$this->advModel = $advModel;
}
public function handle(CheckboxesFieldType $fieldType)
{
$categories = $this->advRepository->all();
$categories = $this->advModel->currentAds()->get();
$options = $categories->pluck('name', 'id')->all();
$fieldType->setOptions($options);
}