added bestseller twig function

This commit is contained in:
Muammer Top 2021-06-23 09:16:32 +03:00
parent c03b75ad56
commit 1610a31cc3
3 changed files with 16 additions and 9 deletions

View File

@ -391,6 +391,17 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
return $ads; return $ads;
} }
public function bestsellerAds($catId = null, $limit = 10)
{
return $this->model->orderBy('total_sales', 'desc')
->where(function ($query) use ($catId) {
if ($catId) {
$query->where('cat1', $catId);
}
})
->limit($limit)->get();
}
public function getByCat($catID, $level = 1, $limit = 20) public function getByCat($catID, $level = 1, $limit = 20)
{ {
$advs = $this->model $advs = $this->model

View File

@ -35,6 +35,8 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
public function latestAds(); public function latestAds();
public function bestsellerAds($catId= null, $limit = 10);
public function getByCat($catID, $level = 1, $limit = 20); public function getByCat($catID, $level = 1, $limit = 20);
public function getAdsCountByCategory($catID, $level = 1); public function getAdsCountByCategory($catID, $level = 1);

View File

@ -9,6 +9,7 @@ use Visiosoft\AdvsModule\Adv\Command\getPopular;
use Visiosoft\AdvsModule\Adv\Command\GetUserAds; use Visiosoft\AdvsModule\Adv\Command\GetUserAds;
use Visiosoft\AdvsModule\Adv\Command\isActive; use Visiosoft\AdvsModule\Adv\Command\isActive;
use Visiosoft\AdvsModule\Adv\Command\LatestAds; use Visiosoft\AdvsModule\Adv\Command\LatestAds;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\AdvsModule\Support\Command\Currency; use Visiosoft\AdvsModule\Support\Command\Currency;
class AdvsModulePlugin extends Plugin class AdvsModulePlugin extends Plugin
@ -51,15 +52,8 @@ class AdvsModulePlugin extends Plugin
), ),
new \Twig_SimpleFunction( new \Twig_SimpleFunction(
'bestsellerAds', 'bestsellerAds',
function ($catId = null) { function ($catId = null, $limit = 10) {
return AdvModel::query() return app(AdvRepositoryInterface::class)->bestsellerAds($catId, $limit);
->orderBy('total_sales', 'desc')
->where(function ($query) use ($catId) {
if ($catId) {
$query->where('cat1', $catId);
}
})
->limit(10)->get();
} }
), ),
new \Twig_SimpleFunction( new \Twig_SimpleFunction(