From aad685d79533afacfbc06d6c51ceb452455252fa Mon Sep 17 00:00:00 2001 From: diashalabi Date: Sun, 10 Oct 2021 16:21:23 +0300 Subject: [PATCH 1/3] #654 [customfields] Improvments --- .../visiosoft/advs-module/src/Adv/AdvModel.php | 5 ----- .../advs-module/src/Adv/Contract/AdvInterface.php | 2 -- .../src/Http/Controller/Admin/AdvsController.php | 12 ------------ 3 files changed, 19 deletions(-) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index faf106f2f..aed892ffc 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -381,11 +381,6 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface } } - public function customfields() - { - return $this->hasMany('Visiosoft\CustomfieldsModule\CustomFieldAdv\CustomFieldAdvModel', 'parent_adv_id', 'id'); - } - // public function getCustomFieldEditId($id) { // $custom_field = AdvsCustomFieldsEntryModel::query()->where('advs_custom_fields.id', $id)->first(); // return DB::table('streams_assignments')->where('field_id', $custom_field->field_id)->first(); diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php index 693d69980..5370ca5a8 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php @@ -58,8 +58,6 @@ interface AdvInterface extends EntryInterface public function saveCustomField($category_id, $field_id, $name); - public function customfields(); - public function priceFormat($adv); public function AddAdsDefaultCoverImage($ad); diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php index 139a74034..3f0bec60f 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php @@ -128,18 +128,6 @@ class AdvsController extends AdminController $newAdvOption->save(); } - // Replicate ad custom fields - $advCustomFields = $this->model->is_enabled('customfields'); - if ($advCustomFields) { - $advCustomFields = app('Visiosoft\CustomfieldsModule\CustomFieldAdv\Contract\CustomFieldAdvRepositoryInterface') - ->newQuery()->where('parent_adv_id', $advID)->get(); - foreach ($advCustomFields as $advCustomField) { - $newaAdvCustomField = $advCustomField->replicate(); - $newaAdvCustomField->parent_adv_id = $newAdv->id; - $newaAdvCustomField->save(); - } - } - $this->messages->success(trans('visiosoft.module.advs::message.replicated_success')); } From d7bdfcef5d34c616e7db222323a9a72fb6bed2c3 Mon Sep 17 00:00:00 2001 From: diashalabi Date: Sun, 10 Oct 2021 17:13:06 +0300 Subject: [PATCH 2/3] fix --- .../visiosoft/advs-module/src/Adv/AdvModel.php | 15 +++++++++++++++ .../advs-module/src/Adv/Contract/AdvInterface.php | 2 ++ 2 files changed, 17 insertions(+) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index aed892ffc..1206b5420 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -12,6 +12,7 @@ use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationModel; use Visiosoft\AdvsModule\Support\Command\Currency; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; +use Visiosoft\CustomfieldsModule\CustomField\Contract\CustomFieldRepositoryInterface; use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\CartsModule\Cart\Command\GetCart; @@ -381,6 +382,20 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface } } + public function customfields() + { + if ($cFs = (array) json_decode($this->cf_json)) { + $cFs = array_keys($cFs); + + return app(CustomFieldRepositoryInterface::class) + ->newQuery() + ->whereIn('id', $cFs) + ->get(); + } + + return []; + } + // public function getCustomFieldEditId($id) { // $custom_field = AdvsCustomFieldsEntryModel::query()->where('advs_custom_fields.id', $id)->first(); // return DB::table('streams_assignments')->where('field_id', $custom_field->field_id)->first(); diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php index 5370ca5a8..693d69980 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php @@ -58,6 +58,8 @@ interface AdvInterface extends EntryInterface public function saveCustomField($category_id, $field_id, $name); + public function customfields(); + public function priceFormat($adv); public function AddAdsDefaultCoverImage($ad); From b771f0bc9b882d754c37c7d133cece12430aff0a Mon Sep 17 00:00:00 2001 From: diashalabi Date: Sun, 10 Oct 2021 17:43:31 +0300 Subject: [PATCH 3/3] #654 [customfields] Improvments --- .../visiosoft/advs-module/src/Adv/AdvModel.php | 11 ++++++++++- .../advs-module/src/Adv/Contract/AdvInterface.php | 2 ++ 2 files changed, 12 insertions(+), 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 1206b5420..2b73fceed 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -387,15 +387,24 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface if ($cFs = (array) json_decode($this->cf_json)) { $cFs = array_keys($cFs); + $cFIDs = array_map(function ($cF) { + return ltrim($cF, 'cf'); + }, $cFs); + return app(CustomFieldRepositoryInterface::class) ->newQuery() - ->whereIn('id', $cFs) + ->whereIn('id', $cFIDs) ->get(); } return []; } + public function cFJSON() + { + return (array) json_decode($this->cf_json); + } + // public function getCustomFieldEditId($id) { // $custom_field = AdvsCustomFieldsEntryModel::query()->where('advs_custom_fields.id', $id)->first(); // return DB::table('streams_assignments')->where('field_id', $custom_field->field_id)->first(); diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php index 693d69980..105da9504 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php @@ -60,6 +60,8 @@ interface AdvInterface extends EntryInterface public function customfields(); + public function cFJSON(); + public function priceFormat($adv); public function AddAdsDefaultCoverImage($ad);