From 37688d824da19530b3e61e436dab1925e9b99116 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Mon, 7 Dec 2020 11:58:53 +0300 Subject: [PATCH] #2336 redirect ad detail link if slug is different --- .../advs-module/src/Adv/AdvModel.php | 9 +++------ .../advs-module/src/Adv/AdvRepository.php | 14 ++++++++++++++ .../Adv/Contract/AdvRepositoryInterface.php | 2 ++ .../src/Http/Controller/advsController.php | 13 ++++++------- .../src/Category/CategoryModel.php | 19 ++++++++++--------- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index 13a069deb..d6bbfe168 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -218,13 +218,11 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface { if ($type != null) { $id = $object->id; - $seo = str_slug($object->name); - $seo = str_replace('_', '-', $seo); + $seo = $object->slug; return \route('adv_detail_seo', [$seo, $id]); } $id = $object->getObject()->id; - $seo = str_slug($object->getObject()->name); - $seo = str_replace('_', '-', $seo); + $seo = $object->getObject()->slug; return \route('adv_detail_seo', [$seo, $id]); } @@ -233,8 +231,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface $adv = $this->find($id); if ($adv != null) { $id = $adv->id; - $seo = str_slug($adv->name); - $seo = str_replace('_', '-', $seo); + $seo = $adv->slug; return \route('adv_detail_seo', [$seo, $id]); } } diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 0d0ad4b45..ded2da4d6 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -244,6 +244,20 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface return $adv; } + public function findByIDAndSlug($id, $slug) + { + $adv = $this->newQuery() + ->where('advs_advs.id', $id) + ->where('slug', $slug) + ->first(); + + if ($adv) { + $adv = $this->getLocationNames($adv); + } + + return $adv; + } + public function getListItemAdv($id) { $adv = $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 abea0bc85..16984415e 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -21,6 +21,8 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface public function getCatNames($adv); + public function findByIDAndSlug($id, $slug); + public function cover_image_update($adv); public function getRecommendedAds($id); diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php index 50b518453..ad1182101 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -135,10 +135,6 @@ class AdvsController extends PublicController parent::__construct(); } - - /** - * @return \Illuminate\Contracts\View\View|mixed - */ public function index($category = null, $city = null) { $customParameters = array(); @@ -481,9 +477,12 @@ class AdvsController extends PublicController public function view($seo, $id = null) { - $id = is_null($id) ? $seo : $id; - - $adv = $this->adv_repository->getListItemAdv($id); + if ($id) { + $adv = $this->adv_repository->findByIDAndSlug($id, $seo); + } else { + $id = $seo; + $adv = $this->adv_repository->getListItemAdv($id); + } if ($adv && ((!$adv->expired() && $adv->getStatus() === 'approved') || $adv->created_by_id === \auth()->id())) { // Check if created by exists diff --git a/addons/default/visiosoft/cats-module/src/Category/CategoryModel.php b/addons/default/visiosoft/cats-module/src/Category/CategoryModel.php index bf229443b..ccf3769cd 100644 --- a/addons/default/visiosoft/cats-module/src/Category/CategoryModel.php +++ b/addons/default/visiosoft/cats-module/src/Category/CategoryModel.php @@ -176,15 +176,16 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface $categories = array(); $z = 1; for ($i = 1; $i <= $z; $i++) { - $main = $this->newQuery()->where('id', $id)->first(); - $new = array(); - $new['id'] = $main->id; - $new['val'] = $main->name; - $new['slug'] = $main->slug; - $categories[] = $new; - if ($main->parent_category_id != null) { - $id = $main->parent_category_id; - $z++; + if ($main = $this->newQuery()->where('id', $id)->first()) { + $new = array(); + $new['id'] = $main->id; + $new['val'] = $main->name; + $new['slug'] = $main->slug; + $categories[] = $new; + if ($main->parent_category_id != null) { + $id = $main->parent_category_id; + $z++; + } } } $categories = array_reverse($categories);