From 1610a31cc37d879fbd320e73eabf21efbbc24c43 Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Wed, 23 Jun 2021 09:16:32 +0300 Subject: [PATCH] added bestseller twig function --- .../visiosoft/advs-module/src/Adv/AdvRepository.php | 11 +++++++++++ .../src/Adv/Contract/AdvRepositoryInterface.php | 2 ++ .../visiosoft/advs-module/src/AdvsModulePlugin.php | 12 +++--------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 896471a72..1c989cc4d 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -391,6 +391,17 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface 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) { $advs = $this->model diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php index 7b71113b6..1189eab15 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -35,6 +35,8 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface public function latestAds(); + public function bestsellerAds($catId= null, $limit = 10); + public function getByCat($catID, $level = 1, $limit = 20); public function getAdsCountByCategory($catID, $level = 1); diff --git a/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php b/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php index 91f553b45..f0b1f235e 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php @@ -9,6 +9,7 @@ use Visiosoft\AdvsModule\Adv\Command\getPopular; use Visiosoft\AdvsModule\Adv\Command\GetUserAds; use Visiosoft\AdvsModule\Adv\Command\isActive; use Visiosoft\AdvsModule\Adv\Command\LatestAds; +use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Support\Command\Currency; class AdvsModulePlugin extends Plugin @@ -51,15 +52,8 @@ class AdvsModulePlugin extends Plugin ), new \Twig_SimpleFunction( 'bestsellerAds', - function ($catId = null) { - return AdvModel::query() - ->orderBy('total_sales', 'desc') - ->where(function ($query) use ($catId) { - if ($catId) { - $query->where('cat1', $catId); - } - }) - ->limit(10)->get(); + function ($catId = null, $limit = 10) { + return app(AdvRepositoryInterface::class)->bestsellerAds($catId, $limit); } ), new \Twig_SimpleFunction(