From fd12783ec063ff48e2b8156015f541624b8b51fb Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Mon, 21 Jun 2021 13:39:15 +0300 Subject: [PATCH 01/10] added bestseller twig function --- ...oft.module.advs__add_total-sales_field.php | 26 ++++++++++ .../advs-module/src/Adv/AdvModel.php | 52 +++++++++++++++++-- .../advs-module/src/AdvsModulePlugin.php | 13 +++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 addons/default/visiosoft/advs-module/migrations/2021_06_21_101029_visiosoft.module.advs__add_total-sales_field.php diff --git a/addons/default/visiosoft/advs-module/migrations/2021_06_21_101029_visiosoft.module.advs__add_total-sales_field.php b/addons/default/visiosoft/advs-module/migrations/2021_06_21_101029_visiosoft.module.advs__add_total-sales_field.php new file mode 100644 index 000000000..3012804f1 --- /dev/null +++ b/addons/default/visiosoft/advs-module/migrations/2021_06_21_101029_visiosoft.module.advs__add_total-sales_field.php @@ -0,0 +1,26 @@ + 'advs', + ]; + + protected $fields = [ + 'total_sales' => [ + 'type' => 'anomaly.field_type.integer', + 'config' => [ + 'min' => 0, + 'default_value' => 0, + ], + ], + ]; + + protected $assignments = [ + 'total_sales' + ]; +} diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index b7227eda5..599ef84d9 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Visiosoft\AdvsModule\Adv\Contract\AdvInterface; use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; +use Visiosoft\AdvsModule\Support\Command\Currency; use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\CartsModule\Cart\Command\GetCart; @@ -17,6 +18,51 @@ use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface; class AdvModel extends AdvsAdvsEntryModel implements AdvInterface { + protected $appends = [ + 'detail_url', + 'currency_price', + 'currency_standard_price', + 'category1', + 'category2', + 'thumbnail', + ]; + + public function getDetailUrlAttribute() + { + return $this->getAdvDetailLinkByModel($this, 'list'); + } + + public function getCurrencyPriceAttribute() + { + return app(Currency::class)->format($this->price, $this->currency); + } + + public function getCurrencyStandardPriceAttribute() + { + return app(Currency::class)->format($this->standard_price, $this->currency); + } + + public function getCategory1Attribute() + { + return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat1')->first(); + + } + + public function getCategory2Attribute() + { + return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat1')->first(); + + } + + public function getThumbnailAttribute() + { + if ($this->cover_photo == null) { + return $this->dispatch(new MakeImageInstance('visiosoft.theme.base::images/no-image.png', 'img'))->url(); + } else { + return url($this->cover_photo); + } + } + public function getTransNameAttribute() { if (is_null($this->name)) { @@ -278,12 +324,10 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface public function stockControl($id, $quantity) { - if($adv = $this->getAdv($id)) - { + if ($adv = $this->getAdv($id)) { $stock = $adv->stock; - if($stock and $stock >= $quantity) - { + if ($stock and $stock >= $quantity) { return 1; } } diff --git a/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php b/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php index 0a1bcc3e3..91f553b45 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php @@ -49,6 +49,19 @@ class AdvsModulePlugin extends Plugin return $latestAds; } ), + 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(); + } + ), new \Twig_SimpleFunction( 'appendRequestURL', function ($request, $url, $new_parameters, $removeParams = []) { From d10bf323c9c4a68f07b3d454f804f6f0b7d3f18b Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Mon, 21 Jun 2021 13:40:34 +0300 Subject: [PATCH 02/10] added bestseller twig function --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2d6098803..6ea064e89 100644 --- a/composer.json +++ b/composer.json @@ -92,7 +92,8 @@ "filp/whoops": "~2.0", "fzaninotto/faker": "~1.4", "symfony/css-selector": "3.1.*", - "symfony/dom-crawler": "3.1.*" + "symfony/dom-crawler": "3.1.*", + "anomaly/installer-module": "~2.4.0" }, "repositories": [ { From 9296722c4d2459f9d3bf7ae62eb8d8158701eaca Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Tue, 22 Jun 2021 09:20:49 +0300 Subject: [PATCH 03/10] added bestseller twig function --- addons/default/visiosoft/advs-module/src/Adv/AdvModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index 599ef84d9..adb8c2a37 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -50,7 +50,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface public function getCategory2Attribute() { - return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat1')->first(); + return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat2')->first(); } From c03b75ad56f2751ad346e2755eae0a45b46da29a Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Tue, 22 Jun 2021 18:28:20 +0300 Subject: [PATCH 04/10] #4183 Biolife-theme pyro add --- .../src/OptionHandler/AdvsOptions.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php diff --git a/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php b/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php new file mode 100644 index 000000000..9a6dc8e24 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php @@ -0,0 +1,21 @@ +advRepository = $advRepository; + } + + public function handle(CheckboxesFieldType $fieldType) + { + $categories = $this->advRepository->all(); + $options = $categories->pluck('name', 'id')->all(); + $fieldType->setOptions($options); + } +} \ No newline at end of file From 1610a31cc37d879fbd320e73eabf21efbbc24c43 Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Wed, 23 Jun 2021 09:16:32 +0300 Subject: [PATCH 05/10] 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( From f987be6bc228f24e49ddcaab4cc4c8f81ee2894b Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Mon, 28 Jun 2021 14:14:40 +0300 Subject: [PATCH 06/10] #4237 The main category does not appear if the subcategory is not attached. --- .../src/Category/CategoryRepository.php | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php b/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php index 69fbd4f8c..2c5d2516c 100644 --- a/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php +++ b/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php @@ -44,36 +44,38 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn $dBName = 'default_cats_category'; $dBNamet = $dBName . '_translations'; - $catsDB = DB::table((DB::raw($dBName . ' c1'))) - ->select( - DB::raw('c1.id'), - DB::raw('c1.slug'), - DB::raw('c1.icon'), - DB::raw('c1.count'), - DB::raw('c1.parent_category_id'), - DB::raw('t1.name'), + $catsDB = DB::table((DB::raw($dBName . ' c1'))) + ->select( + DB::raw('c1.id'), + DB::raw('c1.slug'), + DB::raw('c1.icon'), + DB::raw('c1.count'), + DB::raw('c1.parent_category_id'), + DB::raw('t1.name'), - DB::raw('c2.id as c2_id'), - DB::raw('c2.slug as c2_slug'), - DB::raw('c2.count as c2_count'), - DB::raw('c2.parent_category_id as c2_parent_category_id'), - DB::raw('t2.name as c2_name') - ) - ->leftJoin((DB::raw($dBName . ' c2')), DB::raw('c2.parent_category_id'), '=', DB::raw('c1.id')) - ->leftJoin((DB::raw($dBNamet . ' t1')), DB::raw('c1.id'), '=', DB::raw('t1.entry_id')) - ->leftJoin((DB::raw($dBNamet . ' t2')), DB::raw('c2.id'), '=', DB::raw('t2.entry_id')) - ->where(DB::raw('t1.locale'), Request()->session()->get('_locale', setting_value('streams::default_locale'))) - ->where(DB::raw('t2.locale'), Request()->session()->get('_locale', setting_value('streams::default_locale'))) - ->where(DB::raw("c1.deleted_at"), NULL) - ->where(DB::raw("c2.deleted_at"), NULL) - ->whereNull(DB::raw("c1.parent_category_id")) - ->orderBy(DB::raw("c1.sort_order")) - ->orderBy(DB::raw("c2.sort_order")) - ->get(); - $cats = collect([]); - $cats->subcats = $catsDB; - $cats->maincats = $catsDB->unique('id'); - return $cats; + DB::raw('c2.id as c2_id'), + DB::raw('c2.slug as c2_slug'), + DB::raw('c2.count as c2_count'), + DB::raw('c2.parent_category_id as c2_parent_category_id'), + DB::raw('t2.name as c2_name') + ) + ->leftJoin((DB::raw($dBName . ' c2')), DB::raw('c2.parent_category_id'), '=', DB::raw('c1.id')) + ->leftJoin((DB::raw($dBNamet . ' t1')), DB::raw('c1.id'), '=', DB::raw('t1.entry_id')) + ->leftJoin((DB::raw($dBNamet . ' t2')), function ($join) { + $join->on(DB::raw('c2.id'), '=', DB::raw('t2.entry_id')) + ->where(DB::raw('t2.locale'), Request()->session()->get('_locale', setting_value('streams::default_locale'))); + }) + ->where(DB::raw('t1.locale'), Request()->session()->get('_locale', setting_value('streams::default_locale'))) + ->where(DB::raw("c1.deleted_at"), NULL) + ->where(DB::raw("c2.deleted_at"), NULL) + ->whereNull(DB::raw("c1.parent_category_id")) + ->orderBy(DB::raw("c1.sort_order")) + ->orderBy(DB::raw("c2.sort_order")) + ->get(); + $cats = collect([]); + $cats->subcats = $catsDB; + $cats->maincats = $catsDB->unique('id'); + return $cats; } public function getCategoryById($id) From 8b320f93fcd3633d8108bfad7f383815994f31b9 Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Mon, 28 Jun 2021 16:42:00 +0300 Subject: [PATCH 07/10] added bestseller twig function (fixed comment) --- .../advs-module/src/Adv/AdvModel.php | 7 + .../advs-module/src/Adv/AdvRepository.php | 864 +++++++++--------- .../src/OptionHandler/AdvsOptions.php | 10 +- 3 files changed, 442 insertions(+), 439 deletions(-) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index 545aee1aa..6c565f16b 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -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; diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 1c989cc4d..321e85c85 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -17,383 +17,377 @@ use Visiosoft\LocationModule\District\DistrictModel; class AdvRepository extends EntryRepository implements AdvRepositoryInterface { - protected $model; - private $fileRepository; - private $folderRepository; + protected $model; + private $fileRepository; + private $folderRepository; - public function __construct( - AdvModel $model, - FileRepositoryInterface $fileRepository, - FolderRepositoryInterface $folderRepository - ) - { - $this->model = $model; - $this->fileRepository = $fileRepository; - $this->folderRepository = $folderRepository; - } + public function __construct( + AdvModel $model, + FileRepositoryInterface $fileRepository, + FolderRepositoryInterface $folderRepository + ) + { + $this->model = $model; + $this->fileRepository = $fileRepository; + $this->folderRepository = $folderRepository; + } - public function searchAdvs( - $type, $param = null, $customParameters = [], - $limit = null, $category = null, $city = null, $paginate = true - ) - { - $isActiveDopings = new AdvModel(); - $isActiveDopings = $isActiveDopings->is_enabled('dopings'); + public function searchAdvs( + $type, $param = null, $customParameters = [], + $limit = null, $category = null, $city = null, $paginate = true + ) + { + $isActiveDopings = new AdvModel(); + $isActiveDopings = $isActiveDopings->is_enabled('dopings'); - $query = $this->model; - $query = $query->where('advs_advs.slug', '!=', ""); - $query = $query->where('advs_advs.status', 'approved'); - $query = $query->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s')); + $query = $this->model; + $query = $query->where('advs_advs.slug', '!=', ""); + $query = $query->where('advs_advs.status', 'approved'); + $query = $query->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s')); - $query = $query->leftJoin('advs_advs_translations', function ($join) { - $join->on('advs_advs.id', '=', 'advs_advs_translations.entry_id'); - $join->where('advs_advs_translations.locale', '=', Request()->session()->get('_locale', setting_value('streams::default_locale'))); - }); + $query = $query->leftJoin('advs_advs_translations', function ($join) { + $join->on('advs_advs.id', '=', 'advs_advs_translations.entry_id'); + $join->where('advs_advs_translations.locale', '=', Request()->session()->get('_locale', setting_value('streams::default_locale'))); + }); - if (!empty($param['keyword'])) { - if (is_numeric($param['keyword'])) { - $query = $query->where('advs_advs.id', $param['keyword']); - } else { - $delimiter = '_'; - $keyword = str_slug($param['keyword'], $delimiter); - $query = $query->where(function ($query) use ($keyword) { - $query->where('slug', 'like', '%' . $keyword . '%') - ->orWhere('advs_advs_translations.name', 'like', '%' . $keyword . '%'); - }); - } - } - if (!setting_value('visiosoft.module.location::hide_location_filter')) { - $country = !empty($param['country']) ? $param['country'] : setting_value('visiosoft.module.location::default_country'); - if ($country) { - $query = $query->where('country_id', $country); - } - if ($city) { - $query = $query->where('city', $city->id); - } elseif (isset($param['city']) and !empty(array_filter($param['city']))) { - $query = $query->whereIn('city', explode(',', array_first($param['city']))); - } - if (isset($param['district']) and !empty(array_filter($param['district']))) { - $query = $query->whereIn('district', explode(',', array_first($param['district']))); - } - if (isset($param['neighborhood']) and !empty(array_filter($param['neighborhood']))) { - $query = $query->whereIn('neighborhood', explode(',', array_first($param['neighborhood']))); - } - if (isset($param['village']) and !empty(array_filter($param['village']))) { - $query = $query->whereIn('village', explode(',', array_first($param['village']))); - } - } - if ($category) { - $category_repository = app(CategoryRepositoryInterface::class); + if (!empty($param['keyword'])) { + if (is_numeric($param['keyword'])) { + $query = $query->where('advs_advs.id', $param['keyword']); + } else { + $delimiter = '_'; + $keyword = str_slug($param['keyword'], $delimiter); + $query = $query->where(function ($query) use ($keyword) { + $query->where('slug', 'like', '%' . $keyword . '%') + ->orWhere('advs_advs_translations.name', 'like', '%' . $keyword . '%'); + }); + } + } + if (!setting_value('visiosoft.module.location::hide_location_filter')) { + $country = !empty($param['country']) ? $param['country'] : setting_value('visiosoft.module.location::default_country'); + if ($country) { + $query = $query->where('country_id', $country); + } + if ($city) { + $query = $query->where('city', $city->id); + } elseif (isset($param['city']) and !empty(array_filter($param['city']))) { + $query = $query->whereIn('city', explode(',', array_first($param['city']))); + } + if (isset($param['district']) and !empty(array_filter($param['district']))) { + $query = $query->whereIn('district', explode(',', array_first($param['district']))); + } + if (isset($param['neighborhood']) and !empty(array_filter($param['neighborhood']))) { + $query = $query->whereIn('neighborhood', explode(',', array_first($param['neighborhood']))); + } + if (isset($param['village']) and !empty(array_filter($param['village']))) { + $query = $query->whereIn('village', explode(',', array_first($param['village']))); + } + } + if ($category) { + $category_repository = app(CategoryRepositoryInterface::class); - $catLevel = $category_repository->getLevelById($category->id); - $catLevel = "cat" . $catLevel; - $query = $query->where($catLevel, $category->id); - } - if (!empty($param['user'])) { - $query = $query->where('advs_advs.created_by_id', $param['user']); - } - $currency = setting_value('streams::currency'); + $catLevel = $category_repository->getLevelById($category->id); + $catLevel = "cat" . $catLevel; + $query = $query->where($catLevel, $category->id); + } + if (!empty($param['user'])) { + $query = $query->where('advs_advs.created_by_id', $param['user']); + } + $currency = setting_value('streams::currency'); - if (!empty($param['currency'])) { - $currency = $param['currency']; - } + if (!empty($param['currency'])) { + $currency = $param['currency']; + } - if (!empty($param['min_price'])) { - $num = $param['min_price']; - $int = (int)$num; - $column = "JSON_EXTRACT(foreign_currencies, '$." . $currency . "') >= " . $int; - $query = $query->whereRaw($column); - } + if (!empty($param['min_price'])) { + $num = $param['min_price']; + $int = (int)$num; + $column = "JSON_EXTRACT(foreign_currencies, '$." . $currency . "') >= " . $int; + $query = $query->whereRaw($column); + } - if (!empty($param['max_price'])) { - $num = $param['max_price']; - $int = (int)$num; - $column = "JSON_EXTRACT(foreign_currencies, '$." . $currency . "') <= " . $int; - $query = $query->whereRaw($column); - } + if (!empty($param['max_price'])) { + $num = $param['max_price']; + $int = (int)$num; + $column = "JSON_EXTRACT(foreign_currencies, '$." . $currency . "') <= " . $int; + $query = $query->whereRaw($column); + } - if (!empty($param['date'])) { - if ($param['date'] === 'day') { - $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subDay()); - } elseif ($param['date'] === 'two_days') { - $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subDays(2)); - } elseif ($param['date'] === 'week') { - $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subWeek()); - } elseif ($param['date'] === 'month') { - $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subMonth()); - } - } - if (!empty($param['photo'])) { - $query = $query->whereNotNull('cover_photo'); - } - if (!empty($param['video'])) { - $query = $query->where('cover_photo', 'like', '%video/upload/w_400,e_loop%'); - } - if (!empty($param['map']) && $param['map'] == true) { - $query = $query->whereNotNull('map_Val'); - } - if (!empty($param['get_ads']) && $param['get_ads'] == true) { - $query = $query->where('is_get_adv', 1); - } + if (!empty($param['date'])) { + if ($param['date'] === 'day') { + $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subDay()); + } elseif ($param['date'] === 'two_days') { + $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subDays(2)); + } elseif ($param['date'] === 'week') { + $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subWeek()); + } elseif ($param['date'] === 'month') { + $query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subMonth()); + } + } + if (!empty($param['photo'])) { + $query = $query->whereNotNull('cover_photo'); + } + if (!empty($param['video'])) { + $query = $query->where('cover_photo', 'like', '%video/upload/w_400,e_loop%'); + } + if (!empty($param['map']) && $param['map'] == true) { + $query = $query->whereNotNull('map_Val'); + } + if (!empty($param['get_ads']) && $param['get_ads'] == true) { + $query = $query->where('is_get_adv', 1); + } - if (!empty($param['created_at'])) { - $query = $query->whereDate('advs_advs.created_at', $param['created_at']); - } + if (!empty($param['created_at'])) { + $query = $query->whereDate('advs_advs.created_at', $param['created_at']); + } - foreach ($param as $para => $value) { - if (substr($para, 0, 3) === "cf_") { - $id = substr($para, 3); - $customParameters[] = ['id' => "$.cf" . $id, 'value' => $param[$para]]; - } - } + foreach ($param as $para => $value) { + if (substr($para, 0, 3) === "cf_") { + $id = substr($para, 3); + $customParameters[] = ['id' => "$.cf" . $id, 'value' => $param[$para]]; + } + } - if ($this->model->is_enabled('customfields')) { - $query = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->filterSearch($customParameters, $param, $query); - } + if ($this->model->is_enabled('customfields')) { + $query = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->filterSearch($customParameters, $param, $query); + } // //UPDATE `default_advs_advs` SET `coor` = (PointFromText('POINT(41.085022 28.804754)')) WHERE `default_advs_advs`.`id` = 8 // //SELECT * FROM `default_advs_advs` WHERE ST_DISTANCE(ST_GeomFromText('POINT(41.0709052 28.829627)'), coor) < 20 - if (!empty($param['dlong']) && !empty($param['dlat']) && !empty($param['distance'])) { - $query = $query->whereNotNull('coor'); - $query = $query->whereRaw("ST_DISTANCE(ST_GeomFromText('POINT(" . $param['dlong'] . " " . $param['dlat'] . ")'), coor) < " . $param['distance']); - } + if (!empty($param['dlong']) && !empty($param['dlat']) && !empty($param['distance'])) { + $query = $query->whereNotNull('coor'); + $query = $query->whereRaw("ST_DISTANCE(ST_GeomFromText('POINT(" . $param['dlong'] . " " . $param['dlat'] . ")'), coor) < " . $param['distance']); + } - if ($isActiveDopings) { - $query = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->search($query, $param); - } + if ($isActiveDopings) { + $query = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->search($query, $param); + } - if (!empty($param['sort_by'])) { - switch ($param['sort_by']) { - case "popular": - $query = $query->orderBy('advs_advs.count_show_ad', 'desc'); - break; - case "sort_price_up": - $query = $query->orderBy('advs_advs.price', 'desc'); - break; - case "sort_price_down": - $query = $query->orderBy('advs_advs.price', 'asc'); - break; - case "sort_time_newest": - $query = $query->orderBy('advs_advs.created_at', 'desc'); - break; - case "sort_time_oldest": - $query = $query->orderBy('advs_advs.created_at', 'asc'); - break; - case "address_a_z": - $query = $query->join('location_cities_translations', 'advs_advs.city', '=', 'location_cities_translations.entry_id') - ->orderBy('location_cities_translations.name', 'ASC'); - break; - case "address_z_a": - $query = $query->join('location_cities_translations', 'advs_advs.city', '=', 'location_cities_translations.entry_id') - ->orderBy('location_cities_translations.name', 'DESC'); - break; - } - } else { - $query = $query->orderBy('advs_advs.created_at', 'desc'); - } + if (!empty($param['sort_by'])) { + switch ($param['sort_by']) { + case "popular": + $query = $query->orderBy('advs_advs.count_show_ad', 'desc'); + break; + case "sort_price_up": + $query = $query->orderBy('advs_advs.price', 'desc'); + break; + case "sort_price_down": + $query = $query->orderBy('advs_advs.price', 'asc'); + break; + case "sort_time_newest": + $query = $query->orderBy('advs_advs.created_at', 'desc'); + break; + case "sort_time_oldest": + $query = $query->orderBy('advs_advs.created_at', 'asc'); + break; + case "address_a_z": + $query = $query->join('location_cities_translations', 'advs_advs.city', '=', 'location_cities_translations.entry_id') + ->orderBy('location_cities_translations.name', 'ASC'); + break; + case "address_z_a": + $query = $query->join('location_cities_translations', 'advs_advs.city', '=', 'location_cities_translations.entry_id') + ->orderBy('location_cities_translations.name', 'DESC'); + break; + } + } else { + $query = $query->orderBy('advs_advs.created_at', 'desc'); + } - if ($isActiveDopings) { - $query = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->querySelect($query, $param); - } else { - $query = $query->select('advs_advs.*', 'advs_advs_translations.name as name', - 'advs_advs_translations.advs_desc as advs_desc'); - } + if ($isActiveDopings) { + $query = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->querySelect($query, $param); + } else { + $query = $query->select('advs_advs.*', 'advs_advs_translations.name as name', + 'advs_advs_translations.advs_desc as advs_desc'); + } - if ($type == "list") { - return $paginate ? $query->paginate(setting_value('streams::per_page')) : $query; - } else { - return $query->get(); - } - } + if ($type == "list") { + return $paginate ? $query->paginate(setting_value('streams::per_page')) : $query; + } else { + return $query->get(); + } + } - public function softDeleteAdv($id) - { - return $this->find($id)->update(['deleted_at' => date('Y-m-d H:i:s')]); - } + public function softDeleteAdv($id) + { + return $this->find($id)->update(['deleted_at' => date('Y-m-d H:i:s')]); + } - public function getLocationNames($adv) - { - $country = CountryModel::query()->where('location_countries.id', $adv->country_id)->first(); - $city = CityModel::query()->where('location_cities.id', $adv->city)->first(); - $district = DistrictModel::query()->where('location_districts.id', $adv->district)->first(); - if ($country != null) { - $adv->setAttribute('country_name', $country->name); - } - if ($city != null) { - $adv->setAttribute('city_name', $city->name); - } - if ($district != null) { - $adv->setAttribute('district_name', $district->name); - } - return $adv; - } + public function getLocationNames($adv) + { + $country = CountryModel::query()->where('location_countries.id', $adv->country_id)->first(); + $city = CityModel::query()->where('location_cities.id', $adv->city)->first(); + $district = DistrictModel::query()->where('location_districts.id', $adv->district)->first(); + if ($country != null) { + $adv->setAttribute('country_name', $country->name); + } + if ($city != null) { + $adv->setAttribute('city_name', $city->name); + } + if ($district != null) { + $adv->setAttribute('district_name', $district->name); + } + return $adv; + } - public function getCatNames($adv) - { - $cat1 = CategoryModel::query()->where('cats_category.id', $adv->cat1)->first(); - $cat2 = CategoryModel::query()->where('cats_category.id', $adv->cat2)->first(); + public function getCatNames($adv) + { + $cat1 = CategoryModel::query()->where('cats_category.id', $adv->cat1)->first(); + $cat2 = CategoryModel::query()->where('cats_category.id', $adv->cat2)->first(); - if (!is_null($cat1)) - $adv->setAttribute('cat1_name', $cat1->name); - else - $adv->setAttribute('cat1_name', ""); + if (!is_null($cat1)) + $adv->setAttribute('cat1_name', $cat1->name); + else + $adv->setAttribute('cat1_name', ""); - if (!is_null($cat2)) - $adv->setAttribute('cat2_name', $cat2->name); + if (!is_null($cat2)) + $adv->setAttribute('cat2_name', $cat2->name); - else - $adv->setAttribute('cat2_name', ""); + else + $adv->setAttribute('cat2_name', ""); - return $adv; - } + return $adv; + } - public function findByIDAndSlug($id, $slug) - { - $adv = $this->newQuery() - ->where('advs_advs.id', $id) - ->where('slug', $slug) - ->first(); + public function findByIDAndSlug($id, $slug) + { + $adv = $this->newQuery() + ->where('advs_advs.id', $id) + ->where('slug', $slug) + ->first(); - if ($adv) { - $adv = $this->getLocationNames($adv); - } + if ($adv) { + $adv = $this->getLocationNames($adv); + } - return $adv; - } + return $adv; + } - public function getListItemAdv($id) - { - $adv = $this->model - ->where('advs_advs.id', $id) - ->leftJoin('users_users as u1', 'advs_advs.created_by_id', '=', 'u1.id') - ->select('advs_advs.*', 'u1.first_name as first_name', 'u1.last_name as last_name', 'u1.id as owner_id') - ->inRandomOrder() - ->first(); + public function getListItemAdv($id) + { + $adv = $this->model + ->where('advs_advs.id', $id) + ->leftJoin('users_users as u1', 'advs_advs.created_by_id', '=', 'u1.id') + ->select('advs_advs.*', 'u1.first_name as first_name', 'u1.last_name as last_name', 'u1.id as owner_id') + ->inRandomOrder() + ->first(); - if ($adv) { - $adv = $this->getLocationNames($adv); - } + if ($adv) { + $adv = $this->getLocationNames($adv); + } - return $adv; - } + return $adv; + } - public function addAttributes($advs) - { - foreach ($advs as $adv) { - $adv = $this->getLocationNames($adv); - $adv = $this->getCatNames($adv); - } + public function addAttributes($advs) + { + foreach ($advs as $adv) { + $adv = $this->getLocationNames($adv); + $adv = $this->getCatNames($adv); + } - return $advs; - } + return $advs; + } - public function cover_image_update($adv) - { - if (count($adv->files) != 0) { - $fileName = 'tn-' . $adv->files[0]->name; - $folder = $this->folderRepository->findBySlug('images'); - $thumbnail = $this->fileRepository->findByNameAndFolder($fileName, $folder); - if (!$thumbnail) { - // Create thumbnail image - $image = Image::make(file_get_contents($adv->files[0]->make()->url())); - $image->resize( - null, - setting_value('visiosoft.module.advs::thumbnail_height'), - function ($constraint) { - $constraint->aspectRatio(); - }); - if (setting_value('visiosoft.module.advs::add_canvas')) { - $image->resizeCanvas( - setting_value('visiosoft.module.advs::thumbnail_width'), - setting_value('visiosoft.module.advs::thumbnail_height'), - 'center', false, 'fff' - ); - } - $fileName = 'tn-' . $adv->files[0]->name; - $image->save(app_storage_path() . '/files-module/local/images/' . $fileName); + public function cover_image_update($adv) + { + if (count($adv->files) != 0) { + $fileName = 'tn-' . $adv->files[0]->name; + $folder = $this->folderRepository->findBySlug('images'); + $thumbnail = $this->fileRepository->findByNameAndFolder($fileName, $folder); + if (!$thumbnail) { + // Create thumbnail image + $image = Image::make(file_get_contents($adv->files[0]->make()->url())); + $image->resize( + null, + setting_value('visiosoft.module.advs::thumbnail_height'), + function ($constraint) { + $constraint->aspectRatio(); + }); + if (setting_value('visiosoft.module.advs::add_canvas')) { + $image->resizeCanvas( + setting_value('visiosoft.module.advs::thumbnail_width'), + setting_value('visiosoft.module.advs::thumbnail_height'), + 'center', false, 'fff' + ); + } + $fileName = 'tn-' . $adv->files[0]->name; + $image->save(app_storage_path() . '/files-module/local/images/' . $fileName); - // Create file entry for the image - $this->fileRepository->create([ - 'folder_id' => $folder->getId(), - 'name' => $fileName, - 'disk_id' => 1, - 'size' => $image->filesize(), - 'mime_type' => $image->mime, - 'extension' => $image->extension, - ]); + // Create file entry for the image + $this->fileRepository->create([ + 'folder_id' => $folder->getId(), + 'name' => $fileName, + 'disk_id' => 1, + 'size' => $image->filesize(), + 'mime_type' => $image->mime, + 'extension' => $image->extension, + ]); - } - $coverPhoto = 'files/images/' . $fileName; - } else { - $coverPhoto = null; - } - $adv->update(['cover_photo' => $coverPhoto]); - } + } + $coverPhoto = 'files/images/' . $fileName; + } else { + $coverPhoto = null; + } + $adv->update(['cover_photo' => $coverPhoto]); + } - public function getRecommendedAds($id) - { - return AdvModel::query() - ->where('advs_advs.id', '!=', $id) - ->where('advs_advs.status', 'approved') - ->select('advs_advs.*') - ->orderBy('id', 'desc') - ->take(4) - ->get(); - } + public function getRecommendedAds($id) + { + return AdvModel::query() + ->where('advs_advs.id', '!=', $id) + ->where('advs_advs.status', 'approved') + ->select('advs_advs.*') + ->orderBy('id', 'desc') + ->take(4) + ->get(); + } - public function getLastAd($id) - { - return AdvsAdvsEntryModel::query()->where('advs_advs.created_by_id', '=', $id)->max('id'); - } + public function getLastAd($id) + { + return AdvsAdvsEntryModel::query()->where('advs_advs.created_by_id', '=', $id)->max('id'); + } - public function getAdvArray($id) - { - $ad = AdvsAdvsEntryModel::query()->where('advs_advs.id', $id)->first(); + public function getAdvArray($id) + { + $ad = AdvsAdvsEntryModel::query()->where('advs_advs.id', $id)->first(); - return ($ad !== null) ? $ad->toArray() : null; - } + return ($ad !== null) ? $ad->toArray() : null; + } - public function getQuantity($quantity, $type, $item) - { - if ($type == "minus") { - return $quantity - 1; - } elseif ($type == "plus") { - return $quantity + 1; - } else { - return $quantity; - } - } + public function getQuantity($quantity, $type, $item) + { + if ($type == "minus") { + return $quantity - 1; + } elseif ($type == "plus") { + return $quantity + 1; + } else { + return $quantity; + } + } - public function findByIds($ids) - { - return $this->model->orderBy('created_at', 'DESC')->whereIn('advs_advs.id', $ids)->get(); - } + public function findByIds($ids) + { + return $this->model->orderBy('created_at', 'DESC')->whereIn('advs_advs.id', $ids)->get(); + } - /** - * Get Latest Ads - * @return mixed - */ - 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; - } + /** + * Get Latest Ads + * @return mixed + */ + public function latestAds() + { + $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); @@ -402,134 +396,134 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface ->limit($limit)->get(); } - public function getByCat($catID, $level = 1, $limit = 20) - { - $advs = $this->model - ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) - ->where('status', 'approved') - ->where('slug', '!=', '') - ->where('cat' . $level, $catID); + public function getByCat($catID, $level = 1, $limit = 20) + { + $advs = $this->model + ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) + ->where('status', 'approved') + ->where('slug', '!=', '') + ->where('cat' . $level, $catID); - if ($limit) { - $advs = $advs->limit($limit); - } + if ($limit) { + $advs = $advs->limit($limit); + } - $advs = $advs->get(); + $advs = $advs->get(); - $ads = $this->model->getLocationNames($advs); + $ads = $this->model->getLocationNames($advs); - foreach ($ads as $index => $ad) { - $ads[$index]->detail_url = $this->model->getAdvDetailLinkByModel($ad, 'list'); - $ads[$index]->currency_price = app(Currency::class)->format($ad->price, $ad->currency); - $ads[$index] = $this->model->AddAdsDefaultCoverImage($ad); - } + foreach ($ads as $index => $ad) { + $ads[$index]->detail_url = $this->model->getAdvDetailLinkByModel($ad, 'list'); + $ads[$index]->currency_price = app(Currency::class)->format($ad->price, $ad->currency); + $ads[$index] = $this->model->AddAdsDefaultCoverImage($ad); + } - return $ads; - } + return $ads; + } - public function getAdsCountByCategory($catID, $level = 1) - { - return DB::table('advs_advs') - ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) - ->where('status', 'approved') - ->whereNull('deleted_at') - ->where('slug', '!=', '') - ->where('cat' . $level, $catID) - ->count(); - } + public function getAdsCountByCategory($catID, $level = 1) + { + return DB::table('advs_advs') + ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) + ->where('status', 'approved') + ->whereNull('deleted_at') + ->where('slug', '!=', '') + ->where('cat' . $level, $catID) + ->count(); + } - public function getCategoriesWithAdID($id) - { - $adv = $this->model->find($id); + public function getCategoriesWithAdID($id) + { + $adv = $this->model->find($id); - if (!is_null($adv)) { - $categories = array(); - foreach ($adv->toArray() as $key => $field) { - if (preg_match('/cat\d/', $key) and !is_null($field)) { - $categories[$key] = $field; - } - } - return $categories; - } - return null; - } + if (!is_null($adv)) { + $categories = array(); + foreach ($adv->toArray() as $key => $field) { + if (preg_match('/cat\d/', $key) and !is_null($field)) { + $categories[$key] = $field; + } + } + return $categories; + } + return null; + } - public function extendAds($allAds, $isAdmin = false) - { - if (is_array($allAds)) { - $advs = $this->newQuery()->whereIn('id', $allAds); - } elseif (!is_numeric($allAds)) { - if ($isAdmin && auth()->user()->hasRole('admin')) { - $advs = $this->newQuery(); - } else { - $advs = $this->newQuery()->where('created_by_id', auth()->id()); - } - } else { - $advs = $this->newQuery()->where('id', $allAds); - } - $newDate = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . setting_value('visiosoft.module.advs::default_published_time') . ' day')); - return $advs - ->where('slug', '!=', '') - ->update(['finish_at' => $newDate]); - } + public function extendAds($allAds, $isAdmin = false) + { + if (is_array($allAds)) { + $advs = $this->newQuery()->whereIn('id', $allAds); + } elseif (!is_numeric($allAds)) { + if ($isAdmin && auth()->user()->hasRole('admin')) { + $advs = $this->newQuery(); + } else { + $advs = $this->newQuery()->where('created_by_id', auth()->id()); + } + } else { + $advs = $this->newQuery()->where('id', $allAds); + } + $newDate = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . setting_value('visiosoft.module.advs::default_published_time') . ' day')); + return $advs + ->where('slug', '!=', '') + ->update(['finish_at' => $newDate]); + } - public function getByUsersIDs($usersIDs, $status = 'approved', $withDraft = false) - { - $ads = $this - ->newQuery() - ->whereIn('advs_advs.created_by_id', $usersIDs); + public function getByUsersIDs($usersIDs, $status = 'approved', $withDraft = false) + { + $ads = $this + ->newQuery() + ->whereIn('advs_advs.created_by_id', $usersIDs); - if ($status) { - $ads = $ads->where('advs_advs.status', 'approved'); - } + if ($status) { + $ads = $ads->where('advs_advs.status', 'approved'); + } - if (!$withDraft) { - $ads = $ads - ->where('advs_advs.slug', '!=', "") - ->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s')); - } + if (!$withDraft) { + $ads = $ads + ->where('advs_advs.slug', '!=', "") + ->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s')); + } - return $ads; - } + return $ads; + } - public function getPopular() - { - return $this->newQuery() - ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) - ->where('status', '=', 'approved') - ->where('slug', '!=', '') - ->orderBy('count_show_ad', 'desc') - ->paginate(setting_value('visiosoft.module.advs::popular_ads_limit', setting_value('streams::per_page'))); - } + public function getPopular() + { + return $this->newQuery() + ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) + ->where('status', '=', 'approved') + ->where('slug', '!=', '') + ->orderBy('count_show_ad', 'desc') + ->paginate(setting_value('visiosoft.module.advs::popular_ads_limit', setting_value('streams::per_page'))); + } - public function getName($id) - { - return $this->find($id)->name; - } + public function getName($id) + { + return $this->find($id)->name; + } - public function approveAds($adsIDs) - { - $defaultAdPublishTime = setting_value('visiosoft.module.advs::default_published_time'); - $ads = $this->newQuery()->whereIn('advs_advs.id', $adsIDs)->update([ - 'status' => 'approved', - 'finish_at' => date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . $defaultAdPublishTime . ' day')), - 'publish_at' => date('Y-m-d H:i:s') - ]); + public function approveAds($adsIDs) + { + $defaultAdPublishTime = setting_value('visiosoft.module.advs::default_published_time'); + $ads = $this->newQuery()->whereIn('advs_advs.id', $adsIDs)->update([ + 'status' => 'approved', + 'finish_at' => date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . $defaultAdPublishTime . ' day')), + 'publish_at' => date('Y-m-d H:i:s') + ]); - return $ads; - } + return $ads; + } - public function getUserAds($userID = null, $status = "approved") - { - $userID = auth_id_if_null($userID); + public function getUserAds($userID = null, $status = "approved") + { + $userID = auth_id_if_null($userID); - $query = $this->newQuery() - ->where('advs_advs.created_by_id', $userID); + $query = $this->newQuery() + ->where('advs_advs.created_by_id', $userID); - if ($status) { - $query = $query->where('status', $status); - } - return $query->where('finish_at', '>', date('Y-m-d H:i:s')) - ->get(); - } + if ($status) { + $query = $query->where('status', $status); + } + return $query->where('finish_at', '>', date('Y-m-d H:i:s')) + ->get(); + } } diff --git a/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php b/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php index 9a6dc8e24..6304f7045 100644 --- a/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php +++ b/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php @@ -1,20 +1,22 @@ 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); } From 514460222734e307b1e9a3479f82f37c2c0733f1 Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Mon, 28 Jun 2021 16:42:52 +0300 Subject: [PATCH 08/10] added bestseller twig function (fixed comment) --- .../visiosoft/advs-module/src/OptionHandler/AdvsOptions.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php b/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php index 6304f7045..3d5236222 100644 --- a/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php +++ b/addons/default/visiosoft/advs-module/src/OptionHandler/AdvsOptions.php @@ -2,8 +2,6 @@ use Anomaly\CheckboxesFieldType\CheckboxesFieldType; use Visiosoft\AdvsModule\Adv\AdvModel; -use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; -use Visiosoft\MultipleFieldType\MultipleFieldType; class AdvsOptions { From aef54dd4bd5b34b2421dd72479aaacc948f85f08 Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Mon, 28 Jun 2021 17:46:19 +0300 Subject: [PATCH 09/10] fixed total sales --- .../src/AdvsModuleServiceProvider.php | 6 ++++- .../src/Listener/AddTotalSales.php | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 addons/default/visiosoft/advs-module/src/Listener/AddTotalSales.php diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index 04f7a4348..14fc29ca9 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -15,6 +15,7 @@ use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder; use Visiosoft\AdvsModule\Http\Middleware\redirectDiffrentLang; use Visiosoft\AdvsModule\Http\Middleware\SetLang; use Visiosoft\AdvsModule\Listener\AddAdvsSettingsScript; +use Visiosoft\AdvsModule\Listener\AddTotalSales; use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; use Visiosoft\AdvsModule\Option\OptionRepository; use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface; @@ -33,6 +34,7 @@ use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\CatsModule\Category\CategoryRepository; use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface; use Visiosoft\LocationModule\Country\CountryRepository; +use Visiosoft\OrdersModule\Orderdetail\Event\CreatedOrderDetail; class AdvsModuleServiceProvider extends AddonServiceProvider { @@ -245,7 +247,9 @@ class AdvsModuleServiceProvider extends AddonServiceProvider protected $listeners = [ TableIsQuerying::class => [ AddAdvsSettingsScript::class, - ], + ], CreatedOrderDetail::class => [ + AddTotalSales::class, + ] ]; protected $bindings = [ diff --git a/addons/default/visiosoft/advs-module/src/Listener/AddTotalSales.php b/addons/default/visiosoft/advs-module/src/Listener/AddTotalSales.php new file mode 100644 index 000000000..14332d921 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Listener/AddTotalSales.php @@ -0,0 +1,24 @@ +advModel = $advModel; + } + + public function handle(CreatedOrderDetail $event) + { + $item = $event->getOrderItem(); + $adv = $this->advModel->find($event->getOrderItem()->item_id); + $total = $adv->total_sales + $item->piece; + $adv->total_sales = $total; + $adv->save(); + } +} \ No newline at end of file From f9a6541e7b3eca03256b2da4d735aaebfa3ff4d6 Mon Sep 17 00:00:00 2001 From: Muammer Top Date: Mon, 28 Jun 2021 17:51:25 +0300 Subject: [PATCH 10/10] fixed total sales --- addons/default/visiosoft/advs-module/src/Adv/AdvModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index b57e4256e..a13e2f44f 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -43,7 +43,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface public function getCurrencyStandardPriceAttribute() { - if ($this->standard_price > $this->currency) { + if ($this->standard_price > $this->price) { return app(Currency::class)->format($this->standard_price, $this->currency); } return null;